stylelint-a11y
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -14,2 +14,4 @@ 'use strict'; | ||
accept: [{ | ||
code: '.foo { }' | ||
}, { | ||
code: '.foo { font-size: 15px; }' | ||
@@ -16,0 +18,0 @@ }, { |
@@ -16,13 +16,8 @@ 'use strict'; | ||
root.walk(function (node) { | ||
root.walkRules(function (rule) { | ||
var selector = null; | ||
if (node.type === 'rule') { | ||
if (!(0, _isStandardSyntaxRule2.default)(node)) { | ||
return; | ||
} | ||
selector = node.selector; | ||
} else if (node.type === 'atrule' && node.name.toLowerCase() === 'page' && node.params) { | ||
selector = node.params; | ||
if (!(0, _isStandardSyntaxRule2.default)(rule)) { | ||
return; | ||
} | ||
selector = rule.selector; | ||
@@ -33,9 +28,11 @@ if (!selector) { | ||
var isAccepted = check(node); | ||
var isRejected = rule.nodes.some(function (o) { | ||
return o.type === 'decl' && o.prop.toLowerCase() === 'font-size' && o.value.toLowerCase().endsWith('px') && parseFloat(o.value) < 15; | ||
}); | ||
if (!isAccepted) { | ||
if (isRejected) { | ||
_stylelint.utils.report({ | ||
index: node.lastEach, | ||
index: rule.lastEach, | ||
message: messages.expected(selector), | ||
node: node, | ||
node: rule, | ||
ruleName: ruleName, | ||
@@ -61,14 +58,4 @@ result: result | ||
expected: function expected(selector) { | ||
return 'Expected a larger "font-size" in ' + selector; | ||
return 'Expected a larger font-size in ' + selector; | ||
} | ||
}); | ||
function check(node) { | ||
if (node.type !== 'rule') { | ||
return true; | ||
} | ||
return node.nodes.some(function (o) { | ||
return o.type === 'decl' && o.prop.toLowerCase() === 'font-size' && (!o.value.toLowerCase().endsWith('px') || parseFloat(o.value) >= 15); | ||
}); | ||
} | ||
}); |
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _lineHeightIsVerticalRhythmed = require('./line-height-is-vertical-rhythmed'); | ||
var _lineHeightIsVerticalRhythmed2 = _interopRequireDefault(_lineHeightIsVerticalRhythmed); | ||
var _mediaPrefersReducedMotion = require('./media-prefers-reduced-motion'); | ||
@@ -36,2 +40,3 @@ | ||
'font-size-is-readable': _fontSizeIsReadable2.default, | ||
'line-height-is-vertical-rhythmed': _lineHeightIsVerticalRhythmed2.default, | ||
'media-prefers-reduced-motion': _mediaPrefersReducedMotion2.default, | ||
@@ -38,0 +43,0 @@ 'no-display-none': _noDisplayNone2.default, |
@@ -9,2 +9,4 @@ 'use strict'; | ||
// eslint-disable-line | ||
testRule(_index2.default, { | ||
@@ -15,2 +17,4 @@ ruleName: _index.ruleName, | ||
accept: [{ | ||
code: 'a { }' | ||
}, { | ||
code: 'a:focus { }' | ||
@@ -25,6 +29,13 @@ }, { | ||
code: 'a:hover { }', | ||
message: _index.messages.expected('a:hover'), | ||
line: 1, | ||
column: 4 | ||
message: _index.messages.expected('a:hover') | ||
}, { | ||
code: 'a:hover { } b:hover { }', | ||
message: _index.messages.expected('a:hover') | ||
}, { | ||
code: 'a:hover { } a:focus { } b:hover { } b { }', | ||
message: _index.messages.expected('b:hover') | ||
}, { | ||
code: 'a:hover, a:focus { } b:hover { } b { }', | ||
message: _index.messages.expected('b:hover') | ||
}] | ||
}); |
@@ -16,19 +16,11 @@ 'use strict'; | ||
root.walk(function (node) { | ||
root.walkRules(function (rule) { | ||
var selector = null; | ||
if (node.type === 'rule') { | ||
if (!(0, _isStandardSyntaxRule2.default)(node)) { | ||
return; | ||
} | ||
if (!(0, _isStandardSyntaxRule2.default)(rule)) { | ||
return; | ||
} | ||
selector = node.selector; | ||
} else if (node.type === 'atrule' && node.name === 'page' && node.params) { | ||
if (!(0, _isStandardSyntaxAtRule2.default)(node)) { | ||
return; | ||
} | ||
selector = rule.selector; | ||
selector = node.params; | ||
} | ||
if (!selector) { | ||
@@ -42,20 +34,17 @@ return; | ||
var parentNodes = node.parent.nodes; | ||
var isAccepted = null; | ||
if (selector.indexOf(':hover') === -1) { | ||
return; | ||
} | ||
if (parentNodes.length > 1) { | ||
var checkParentNodes = parentNodes.map(function (parentNode) { | ||
return check(parentNode.selector); | ||
}).filter(Boolean); | ||
isAccepted = !!checkParentNodes; | ||
} else { | ||
isAccepted = check(selector); | ||
if (selector.indexOf(':hover') >= 0 && selector.indexOf(':focus') >= 0) { | ||
return; | ||
} | ||
var isAccepted = hasAlready(rule.parent, selector.replace(/:hover/g, ':focus')); | ||
if (!isAccepted) { | ||
_stylelint.utils.report({ | ||
index: node.lastEach, | ||
index: rule.lastEach, | ||
message: messages.expected(selector), | ||
node: node, | ||
node: rule, | ||
ruleName: ruleName, | ||
@@ -75,14 +64,2 @@ result: result | ||
var _isStandardSyntaxSelector = require('stylelint/lib/utils/isStandardSyntaxSelector'); | ||
var _isStandardSyntaxSelector2 = _interopRequireDefault(_isStandardSyntaxSelector); | ||
var _isStandardSyntaxAtRule = require('stylelint/lib/utils/isStandardSyntaxAtRule'); | ||
var _isStandardSyntaxAtRule2 = _interopRequireDefault(_isStandardSyntaxAtRule); | ||
var _isCustomSelector = require('stylelint/lib/utils/isCustomSelector'); | ||
var _isCustomSelector2 = _interopRequireDefault(_isCustomSelector); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -98,18 +75,6 @@ | ||
function check(selector) { | ||
if (!selector) return; | ||
if (selector.match(/:focus/gi) || selector.match(/:hover/gi) && selector.match(/:focus/gi) || !selector.match(/:hover/gi) && !selector.match(/:focus/gi)) { | ||
return true; | ||
} | ||
if (!(0, _isStandardSyntaxSelector2.default)(selector)) { | ||
return true; | ||
} | ||
if ((0, _isCustomSelector2.default)(selector)) { | ||
return true; | ||
} | ||
return false; | ||
function hasAlready(parent, selector) { | ||
return parent.nodes.some(function (i) { | ||
return i.type === 'rule' && i.selectors.indexOf(selector) !== -1; | ||
}); | ||
} |
{ | ||
"name": "stylelint-a11y", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"description": "Plugin for stylelint with a11y rules", | ||
@@ -50,7 +50,7 @@ "main": "dist/index.js", | ||
"lodash": "^4.17.10", | ||
"prettier": "^1.13.4", | ||
"prettier": "^1.13.5", | ||
"rimraf": "^2.6.2", | ||
"stylelint": "^9.2.1", | ||
"stylelint": "^9.3.0", | ||
"stylelint-test-rule-tape": "^0.2.0" | ||
} | ||
} |
@@ -18,8 +18,9 @@ # stylelint-a11y | ||
"rules": { | ||
"a11y/font-size-is-readable": [true, { "severity": "warning" }], | ||
"a11y/media-prefers-reduced-motion": true, | ||
"a11y/no-display-none": [true, { "severity": "warning" }], | ||
"a11y/no-outline-none": true, | ||
"a11y/no-text-align-justify": true, | ||
"a11y/selector-pseudo-class-focus": true | ||
"a11y/selector-pseudo-class-focus": true, | ||
"a11y/font-size-is-readable": [true, { "severity": "warning" }], | ||
"a11y/line-height-is-vertical-rhythmed": [true, { "severity": "warning" }], | ||
"a11y/no-display-none": [true, { "severity": "warning" }] | ||
} | ||
@@ -34,2 +35,3 @@ } | ||
- [`font-size-is-readable`](./src/rules/font-size-is-readable/README.md): Disallow font sizes less than 15px. | ||
- [`line-height-is-vertical-rhythmed`](./src/rules/line-height-is-vertical-rhythmed/README.md): Disallow not vertical rhythmed line-height. | ||
- [`media-prefers-reduced-motion`](./src/rules/media-prefers-reduced-motion/README.md): Require certain styles if the animation or transition in media features. | ||
@@ -36,0 +38,0 @@ - [`no-display-none`](./src/rules/no-display-none/README.md): Disallow content hiding with `{ display: none; }` property. |
@@ -9,2 +9,5 @@ import rule, { messages, ruleName } from '../index'; | ||
{ | ||
code: '.foo { }', | ||
}, | ||
{ | ||
code: '.foo { font-size: 15px; }', | ||
@@ -11,0 +14,0 @@ }, |
@@ -7,18 +7,5 @@ import { utils } from 'stylelint'; | ||
export const messages = utils.ruleMessages(ruleName, { | ||
expected: selector => `Expected a larger "font-size" in ${selector}`, | ||
expected: selector => `Expected a larger font-size in ${selector}`, | ||
}); | ||
function check(node) { | ||
if (node.type !== 'rule') { | ||
return true; | ||
} | ||
return node.nodes.some( | ||
o => | ||
o.type === 'decl' && | ||
o.prop.toLowerCase() === 'font-size' && | ||
(!o.value.toLowerCase().endsWith('px') || parseFloat(o.value) >= 15) | ||
); | ||
} | ||
export default function(actual) { | ||
@@ -32,13 +19,8 @@ return (root, result) => { | ||
root.walk(node => { | ||
root.walkRules(rule => { | ||
let selector = null; | ||
if (node.type === 'rule') { | ||
if (!isStandardSyntaxRule(node)) { | ||
return; | ||
} | ||
selector = node.selector; | ||
} else if (node.type === 'atrule' && node.name.toLowerCase() === 'page' && node.params) { | ||
selector = node.params; | ||
if (!isStandardSyntaxRule(rule)) { | ||
return; | ||
} | ||
selector = rule.selector; | ||
@@ -49,9 +31,16 @@ if (!selector) { | ||
const isAccepted = check(node); | ||
const isRejected = rule.nodes.some(o => { | ||
return ( | ||
o.type === 'decl' && | ||
o.prop.toLowerCase() === 'font-size' && | ||
o.value.toLowerCase().endsWith('px') && | ||
parseFloat(o.value) < 15 | ||
); | ||
}); | ||
if (!isAccepted) { | ||
if (isRejected) { | ||
utils.report({ | ||
index: node.lastEach, | ||
index: rule.lastEach, | ||
message: messages.expected(selector), | ||
node, | ||
node: rule, | ||
ruleName, | ||
@@ -58,0 +47,0 @@ result, |
import fontSizeIsReadable from './font-size-is-readable'; | ||
import lineHeightIsVerticalRhythmed from './line-height-is-vertical-rhythmed'; | ||
import mediaPrefersReducedMotion from './media-prefers-reduced-motion'; | ||
@@ -10,2 +11,3 @@ import noDisplayNone from './no-display-none'; | ||
'font-size-is-readable': fontSizeIsReadable, | ||
'line-height-is-vertical-rhythmed': lineHeightIsVerticalRhythmed, | ||
'media-prefers-reduced-motion': mediaPrefersReducedMotion, | ||
@@ -12,0 +14,0 @@ 'no-display-none': noDisplayNone, |
@@ -1,2 +0,2 @@ | ||
import rule, { messages, ruleName } from '../index'; | ||
import rule, { messages, ruleName } from '../index'; // eslint-disable-line | ||
@@ -9,2 +9,5 @@ testRule(rule, { | ||
{ | ||
code: 'a { }', | ||
}, | ||
{ | ||
code: 'a:focus { }', | ||
@@ -24,6 +27,16 @@ }, | ||
message: messages.expected('a:hover'), | ||
line: 1, | ||
column: 4, | ||
}, | ||
{ | ||
code: 'a:hover { } b:hover { }', | ||
message: messages.expected('a:hover'), | ||
}, | ||
{ | ||
code: 'a:hover { } a:focus { } b:hover { } b { }', | ||
message: messages.expected('b:hover'), | ||
}, | ||
{ | ||
code: 'a:hover, a:focus { } b:hover { } b { }', | ||
message: messages.expected('b:hover'), | ||
}, | ||
], | ||
}); |
import { utils } from 'stylelint'; | ||
import isStandardSyntaxRule from 'stylelint/lib/utils/isStandardSyntaxRule'; | ||
import isStandardSyntaxSelector from 'stylelint/lib/utils/isStandardSyntaxSelector'; | ||
import isStandardSyntaxAtRule from 'stylelint/lib/utils/isStandardSyntaxAtRule'; | ||
import isCustomSelector from 'stylelint/lib/utils/isCustomSelector'; | ||
@@ -13,22 +10,6 @@ export const ruleName = 'a11y/selector-pseudo-class-focus'; | ||
function check(selector) { | ||
if (!selector) return; | ||
if ( | ||
selector.match(/:focus/gi) || | ||
(selector.match(/:hover/gi) && selector.match(/:focus/gi)) || | ||
(!selector.match(/:hover/gi) && !selector.match(/:focus/gi)) | ||
) { | ||
return true; | ||
} | ||
if (!isStandardSyntaxSelector(selector)) { | ||
return true; | ||
} | ||
if (isCustomSelector(selector)) { | ||
return true; | ||
} | ||
return false; | ||
function hasAlready(parent, selector) { | ||
return parent.nodes.some(i => { | ||
return i.type === 'rule' && i.selectors.indexOf(selector) !== -1; | ||
}); | ||
} | ||
@@ -44,19 +25,11 @@ | ||
root.walk(node => { | ||
root.walkRules(rule => { | ||
let selector = null; | ||
if (node.type === 'rule') { | ||
if (!isStandardSyntaxRule(node)) { | ||
return; | ||
} | ||
if (!isStandardSyntaxRule(rule)) { | ||
return; | ||
} | ||
selector = node.selector; | ||
} else if (node.type === 'atrule' && node.name === 'page' && node.params) { | ||
if (!isStandardSyntaxAtRule(node)) { | ||
return; | ||
} | ||
selector = rule.selector; | ||
selector = node.params; | ||
} | ||
if (!selector) { | ||
@@ -70,22 +43,17 @@ return; | ||
const parentNodes = node.parent.nodes; | ||
let isAccepted = null; | ||
if (selector.indexOf(':hover') === -1) { | ||
return; | ||
} | ||
if (parentNodes.length > 1) { | ||
const checkParentNodes = parentNodes | ||
.map(parentNode => { | ||
return check(parentNode.selector); | ||
}) | ||
.filter(Boolean); | ||
isAccepted = !!checkParentNodes; | ||
} else { | ||
isAccepted = check(selector); | ||
if (selector.indexOf(':hover') >= 0 && selector.indexOf(':focus') >= 0) { | ||
return; | ||
} | ||
const isAccepted = hasAlready(rule.parent, selector.replace(/:hover/g, ':focus')); | ||
if (!isAccepted) { | ||
utils.report({ | ||
index: node.lastEach, | ||
index: rule.lastEach, | ||
message: messages.expected(selector), | ||
node, | ||
node: rule, | ||
ruleName, | ||
@@ -92,0 +60,0 @@ result, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
255842
49
1555
57