From 5e48f43172faf7b8f4f51480600473648388c151 Mon Sep 17 00:00:00 2001 From: Nick Charlton Date: Tue, 30 Jan 2024 17:27:23 +0000 Subject: [PATCH] Remove deprecated rules, but test for future ones Upgrading `stylelint` to v15 deprecated a bunch of rules, which are intended to be handled by Prettier instead. This removes the style rules deprecated in that upgrade, alongside others which have changed. To try and catch when future rules are deprecated in upgrades, we add a test to see if the rule is listed as deprecated. Unfortunately, not all plugins follow the same method signature, so we need to check if `stylelint` knows about the rules before asserting on them. https://github.com/stylelint/stylelint/blob/main/docs/migration-guide/to-15.md https://github.com/stylelint/stylelint-config-standard/blob/main/__tests__/index.test.mjs --- __tests__/index.test.mjs | 34 ++++++++++++++-------------------- index.js | 38 +------------------------------------- 2 files changed, 15 insertions(+), 57 deletions(-) diff --git a/__tests__/index.test.mjs b/__tests__/index.test.mjs index 71be40a..27d3ce3 100644 --- a/__tests__/index.test.mjs +++ b/__tests__/index.test.mjs @@ -12,7 +12,19 @@ describe('rules', () => { it('is not empty', () => { assert.ok(ruleNames.length > 0); }); -}) + + ruleNames.forEach((ruleName) => { + it(`${ruleName}`, async () => { + const rule = await stylelint.rules[ruleName]; + + // rules like `stylelint-order` don't have the same method signature and + // so we can't tell if they're deprectated or not + if (typeof rule !== 'undefined') { + assert.ok(!rule.meta.deprecated, `the ${ruleName} rule is deprecated`); + } + }); + }); +}); describe('with the valid example', () => { const validScss = fs.readFileSync('./__tests__/valid.scss', 'utf-8'); @@ -50,7 +62,7 @@ describe('with the invalid example', () => { }); it('has the correct amount of warnings', () => { - assert.equal(result.results[0].warnings.length, 46); + assert.equal(result.results[0].warnings.length, 28); }); it('flags the correct rules', () => { @@ -67,42 +79,24 @@ describe('with the invalid example', () => { 'scss/map-keys-quotes', 'scss/no-duplicate-dollar-variables', 'scss/dollar-variable-empty-line-before', - 'block-closing-brace-empty-line-before', 'block-no-empty', - 'block-opening-brace-space-before', - 'color-hex-case', - 'color-hex-case', 'color-hex-length', 'color-named', 'color-named', 'comment-whitespace-inside', 'comment-whitespace-inside', 'declaration-block-no-redundant-longhand-properties', - 'declaration-block-semicolon-newline-before', - 'declaration-block-semicolon-space-before', - 'declaration-block-trailing-semicolon', - 'declaration-block-trailing-semicolon', 'declaration-empty-line-before', 'declaration-empty-line-before', 'declaration-no-important', 'declaration-property-unit-allowed-list', 'declaration-property-value-disallowed-list', - 'max-empty-lines', - 'max-empty-lines', 'max-nesting-depth', - 'no-empty-first-line', 'property-no-unknown', 'property-no-vendor-prefix', - 'selector-list-comma-newline-after', - 'selector-list-comma-space-before', 'selector-max-id', 'selector-max-id', - 'selector-pseudo-element-case', 'selector-pseudo-element-colon-notation', - 'unit-case', - 'indentation', - 'indentation', - 'indentation', ], ); }); diff --git a/index.js b/index.js index 3be7471..bf2527e 100644 --- a/index.js +++ b/index.js @@ -6,23 +6,10 @@ module.exports = { ], "rules": { "at-rule-no-unknown": null, - "block-closing-brace-empty-line-before": "never", - "block-closing-brace-newline-before": "always-multi-line", - "block-opening-brace-newline-after": "always-multi-line", - "block-opening-brace-space-before": "always", - "color-hex-case": "lower", "color-hex-length": "long", "color-named": "never", "comment-whitespace-inside": "always", - "declaration-bang-space-after": "never", - "declaration-bang-space-before": "always", "declaration-block-no-redundant-longhand-properties": true, - "declaration-block-semicolon-newline-after": "always", - "declaration-block-semicolon-newline-before": "never-multi-line", - "declaration-block-semicolon-space-before": "never", - "declaration-block-trailing-semicolon": "always", - "declaration-colon-space-after": "always-single-line", - "declaration-colon-space-before": "never", "declaration-no-important": true, "declaration-property-unit-allowed-list": { "line-height": [] @@ -30,28 +17,12 @@ module.exports = { "declaration-property-value-disallowed-list": { "/^transition/": ["/all/"] }, - "function-comma-space-after": "always-single-line", - "function-comma-space-before": "never", - "function-parentheses-space-inside": "never-single-line", "function-url-quotes": "always", - "indentation": 2, "length-zero-no-unit": true, - "max-empty-lines": 1, - "max-line-length": 80, "max-nesting-depth": 3, - "media-query-list-comma-newline-after": "always-multi-line", - "media-query-list-comma-newline-before": "never-multi-line", - "media-query-list-comma-space-after": "always", - "media-query-list-comma-space-before": "never", - "no-empty-first-line": true, "no-empty-source": true, - "no-eol-whitespace": true, - "no-missing-end-of-source-newline": true, - "number-leading-zero": "always", - "number-no-trailing-zeros": true, "order/properties-alphabetical-order": true, "plugin/declaration-block-no-ignored-properties": true, - "property-case": "lower", "property-no-unknown": [ true, { @@ -75,7 +46,7 @@ module.exports = { "scss/at-else-if-parentheses-space-before": "never", "scss/at-extend-no-missing-placeholder": true, "scss/at-function-parentheses-space-before": "never", - "scss/at-import-no-partial-leading-underscore": true, + "scss/load-no-partial-leading-underscore": true, "scss/at-import-partial-extension-blacklist": ["scss"], "scss/at-mixin-parentheses-space-before": "never", "scss/at-rule-no-unknown": true, @@ -86,19 +57,12 @@ module.exports = { "scss/operator-no-unspaced": true, "scss/selector-no-redundant-nesting-selector": true, "scss/selector-no-union-class-name": true, - "selector-list-comma-newline-after": "always", - "selector-list-comma-newline-before": "never-multi-line", - "selector-list-comma-space-before": "never", "selector-max-id": 0, "selector-no-qualifying-type": true, "selector-no-vendor-prefix": true, - "selector-pseudo-class-case": "lower", - "selector-pseudo-element-case": "lower", "selector-pseudo-element-colon-notation": "double", "selector-type-case": "lower", "shorthand-property-no-redundant-values": true, - "string-quotes": "double", - "unit-case": "lower", "value-keyword-case": "lower", "value-no-vendor-prefix": true }