@double-great/stylelint-a11y 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/.babelrc +3 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.js +27 -0
  4. package/.github/dependabot.yml +10 -0
  5. package/.github/workflows/test.yml +21 -0
  6. package/.husky/pre-commit +4 -0
  7. package/LICENSE +21 -0
  8. package/README.md +68 -0
  9. package/dist/index.js +18 -0
  10. package/dist/rules/content-property-no-static-value/__tests__/index.js +37 -0
  11. package/dist/rules/content-property-no-static-value/index.js +90 -0
  12. package/dist/rules/font-size-is-readable/__tests__/index.js +35 -0
  13. package/dist/rules/font-size-is-readable/index.js +77 -0
  14. package/dist/rules/index.js +48 -0
  15. package/dist/rules/line-height-is-vertical-rhythmed/__tests__/index.js +59 -0
  16. package/dist/rules/line-height-is-vertical-rhythmed/index.js +84 -0
  17. package/dist/rules/media-prefers-color-scheme/__tests__/index.js +47 -0
  18. package/dist/rules/media-prefers-color-scheme/index.js +121 -0
  19. package/dist/rules/media-prefers-reduced-motion/__tests__/index.js +41 -0
  20. package/dist/rules/media-prefers-reduced-motion/index.js +175 -0
  21. package/dist/rules/no-display-none/__tests__/index.js +17 -0
  22. package/dist/rules/no-display-none/index.js +76 -0
  23. package/dist/rules/no-obsolete-attribute/__tests__/index.js +27 -0
  24. package/dist/rules/no-obsolete-attribute/index.js +78 -0
  25. package/dist/rules/no-obsolete-attribute/obsoleteAttributes.js +8 -0
  26. package/dist/rules/no-obsolete-element/__tests__/index.js +27 -0
  27. package/dist/rules/no-obsolete-element/index.js +78 -0
  28. package/dist/rules/no-obsolete-element/obsoleteElements.js +8 -0
  29. package/dist/rules/no-outline-none/__tests__/index.js +40 -0
  30. package/dist/rules/no-outline-none/index.js +88 -0
  31. package/dist/rules/no-spread-text/__tests__/index.js +32 -0
  32. package/dist/rules/no-spread-text/index.js +75 -0
  33. package/dist/rules/no-text-align-justify/__tests__/index.js +32 -0
  34. package/dist/rules/no-text-align-justify/index.js +76 -0
  35. package/dist/rules/selector-pseudo-class-focus/__tests__/index.js +46 -0
  36. package/dist/rules/selector-pseudo-class-focus/index.js +121 -0
  37. package/jest.config.js +20 -0
  38. package/jest.setup.js +5 -0
  39. package/package.json +63 -0
  40. package/recommended.js +8 -0
  41. package/src/index.js +8 -0
  42. package/src/rules/content-property-no-static-value/README.md +34 -0
  43. package/src/rules/content-property-no-static-value/__tests__/index.js +48 -0
  44. package/src/rules/content-property-no-static-value/index.js +72 -0
  45. package/src/rules/font-size-is-readable/README.md +34 -0
  46. package/src/rules/font-size-is-readable/__tests__/index.js +45 -0
  47. package/src/rules/font-size-is-readable/index.js +57 -0
  48. package/src/rules/index.js +27 -0
  49. package/src/rules/line-height-is-vertical-rhythmed/README.md +51 -0
  50. package/src/rules/line-height-is-vertical-rhythmed/__tests__/index.js +75 -0
  51. package/src/rules/line-height-is-vertical-rhythmed/index.js +61 -0
  52. package/src/rules/media-prefers-color-scheme/README.md +72 -0
  53. package/src/rules/media-prefers-color-scheme/__tests__/index.js +60 -0
  54. package/src/rules/media-prefers-color-scheme/index.js +115 -0
  55. package/src/rules/media-prefers-reduced-motion/README.md +60 -0
  56. package/src/rules/media-prefers-reduced-motion/__tests__/index.js +55 -0
  57. package/src/rules/media-prefers-reduced-motion/index.js +164 -0
  58. package/src/rules/no-display-none/README.md +27 -0
  59. package/src/rules/no-display-none/__tests__/index.js +21 -0
  60. package/src/rules/no-display-none/index.js +58 -0
  61. package/src/rules/no-obsolete-attribute/README.md +35 -0
  62. package/src/rules/no-obsolete-attribute/__tests__/index.js +33 -0
  63. package/src/rules/no-obsolete-attribute/index.js +58 -0
  64. package/src/rules/no-obsolete-attribute/obsoleteAttributes.js +204 -0
  65. package/src/rules/no-obsolete-element/README.md +20 -0
  66. package/src/rules/no-obsolete-element/__tests__/index.js +33 -0
  67. package/src/rules/no-obsolete-element/index.js +57 -0
  68. package/src/rules/no-obsolete-element/obsoleteElements.js +32 -0
  69. package/src/rules/no-outline-none/README.md +84 -0
  70. package/src/rules/no-outline-none/__tests__/index.js +51 -0
  71. package/src/rules/no-outline-none/index.js +75 -0
  72. package/src/rules/no-spread-text/README.md +50 -0
  73. package/src/rules/no-spread-text/__tests__/index.js +42 -0
  74. package/src/rules/no-spread-text/index.js +72 -0
  75. package/src/rules/no-text-align-justify/README.md +52 -0
  76. package/src/rules/no-text-align-justify/__tests__/index.js +42 -0
  77. package/src/rules/no-text-align-justify/index.js +60 -0
  78. package/src/rules/selector-pseudo-class-focus/README.md +43 -0
  79. package/src/rules/selector-pseudo-class-focus/__tests__/index.js +51 -0
  80. package/src/rules/selector-pseudo-class-focus/index.js +85 -0
package/.babelrc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "presets": ["@babel/preset-env"]
3
+ }
package/.eslintignore ADDED
@@ -0,0 +1,2 @@
1
+ build/*
2
+ node_modules/*
package/.eslintrc.js ADDED
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ extends: ['eslint:recommended', 'prettier'],
3
+ parser: '@babel/eslint-parser',
4
+ parserOptions: {
5
+ sourceType: 'module',
6
+ ecmaVersion: 6,
7
+ },
8
+ env: {
9
+ es6: true,
10
+ jest: true,
11
+ node: true,
12
+ },
13
+ plugins: ['prettier', 'import'],
14
+ globals: {
15
+ testRule: true,
16
+ },
17
+ rules: {
18
+ 'prettier/prettier': [
19
+ 'error',
20
+ {
21
+ printWidth: 100,
22
+ singleQuote: true,
23
+ trailingComma: 'es5',
24
+ },
25
+ ],
26
+ },
27
+ };
@@ -0,0 +1,10 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'monthly'
7
+ - package-ecosystem: 'npm'
8
+ directory: '/'
9
+ schedule:
10
+ interval: 'monthly'
@@ -0,0 +1,21 @@
1
+ name: Test
2
+
3
+ on:
4
+ pull_request:
5
+
6
+ jobs:
7
+ build-npm:
8
+ name: Run NPM install and test
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v3
12
+ - uses: actions/setup-node@v3
13
+ with:
14
+ node-version: 16
15
+ cache: 'npm'
16
+ - name: Test
17
+ run: |
18
+ node -v
19
+ npm -v
20
+ npm ci
21
+ npm run test
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx pretty-quick --staged
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Stanislav
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @double-great/stylelint-a11y
2
+
3
+ ## Installation and usage
4
+
5
+ ```bash
6
+ npm i --save-dev stylelint @double-great/stylelint-a11y
7
+ ```
8
+
9
+ Create the `.stylelintrc.json` config file (or open the existing one), add `stylelint-a11y` to the plugins array and the rules you need to the rules list. All rules from stylelint-a11y need to be namespaced with `a11y`.
10
+
11
+ Please refer to [stylelint docs](https://stylelint.io/user-guide/) for the detailed info on using this linter.
12
+
13
+ ## Rules
14
+
15
+ | Rule ID | Description | |
16
+ | :----------------------------------------------------------------------------------------- | :---------------------------------------------------------------------- | -------------------- |
17
+ | [content-property-no-static-value](./src/rules/content-property-no-static-value/README.md) | Disallow unaccessible CSS generated content in pseudo-elements | |
18
+ | [font-size-is-readable](./src/rules/font-size-is-readable/README.md) | Disallow font sizes less than `15px` | |
19
+ | [line-height-is-vertical-rhythmed](./src/rules/line-height-is-vertical-rhythmed/README.md) | Disallow not vertical rhythmed `line-height` | |
20
+ | [media-prefers-reduced-motion](./src/rules/media-prefers-reduced-motion/README.md) | Require certain styles if the animation or transition in media features | Recommended, Fixable |
21
+ | [media-prefers-color-scheme](./src/rules/media-prefers-color-scheme/README.md) | Require implementation of certain styles for selectors with colors. | |
22
+ | [no-display-none](./src/rules/no-display-none/README.md) | Disallow content hiding with `display: none` property | |
23
+ | [no-obsolete-attribute](./src/rules/no-obsolete-attribute/README.md) | Disallow obsolete attribute using | |
24
+ | [no-obsolete-element](./src/rules/no-obsolete-element/README.md) | Disallow obsolete selectors using | |
25
+ | [no-spread-text](./src/rules/no-spread-text/README.md) | Require width of text in a comfortable range | |
26
+ | [no-outline-none](./src/rules/no-outline-none/README.md) | Disallow outline clearing | Recommended |
27
+ | [no-text-align-justify](./src/rules/no-text-align-justify/README.md) | Disallow content with `text-align: justify` | |
28
+ | [selector-pseudo-class-focus](./src/rules/selector-pseudo-class-focus/README.md) | Require or disallow a pseudo-element to the selectors with `:hover` | Recommended, Fixable |
29
+
30
+ ## Recommended config
31
+
32
+ Add recommended configuration by adding the following to `extends` in your stylelint configuration:
33
+
34
+ ```
35
+ @double-great/stylelint-a11y/recommended
36
+ ```
37
+
38
+ This shareable config contains the following:
39
+
40
+ ```json
41
+ {
42
+ "plugins": ["@double-great/stylelint-a11y"],
43
+ "rules": {
44
+ "a11y/media-prefers-reduced-motion": true,
45
+ "a11y/no-outline-none": true,
46
+ "a11y/selector-pseudo-class-focus": true
47
+ }
48
+ }
49
+ ```
50
+
51
+ Since it adds stylelint-a11y to `plugins`, you don't have to do this yourself when extending this config.
52
+
53
+ ## Help out
54
+
55
+ There work on the plugin's rules is still in progress, so if you feel like it, you're welcome to help out in any of these (the plugin follows stylelint guidelines so most part of this is based on its docs):
56
+
57
+ - Create, enhance, and debug rules (see stylelint's guide to "[Working on rules](https://github.com/stylelint/stylelint/blob/main/docs/developer-guide/rules.md)").
58
+ - Improve documentation.
59
+ - Chime in on any open issue or pull request.
60
+ - Open new issues about your ideas on new rules, or for how to improve the existing ones, and pull requests to show us how your idea works.
61
+ - Add new tests to absolutely anything.
62
+ - Work on improving performance of rules.
63
+ - Contribute to [stylelint](https://github.com/stylelint/stylelint)
64
+ - Spread the word.
65
+
66
+ We communicate via [issues](https://github.com/double-great/stylelint-a11y/issues) and [pull requests](https://github.com/double-great/stylelint-a11y/pulls).
67
+
68
+ There is also [stackoverflow](https://stackoverflow.com/questions/tagged/stylelint), which would be the preferred QA forum.
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _stylelint = require("stylelint");
9
+
10
+ var _rules = _interopRequireDefault(require("./rules"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+
14
+ var rulesPlugins = Object.keys(_rules["default"]).map(function (ruleName) {
15
+ return (0, _stylelint.createPlugin)("a11y/".concat(ruleName), _rules["default"][ruleName]);
16
+ });
17
+ var _default = rulesPlugins;
18
+ exports["default"] = _default;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _index = require("../index");
4
+
5
+ testRule({
6
+ ruleName: _index.ruleName,
7
+ config: [true],
8
+ accept: [{
9
+ code: ".foo::after { content: ''; }"
10
+ }, {
11
+ code: 'a { }'
12
+ }, {
13
+ code: ".foo:after { content: ''; }"
14
+ }, {
15
+ code: '.foo::after { content: ""; }'
16
+ }, {
17
+ code: '.bar::before { content: attr(aria-label); }'
18
+ }, {
19
+ code: ".foo { font-size: '12px'; width: '200px'; }"
20
+ }],
21
+ reject: [{
22
+ code: '.foo::before { content: "bar"; }',
23
+ message: _index.messages.expected('.foo::before'),
24
+ line: 1,
25
+ column: 3
26
+ }, {
27
+ code: '.bar::before { content: 23; }',
28
+ message: _index.messages.expected('.bar::before'),
29
+ line: 1,
30
+ column: 3
31
+ }, {
32
+ code: ".foo:before, .bar { content: ''; }",
33
+ message: _index.messages.expected('.foo:before, .bar'),
34
+ line: 1,
35
+ column: 3
36
+ }]
37
+ });
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = _default;
7
+ exports.ruleName = exports.messages = void 0;
8
+
9
+ var _stylelint = require("stylelint");
10
+
11
+ var _isStandardSyntaxRule = _interopRequireDefault(require("stylelint/lib/utils/isStandardSyntaxRule"));
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+
15
+ var ruleName = 'a11y/content-property-no-static-value';
16
+ exports.ruleName = ruleName;
17
+
18
+ var messages = _stylelint.utils.ruleMessages(ruleName, {
19
+ expected: function expected(selector) {
20
+ return "Unexpected using \"content\" property in ".concat(selector);
21
+ }
22
+ });
23
+
24
+ exports.messages = messages;
25
+
26
+ var isContentPropertyUsedCorrectly = function isContentPropertyUsedCorrectly(selectors) {
27
+ return selectors.every(function (selector) {
28
+ return /:before|:after/.test(selector);
29
+ });
30
+ };
31
+
32
+ var checkNodesForContentProperty = function checkNodesForContentProperty(node) {
33
+ return node.nodes.filter(function (node) {
34
+ return node.prop;
35
+ }).some(function (node) {
36
+ return node.prop.toLowerCase() === 'content';
37
+ });
38
+ };
39
+
40
+ function check(node) {
41
+ if (node.type !== 'rule' || !checkNodesForContentProperty(node) || !node.first) {
42
+ return true;
43
+ }
44
+
45
+ return node.nodes.some(function (o) {
46
+ return o.type === 'decl' && o.prop.toLowerCase() === 'content' && isContentPropertyUsedCorrectly(o.parent.selectors) && (o.value.toLowerCase() === "''" || o.value.toLowerCase() === '""' || o.value.toLowerCase() === 'attr(aria-label)');
47
+ });
48
+ }
49
+
50
+ function _default(actual) {
51
+ return function (root, result) {
52
+ var validOptions = _stylelint.utils.validateOptions(result, ruleName, {
53
+ actual: actual
54
+ });
55
+
56
+ if (!validOptions || !actual) {
57
+ return;
58
+ }
59
+
60
+ root.walk(function (node) {
61
+ var selector = null;
62
+
63
+ if (node.type === 'rule') {
64
+ if (!(0, _isStandardSyntaxRule["default"])(node)) {
65
+ return;
66
+ }
67
+
68
+ selector = node.selector;
69
+ } else if (node.type === 'atrule' && node.name.toLowerCase() === 'page' && node.params) {
70
+ selector = node.params;
71
+ }
72
+
73
+ if (!selector) {
74
+ return;
75
+ }
76
+
77
+ var isAccepted = check(node);
78
+
79
+ if (!isAccepted) {
80
+ _stylelint.utils.report({
81
+ index: node.lastEach,
82
+ message: messages.expected(selector),
83
+ node: node,
84
+ ruleName: ruleName,
85
+ result: result
86
+ });
87
+ }
88
+ });
89
+ };
90
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ var _index = require("../index");
4
+
5
+ testRule({
6
+ ruleName: _index.ruleName,
7
+ config: [true],
8
+ accept: [{
9
+ code: '.foo { }'
10
+ }, {
11
+ code: '.foo { font-size: 15px; }'
12
+ }, {
13
+ code: '.foo { font-size: 12pt; }'
14
+ }, {
15
+ code: '.bar { FONT-SIZE: 15PX; }'
16
+ }, {
17
+ code: '.baz { font-size: 1em; }'
18
+ }],
19
+ reject: [{
20
+ code: '.foo { font-size: 10px; }',
21
+ message: _index.messages.expected('.foo'),
22
+ line: 1,
23
+ column: 3
24
+ }, {
25
+ code: '.foo { font-size: 3pt; }',
26
+ message: _index.messages.expected('.foo'),
27
+ line: 1,
28
+ column: 3
29
+ }, {
30
+ code: '.bar { FONT-SIZE: 8PX; }',
31
+ message: _index.messages.expected('.bar'),
32
+ line: 1,
33
+ column: 3
34
+ }]
35
+ });
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = _default;
7
+ exports.ruleName = exports.messages = void 0;
8
+
9
+ var _stylelint = require("stylelint");
10
+
11
+ var _isStandardSyntaxRule = _interopRequireDefault(require("stylelint/lib/utils/isStandardSyntaxRule"));
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+
15
+ var ruleName = 'a11y/font-size-is-readable';
16
+ exports.ruleName = ruleName;
17
+
18
+ var messages = _stylelint.utils.ruleMessages(ruleName, {
19
+ expected: function expected(selector) {
20
+ return "Expected a larger font-size in ".concat(selector);
21
+ }
22
+ });
23
+
24
+ exports.messages = messages;
25
+ var THRESHOLD_IN_PX = 15;
26
+
27
+ var pxToPt = function pxToPt(v) {
28
+ return 0.75 * v;
29
+ };
30
+
31
+ var checkInPx = function checkInPx(value) {
32
+ return value.toLowerCase().endsWith('px') && parseFloat(value) < THRESHOLD_IN_PX;
33
+ };
34
+
35
+ var checkInPt = function checkInPt(value) {
36
+ return value.toLowerCase().endsWith('pt') && parseFloat(value) < pxToPt(THRESHOLD_IN_PX);
37
+ };
38
+
39
+ function _default(actual) {
40
+ return function (root, result) {
41
+ var validOptions = _stylelint.utils.validateOptions(result, ruleName, {
42
+ actual: actual
43
+ });
44
+
45
+ if (!validOptions || !actual) {
46
+ return;
47
+ }
48
+
49
+ root.walkRules(function (rule) {
50
+ var selector = null;
51
+
52
+ if (!(0, _isStandardSyntaxRule["default"])(rule)) {
53
+ return;
54
+ }
55
+
56
+ selector = rule.selector;
57
+
58
+ if (!selector) {
59
+ return;
60
+ }
61
+
62
+ var isRejected = rule.nodes.some(function (o) {
63
+ return o.type === 'decl' && o.prop.toLowerCase() === 'font-size' && (checkInPx(o.value) || checkInPt(o.value));
64
+ });
65
+
66
+ if (isRejected) {
67
+ _stylelint.utils.report({
68
+ index: rule.lastEach,
69
+ message: messages.expected(selector),
70
+ node: rule,
71
+ ruleName: ruleName,
72
+ result: result
73
+ });
74
+ }
75
+ });
76
+ };
77
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _contentPropertyNoStaticValue = _interopRequireDefault(require("./content-property-no-static-value"));
9
+
10
+ var _fontSizeIsReadable = _interopRequireDefault(require("./font-size-is-readable"));
11
+
12
+ var _lineHeightIsVerticalRhythmed = _interopRequireDefault(require("./line-height-is-vertical-rhythmed"));
13
+
14
+ var _mediaPrefersReducedMotion = _interopRequireDefault(require("./media-prefers-reduced-motion"));
15
+
16
+ var _noDisplayNone = _interopRequireDefault(require("./no-display-none"));
17
+
18
+ var _noObsoleteAttribute = _interopRequireDefault(require("./no-obsolete-attribute"));
19
+
20
+ var _noObsoleteElement = _interopRequireDefault(require("./no-obsolete-element"));
21
+
22
+ var _noOutlineNone = _interopRequireDefault(require("./no-outline-none"));
23
+
24
+ var _noSpreadText = _interopRequireDefault(require("./no-spread-text"));
25
+
26
+ var _noTextAlignJustify = _interopRequireDefault(require("./no-text-align-justify"));
27
+
28
+ var _selectorPseudoClassFocus = _interopRequireDefault(require("./selector-pseudo-class-focus"));
29
+
30
+ var _mediaPrefersColorScheme = _interopRequireDefault(require("./media-prefers-color-scheme"));
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
33
+
34
+ var _default = {
35
+ 'content-property-no-static-value': _contentPropertyNoStaticValue["default"],
36
+ 'font-size-is-readable': _fontSizeIsReadable["default"],
37
+ 'line-height-is-vertical-rhythmed': _lineHeightIsVerticalRhythmed["default"],
38
+ 'media-prefers-reduced-motion': _mediaPrefersReducedMotion["default"],
39
+ 'no-display-none': _noDisplayNone["default"],
40
+ 'no-obsolete-attribute': _noObsoleteAttribute["default"],
41
+ 'no-obsolete-element': _noObsoleteElement["default"],
42
+ 'no-outline-none': _noOutlineNone["default"],
43
+ 'no-spread-text': _noSpreadText["default"],
44
+ 'no-text-align-justify': _noTextAlignJustify["default"],
45
+ 'selector-pseudo-class-focus': _selectorPseudoClassFocus["default"],
46
+ 'media-prefers-color-scheme': _mediaPrefersColorScheme["default"]
47
+ };
48
+ exports["default"] = _default;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ var _index = require("../index");
4
+
5
+ testRule({
6
+ ruleName: _index.ruleName,
7
+ config: [true],
8
+ accept: [{
9
+ code: 'a { }'
10
+ }, {
11
+ code: '.smallText { line-height: 24px; }'
12
+ }, {
13
+ code: '.largeText { line-height: 48px; }'
14
+ }, {
15
+ code: '.relText { line-height: 1.5; }'
16
+ }, {
17
+ code: '.smallTextU { LINE-HEIGHT: 24PX; }'
18
+ }, {
19
+ code: 'body { font-size: 15px; line-height: 48px; }'
20
+ }, {
21
+ code: 'a { font-size: 15px; line-height: 1.6; }'
22
+ }],
23
+ reject: [{
24
+ code: '.foo { line-height: 12px; }',
25
+ message: _index.messages.expected('.foo'),
26
+ line: 1,
27
+ column: 3
28
+ }, {
29
+ code: '.foo { line-height: 50px; }',
30
+ message: _index.messages.expected('.foo'),
31
+ line: 1,
32
+ column: 3
33
+ }, {
34
+ code: '.foo { line-height: 1.2; }',
35
+ message: _index.messages.expected('.foo'),
36
+ line: 1,
37
+ column: 3
38
+ }, {
39
+ code: '.foo { line-height: 12px; }',
40
+ message: _index.messages.expected('.foo'),
41
+ line: 1,
42
+ column: 3
43
+ }, {
44
+ code: '.foo { LINE-HEIGHT: 23PX; }',
45
+ message: _index.messages.expected('.foo'),
46
+ line: 1,
47
+ column: 3
48
+ }, {
49
+ code: 'p { font-size: 23px; line-height: 23px; }',
50
+ message: _index.messages.expected('p'),
51
+ line: 1,
52
+ column: 3
53
+ }, {
54
+ code: 'a { font-size: 23px; line-height: 1; }',
55
+ message: _index.messages.expected('a'),
56
+ line: 1,
57
+ column: 3
58
+ }]
59
+ });
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = _default;
7
+ exports.ruleName = exports.messages = void 0;
8
+
9
+ var _stylelint = require("stylelint");
10
+
11
+ var _isStandardSyntaxRule = _interopRequireDefault(require("stylelint/lib/utils/isStandardSyntaxRule"));
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
+
15
+ var ruleName = 'a11y/line-height-is-vertical-rhythmed';
16
+ exports.ruleName = ruleName;
17
+
18
+ var messages = _stylelint.utils.ruleMessages(ruleName, {
19
+ expected: function expected(selector) {
20
+ return "Expected a vertical rhythmed line-height in ".concat(selector);
21
+ }
22
+ });
23
+
24
+ exports.messages = messages;
25
+
26
+ function check(node) {
27
+ if (node.type !== 'rule') {
28
+ return true;
29
+ }
30
+
31
+ var checkInPx = function checkInPx(o) {
32
+ return o.value.toLowerCase().endsWith('px') && parseInt(o.value) % 24 !== 0;
33
+ };
34
+
35
+ var checkInRel = function checkInRel(o) {
36
+ return !isNaN(o.value) && parseFloat(o.value) < 1.5;
37
+ };
38
+
39
+ return !node.nodes.some(function (o) {
40
+ return o.type === 'decl' && o.prop.toLowerCase() === 'line-height' && (checkInPx(o) || checkInRel(o));
41
+ });
42
+ }
43
+
44
+ function _default(actual) {
45
+ return function (root, result) {
46
+ var validOptions = _stylelint.utils.validateOptions(result, ruleName, {
47
+ actual: actual
48
+ });
49
+
50
+ if (!validOptions || !actual) {
51
+ return;
52
+ }
53
+
54
+ root.walk(function (node) {
55
+ var selector = null;
56
+
57
+ if (node.type === 'rule') {
58
+ if (!(0, _isStandardSyntaxRule["default"])(node)) {
59
+ return;
60
+ }
61
+
62
+ selector = node.selector;
63
+ } else if (node.type === 'atrule' && node.name.toLowerCase() === 'page' && node.params) {
64
+ selector = node.params;
65
+ }
66
+
67
+ if (!selector) {
68
+ return;
69
+ }
70
+
71
+ var isAccepted = check(node);
72
+
73
+ if (!isAccepted) {
74
+ _stylelint.utils.report({
75
+ index: node.lastEach,
76
+ message: messages.expected(selector),
77
+ node: node,
78
+ ruleName: ruleName,
79
+ result: result
80
+ });
81
+ }
82
+ });
83
+ };
84
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ var _index = require("../index");
4
+
5
+ testRule({
6
+ ruleName: _index.ruleName,
7
+ config: [true],
8
+ accept: [{
9
+ code: 'a { }'
10
+ }, {
11
+ code: '.foo { color: red } @media screen and (prefers-color-scheme: dark) { .foo { color: blue } }'
12
+ }, {
13
+ code: '.bar { background-color: red } @media screen and (prefers-color-scheme: dark) { .bar { background-color: blue } }'
14
+ }],
15
+ reject: [{
16
+ code: 'a { color: red; }',
17
+ message: _index.messages.expected('a'),
18
+ line: 1,
19
+ column: 3
20
+ }, {
21
+ code: 'a { color: red; } @media screen and (prefers-color-scheme: dark) { a { background-color: red; } }',
22
+ message: _index.messages.expected('a'),
23
+ line: 1,
24
+ column: 3
25
+ }, {
26
+ code: '.foo { background-color: red;}',
27
+ message: _index.messages.expected('.foo'),
28
+ line: 1,
29
+ column: 3
30
+ }, {
31
+ code: '.bar { color: red; } .baz { background-color: red; } @media screen and (prefers-color-scheme: dark) { .baz { color: blue; } }',
32
+ warnings: [{
33
+ message: _index.messages.expected('.bar'),
34
+ line: 1,
35
+ column: 3
36
+ }, {
37
+ message: _index.messages.expected('.baz'),
38
+ line: 1,
39
+ column: 24
40
+ }]
41
+ }, {
42
+ code: '.foo { background-color: red; } @media screen and (prefers-color-scheme) { .foo { color: red; } }',
43
+ message: _index.messages.expected('.foo'),
44
+ line: 1,
45
+ column: 3
46
+ }]
47
+ });