From cf70e1dd18897036e3979dc4e519d268f62512a3 Mon Sep 17 00:00:00 2001 From: "LB (Ben Johnston)" Date: Fri, 21 Jul 2023 01:08:12 +1000 Subject: [PATCH] Prevent `forced-color-adjust` usage (#35). Fix #32 Co-authored-by: LB Johnston --- README.md | 2 +- __tests__/__snapshots__/index.test.js.snap | 46 +++++++++++----------- __tests__/index.test.js | 14 +++++-- __tests__/scss-invalid.scss | 1 + index.js | 2 + 5 files changed, 38 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index ac2581f..115f033 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Our default export contains all of our Stylelint rules, along with specific plug | [`no-invalid-position-at-import-rule`][30] | `{"ignoreAtRules":["use","forward"]}` | | [`no-irregular-whitespace`][31] | Enabled | | [`order/order`][32] | `[{"name":"include","type":"at-rule"},"declarations"]` | -| [`property-disallowed-list`][33] | `["/left/","/right/","text-transform"]` | +| [`property-disallowed-list`][33] | `["/forced-color-adjust/","/left/","/right/","text-transform"]` | | [`property-no-unknown`][34] | Enabled | | [`property-no-vendor-prefix`][35] | Enabled | | [`rule-empty-line-before`][36] | `"always", {"except":["after-single-line-comment","first-nested"]}` | diff --git a/__tests__/__snapshots__/index.test.js.snap b/__tests__/__snapshots__/index.test.js.snap index 3846a4b..6cc4080 100644 --- a/__tests__/__snapshots__/index.test.js.snap +++ b/__tests__/__snapshots__/index.test.js.snap @@ -1,27 +1,27 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`flags warnings with invalid css did error 1`] = ` -[ - "order/order", - "scale-unlimited/declaration-strict-value", - "scss/selector-no-union-class-name", - "scss/at-rule-no-unknown", - "scss/comment-no-empty", - "block-no-empty", - "color-named", - "comment-no-empty", - "declaration-block-no-duplicate-properties", - "declaration-property-value-allowed-list", - "declaration-property-value-disallowed-list", - "length-zero-no-unit", - "max-nesting-depth", - "property-disallowed-list", - "rule-empty-line-before", - "selector-attribute-name-disallowed-list", - "selector-class-pattern", - "selector-max-combinators", - "selector-max-id", - "selector-max-specificity", - "unit-no-unknown", -] +{ + "block-no-empty": 1, + "color-named": 1, + "comment-no-empty": 1, + "declaration-block-no-duplicate-properties": 1, + "declaration-property-value-allowed-list": 2, + "declaration-property-value-disallowed-list": 3, + "length-zero-no-unit": 1, + "max-nesting-depth": 1, + "order/order": 1, + "property-disallowed-list": 3, + "rule-empty-line-before": 8, + "scale-unlimited/declaration-strict-value": 9, + "scss/at-rule-no-unknown": 1, + "scss/comment-no-empty": 1, + "scss/selector-no-union-class-name": 1, + "selector-attribute-name-disallowed-list": 1, + "selector-class-pattern": 2, + "selector-max-combinators": 2, + "selector-max-id": 1, + "selector-max-specificity": 5, + "unit-no-unknown": 1, +} `; diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 1f577ae..cff0a5a 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -49,9 +49,17 @@ describe('flags warnings with invalid css', () => { expect(data.errored).toBeTruthy(); // output unique error names to a snapshot - expect([ - ...new Set(data.results[0].warnings.map(({ rule }) => rule)), - ]).toMatchSnapshot(); + expect( + data.results[0].warnings + .map(({ rule }) => rule) + .reduce( + (rulesWithCount, rule) => ({ + ...rulesWithCount, + [rule]: (rulesWithCount[rule] || 0) + 1, + }), + {}, + ), + ).toMatchSnapshot(); done(); }); diff --git a/__tests__/scss-invalid.scss b/__tests__/scss-invalid.scss index 744d1f2..80fd484 100644 --- a/__tests__/scss-invalid.scss +++ b/__tests__/scss-invalid.scss @@ -81,6 +81,7 @@ float: left; margin-right: 1em; text-align: right; + forced-color-adjust: none; @include optionalItem; // should not be at the bottom } diff --git a/index.js b/index.js index 700db90..bacde5e 100644 --- a/index.js +++ b/index.js @@ -42,6 +42,8 @@ module.exports = { 'declarations', ], 'property-disallowed-list': [ + // There are very few cases where it’s the correct approach. + '/forced-color-adjust/', // Disallow positioning with physical properties. Use logical ones instead. '/left/', '/right/',