From 406c72ab504b7b8739fba9c0576320ac733f8c5b Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Thu, 26 Dec 2024 18:56:02 +0100 Subject: [PATCH 1/6] Add support for replacement text --- getTestRule.js | 68 ++++++++++++++++++++++++++++++-------------------- index.d.ts | 4 +++ 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/getTestRule.js b/getTestRule.js index 33c5fb9..b1943e3 100644 --- a/getTestRule.js +++ b/getTestRule.js @@ -68,6 +68,7 @@ module.exports = function getTestRule(options = {}) { config: stylelintConfig, customSyntax: schema.customSyntax, codeFilename: testCase.codeFilename || schema.codeFilename, + computeReplacementText: schema.computeReplacementText, }; const outputAfterLint = await lint(stylelintOptions); @@ -90,6 +91,7 @@ module.exports = function getTestRule(options = {}) { column: expected.column, endLine: expected.endLine, endColumn: expected.endColumn, + fix: expected.fix, }; for (const [key, value] of Object.entries(expectedWarning)) { @@ -100,44 +102,56 @@ module.exports = function getTestRule(options = {}) { } expect(actualWarnings[i]).toMatchObject(expectedWarning); - } - - if (!schema.fix) return; - // Check that --fix doesn't change code - if (schema.fix && !testCase.fixed && testCase.fixed !== '' && !testCase.unfixable) { - throw new Error( - 'If using { fix: true } in test schema, all reject cases must have { fixed: .. }', - ); + // @ts-expect-error - API needs to be updated and released + if (actualWarnings[i].fix) { + // @ts-expect-error - API needs to be updated and released + expect(actualWarnings[i].fix).toEqual(expect.objectContaining(expectedWarning.fix)); + } } - const outputAfterFix = await lint({ ...stylelintOptions, fix: true }); + if (schema.fix) { + // Check that --fix does change code + if (!testCase.fixed && testCase.fixed !== '' && !testCase.unfixable) { + throw new Error( + 'If using { fix: true } in test schema, all reject cases must have { fixed: .. }', + ); + } - const fixedCode = getOutputCss(outputAfterFix); + const outputAfterFix = await lint({ ...stylelintOptions, fix: true }); + + const fixedCode = getOutputCss(outputAfterFix); - if (!testCase.unfixable) { - expect(fixedCode).toBe(testCase.fixed); - expect(fixedCode).not.toBe(testCase.code); - } else { - // can't fix - if (testCase.fixed) { + if (!testCase.unfixable) { expect(fixedCode).toBe(testCase.fixed); + expect(fixedCode).not.toBe(testCase.code); + } else { + // can't fix + if (testCase.fixed) { + expect(fixedCode).toBe(testCase.fixed); + } + + expect(fixedCode).toBe(testCase.code); } - expect(fixedCode).toBe(testCase.code); + // Checks whether only errors other than those fixed are reported + const outputAfterLintOnFixedCode = await lint({ + ...stylelintOptions, + code: fixedCode, + fix: testCase.unfixable, + }); + + expect(outputAfterLintOnFixedCode.results[0]).toMatchObject({ + warnings: outputAfterFix.results[0].warnings, + parseErrors: [], + }); } - // Checks whether only errors other than those fixed are reported - const outputAfterLintOnFixedCode = await lint({ - ...stylelintOptions, - code: fixedCode, - fix: testCase.unfixable, - }); + if (schema.computeReplacementText) { + const outputAfterFix = await lint({ ...stylelintOptions }); - expect(outputAfterLintOnFixedCode.results[0]).toMatchObject({ - warnings: outputAfterFix.results[0].warnings, - parseErrors: [], - }); + expect(outputAfterFix.code).toBeUndefined(); + } }, }); }); diff --git a/index.d.ts b/index.d.ts index 95ba6b0..79376c3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -57,6 +57,8 @@ export type Warning = { * Expected end column number of the warning. */ endColumn?: number; + + fix?: { range: Range; text: string }; }; /** @@ -108,6 +110,8 @@ export type TestSchema = { */ fix?: boolean; + computeReplacementText?: boolean; + /** * Maps to Stylelint's `plugins` configuration property. * From 5120172d784faadded2bfd218be89c52996d2ee9 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Fri, 27 Dec 2024 00:06:31 +0100 Subject: [PATCH 2/6] fix --- getTestRule.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/getTestRule.js b/getTestRule.js index b1943e3..3424ddb 100644 --- a/getTestRule.js +++ b/getTestRule.js @@ -102,12 +102,6 @@ module.exports = function getTestRule(options = {}) { } expect(actualWarnings[i]).toMatchObject(expectedWarning); - - // @ts-expect-error - API needs to be updated and released - if (actualWarnings[i].fix) { - // @ts-expect-error - API needs to be updated and released - expect(actualWarnings[i].fix).toEqual(expect.objectContaining(expectedWarning.fix)); - } } if (schema.fix) { From 9a4e69f3c102aa3f28be750e49bc1c2d2a82c44b Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 25 Jan 2025 16:32:17 +0100 Subject: [PATCH 3/6] renames and cleanup --- getTestRule.js | 62 ++++---- index.d.ts | 7 +- package-lock.json | 361 ++++++++++++++++++++++++++++++++-------------- package.json | 2 +- 4 files changed, 290 insertions(+), 142 deletions(-) diff --git a/getTestRule.js b/getTestRule.js index 3424ddb..ca91bdc 100644 --- a/getTestRule.js +++ b/getTestRule.js @@ -68,7 +68,7 @@ module.exports = function getTestRule(options = {}) { config: stylelintConfig, customSyntax: schema.customSyntax, codeFilename: testCase.codeFilename || schema.codeFilename, - computeReplacementText: schema.computeReplacementText, + computeEditInfo: schema.computeEditInfo, }; const outputAfterLint = await lint(stylelintOptions); @@ -104,48 +104,42 @@ module.exports = function getTestRule(options = {}) { expect(actualWarnings[i]).toMatchObject(expectedWarning); } - if (schema.fix) { - // Check that --fix does change code - if (!testCase.fixed && testCase.fixed !== '' && !testCase.unfixable) { - throw new Error( - 'If using { fix: true } in test schema, all reject cases must have { fixed: .. }', - ); - } + if (!schema.fix) return; - const outputAfterFix = await lint({ ...stylelintOptions, fix: true }); + // Check that --fix doesn't change code + if (schema.fix && !testCase.fixed && testCase.fixed !== '' && !testCase.unfixable) { + throw new Error( + 'If using { fix: true } in test schema, all reject cases must have { fixed: .. }', + ); + } - const fixedCode = getOutputCss(outputAfterFix); + const outputAfterFix = await lint({ ...stylelintOptions, fix: true }); - if (!testCase.unfixable) { - expect(fixedCode).toBe(testCase.fixed); - expect(fixedCode).not.toBe(testCase.code); - } else { - // can't fix - if (testCase.fixed) { - expect(fixedCode).toBe(testCase.fixed); - } + const fixedCode = getOutputCss(outputAfterFix); - expect(fixedCode).toBe(testCase.code); + if (!testCase.unfixable) { + expect(fixedCode).toBe(testCase.fixed); + expect(fixedCode).not.toBe(testCase.code); + } else { + // can't fix + if (testCase.fixed) { + expect(fixedCode).toBe(testCase.fixed); } - // Checks whether only errors other than those fixed are reported - const outputAfterLintOnFixedCode = await lint({ - ...stylelintOptions, - code: fixedCode, - fix: testCase.unfixable, - }); - - expect(outputAfterLintOnFixedCode.results[0]).toMatchObject({ - warnings: outputAfterFix.results[0].warnings, - parseErrors: [], - }); + expect(fixedCode).toBe(testCase.code); } - if (schema.computeReplacementText) { - const outputAfterFix = await lint({ ...stylelintOptions }); + // Checks whether only errors other than those fixed are reported + const outputAfterLintOnFixedCode = await lint({ + ...stylelintOptions, + code: fixedCode, + fix: testCase.unfixable, + }); - expect(outputAfterFix.code).toBeUndefined(); - } + expect(outputAfterLintOnFixedCode.results[0]).toMatchObject({ + warnings: outputAfterFix.results[0].warnings, + parseErrors: [], + }); }, }); }); diff --git a/index.d.ts b/index.d.ts index 79376c3..b89258b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -110,7 +110,12 @@ export type TestSchema = { */ fix?: boolean; - computeReplacementText?: boolean; + /** + * Turn on computing `EditInfo`. Default: `false`. + * + * @experimental + */ + computeEditInfo?: boolean; /** * Maps to Stylelint's `plugins` configuration property. diff --git a/package-lock.json b/package-lock.json index f0e0678..f882607 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "npm-run-all": "^4.1.5", "prettier": "^3.4.1", "remark-cli": "^12.0.1", - "stylelint": "^16.11.0", + "stylelint": "^16.14.0", "typescript": "^5.7.2" }, "engines": { @@ -1445,6 +1445,41 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@keyv/serialize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@keyv/serialize/-/serialize-1.0.2.tgz", + "integrity": "sha512-+E/LyaAeuABniD/RvUezWVXKpeuvwLEA9//nE9952zBaOdBd2mQ3pPoM8cUe2X6IcMByfuSLzmYqnYshG60+HQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "buffer": "^6.0.3" + } + }, + "node_modules/@keyv/serialize/node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, "node_modules/@ljharb/through": { "version": "2.3.12", "resolved": "https://registry.npmjs.org/@ljharb/through/-/through-2.3.12.tgz", @@ -2301,6 +2336,7 @@ "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-2.0.0.tgz", "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -2750,6 +2786,27 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/cacheable": { + "version": "1.8.8", + "resolved": "https://registry.npmjs.org/cacheable/-/cacheable-1.8.8.tgz", + "integrity": "sha512-OE1/jlarWxROUIpd0qGBSKFLkNsotY8pt4GeiVErUYh/NUeTNrT+SBksUgllQv4m6a0W/VZsLuiHb88maavqEw==", + "dev": true, + "license": "MIT", + "dependencies": { + "hookified": "^1.7.0", + "keyv": "^5.2.3" + } + }, + "node_modules/cacheable/node_modules/keyv": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-5.2.3.tgz", + "integrity": "sha512-AGKecUfzrowabUv0bH1RIR5Vf7w+l4S3xtQAypKaUpTdIR1EbrAcTxHCrpo9Q+IWeUlFE2palRtgIQcgm+PQJw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@keyv/serialize": "^1.0.2" + } + }, "node_modules/call-bind": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", @@ -3353,12 +3410,13 @@ } }, "node_modules/css-tree": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.0.1.tgz", - "integrity": "sha512-8Fxxv+tGhORlshCdCwnNJytvlvq46sOLSYEx2ZIGurahWvMucSRnyjPA3AmrMq4VPRYbHVpWj5VkiVasrM2H4Q==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.1.0.tgz", + "integrity": "sha512-0eW44TGN5SQXU1mWSkKwFstI/22X2bG1nYzZTYMAWjylYURhse752YgbE4Cx46AC+bAvI+/dYTPRk1LqSUnu6w==", "dev": true, + "license": "MIT", "dependencies": { - "mdn-data": "2.12.1", + "mdn-data": "2.12.2", "source-map-js": "^1.0.1" }, "engines": { @@ -4511,16 +4569,17 @@ "dev": true }, "node_modules/fast-glob": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", - "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", + "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", "glob-parent": "^5.1.2", "merge2": "^1.3.0", - "micromatch": "^4.0.4" + "micromatch": "^4.0.8" }, "engines": { "node": ">=8.6.0" @@ -4550,6 +4609,23 @@ "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, + "node_modules/fast-uri": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.6.tgz", + "integrity": "sha512-Atfo14OibSv5wAp4VWNsFYE1AchQRTv9cBGWET4pZWHzYshFSS9NQI6I57rdKn9croWVMbYFbLhJ+yJvmZIIHw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, "node_modules/fastest-levenshtein": { "version": "1.0.16", "resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz", @@ -4679,10 +4755,11 @@ } }, "node_modules/flatted": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", - "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", - "dev": true + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.2.tgz", + "integrity": "sha512-AiwGJM8YcNOaobumgtng+6NHuOqC3A7MixFeDafM3X9cIUM+xUXoS5Vfgf+OihAYe20fxqNM9yPBXJzRtZ/4eA==", + "dev": true, + "license": "ISC" }, "node_modules/foreground-child": { "version": "3.1.1", @@ -5145,6 +5222,13 @@ "node": ">= 0.4" } }, + "node_modules/hookified": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/hookified/-/hookified-1.7.0.tgz", + "integrity": "sha512-XQdMjqC1AyeOzfs+17cnIk7Wdfu1hh2JtcyNfBf5u9jHrT3iZUlGHxLTntFBuk5lwkqJ6l3+daeQdHK5yByHVA==", + "dev": true, + "license": "MIT" + }, "node_modules/hosted-git-info": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-7.0.1.tgz", @@ -8660,7 +8744,8 @@ "version": "4.4.2", "resolved": "https://registry.npmjs.org/lodash.truncate/-/lodash.truncate-4.4.2.tgz", "integrity": "sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/lodash.zip": { "version": "4.2.0", @@ -9123,10 +9208,11 @@ } }, "node_modules/mdn-data": { - "version": "2.12.1", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.12.1.tgz", - "integrity": "sha512-rsfnCbOHjqrhWxwt5/wtSLzpoKTzW7OXdT5lLOIH1OTYhWu9rRJveGq0sKvDZODABH7RX+uoR+DYcpFnq4Tf6Q==", - "dev": true + "version": "2.12.2", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.12.2.tgz", + "integrity": "sha512-IEn+pegP1aManZuckezWCO+XZQDplx1366JoVhTpMpBB1sPey/SbveZQUosKiKiGYjg1wH4pMlNgXbCiYgihQA==", + "dev": true, + "license": "CC0-1.0" }, "node_modules/memorystream": { "version": "0.3.1", @@ -11037,9 +11123,9 @@ } }, "node_modules/postcss": { - "version": "8.4.49", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.49.tgz", - "integrity": "sha512-OCVPnIObs4N29kxTjzLfUryOkvZEq+pf8jTF0lg8E7uETuWHA+v7j3c/xJmiqpX450191LlmZfUKkXxkTry7nA==", + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.1.tgz", + "integrity": "sha512-6oz2beyjc5VMn/KV1pPw8fliQkhBXrVn1Z3TVyqZxU8kZpzEKhBdmCFqI6ZbmGtamQvQGuU1sgPTk8ZrXDD7jQ==", "dev": true, "funding": [ { @@ -11055,8 +11141,9 @@ "url": "https://github.com/sponsors/ai" } ], + "license": "MIT", "dependencies": { - "nanoid": "^3.3.7", + "nanoid": "^3.3.8", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" }, @@ -11947,6 +12034,7 @@ "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -12672,9 +12760,9 @@ "dev": true }, "node_modules/stylelint": { - "version": "16.11.0", - "resolved": "https://registry.npmjs.org/stylelint/-/stylelint-16.11.0.tgz", - "integrity": "sha512-zrl4IrKmjJQ+h9FoMp69UMCq5SxeHk0URhxUBj4d3ISzo/DplOFBJZc7t7Dr6otB+1bfbbKNLOmCDpzKSlW+Nw==", + "version": "16.14.0", + "resolved": "https://registry.npmjs.org/stylelint/-/stylelint-16.14.0.tgz", + "integrity": "sha512-orePw2dKxzXC0hd1VmxrDBqgf1KUV9DYsZY4guKLE9XcQD7m0BxVnWMaoQqMNsQIG14MyyTHf6zoajvOnDra8g==", "dev": true, "funding": [ { @@ -12686,6 +12774,7 @@ "url": "https://github.com/sponsors/stylelint" } ], + "license": "MIT", "dependencies": { "@csstools/css-parser-algorithms": "^3.0.4", "@csstools/css-tokenizer": "^3.0.3", @@ -12696,16 +12785,16 @@ "colord": "^2.9.3", "cosmiconfig": "^9.0.0", "css-functions-list": "^3.2.3", - "css-tree": "^3.0.1", + "css-tree": "^3.1.0", "debug": "^4.3.7", - "fast-glob": "^3.3.2", + "fast-glob": "^3.3.3", "fastest-levenshtein": "^1.0.16", - "file-entry-cache": "^9.1.0", + "file-entry-cache": "^10.0.5", "global-modules": "^2.0.0", "globby": "^11.1.0", "globjoin": "^0.1.4", "html-tags": "^3.3.1", - "ignore": "^6.0.2", + "ignore": "^7.0.3", "imurmurhash": "^0.1.4", "is-plain-object": "^5.0.0", "known-css-properties": "^0.35.0", @@ -12714,7 +12803,7 @@ "micromatch": "^4.0.8", "normalize-path": "^3.0.0", "picocolors": "^1.1.1", - "postcss": "^8.4.49", + "postcss": "^8.5.1", "postcss-resolve-nested-selector": "^0.1.6", "postcss-safe-parser": "^7.0.1", "postcss-selector-parser": "^7.0.0", @@ -12723,7 +12812,7 @@ "string-width": "^4.2.3", "supports-hyperlinks": "^3.1.0", "svg-tags": "^1.0.0", - "table": "^6.8.2", + "table": "^6.9.0", "write-file-atomic": "^5.0.1" }, "bin": { @@ -12772,35 +12861,33 @@ "dev": true }, "node_modules/stylelint/node_modules/file-entry-cache": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-9.1.0.tgz", - "integrity": "sha512-/pqPFG+FdxWQj+/WSuzXSDaNzxgTLr/OrR1QuqfEZzDakpdYE70PwUxL7BPUa8hpjbvY1+qvCl8k+8Tq34xJgg==", + "version": "10.0.5", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-10.0.5.tgz", + "integrity": "sha512-umpQsJrBNsdMDgreSryMEXvJh66XeLtZUwA8Gj7rHGearGufUFv6rB/bcXRFsiGWw/VeSUgUofF4Rf2UKEOrTA==", "dev": true, + "license": "MIT", "dependencies": { - "flat-cache": "^5.0.0" - }, - "engines": { - "node": ">=18" + "flat-cache": "^6.1.5" } }, "node_modules/stylelint/node_modules/flat-cache": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-5.0.0.tgz", - "integrity": "sha512-JrqFmyUl2PnPi1OvLyTVHnQvwQ0S+e6lGSwu8OkAZlSaNIZciTY2H/cOOROxsBA1m/LZNHDsqAgDZt6akWcjsQ==", + "version": "6.1.5", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-6.1.5.tgz", + "integrity": "sha512-QR+2kN38f8nMfiIQ1LHYjuDEmZNZVjxuxY+HufbS3BW0EX01Q5OnH7iduOYRutmgiXb797HAKcXUeXrvRjjgSQ==", "dev": true, + "license": "MIT", "dependencies": { - "flatted": "^3.3.1", - "keyv": "^4.5.4" - }, - "engines": { - "node": ">=18" + "cacheable": "^1.8.7", + "flatted": "^3.3.2", + "hookified": "^1.6.0" } }, "node_modules/stylelint/node_modules/ignore": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-6.0.2.tgz", - "integrity": "sha512-InwqeHHN2XpumIkMvpl/DCJVrAHgCsG5+cn1XlnLWGwtZBm8QJfSusItfrwx81CTp5agNZqpKU2J/ccC5nGT4A==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.3.tgz", + "integrity": "sha512-bAH5jbK/F3T3Jls4I0SO1hmPR0dKU0a7+SY6n1yzRtG54FLO8d6w/nxLFX2Nb7dBu6cCWXPaAME6cYqFUMmuCA==", "dev": true, + "license": "MIT", "engines": { "node": ">= 4" } @@ -12959,10 +13046,11 @@ } }, "node_modules/table": { - "version": "6.8.2", - "resolved": "https://registry.npmjs.org/table/-/table-6.8.2.tgz", - "integrity": "sha512-w2sfv80nrAh2VCbqR5AK27wswXhqcck2AhfnNW76beQXskGZ1V12GwS//yYVa3d3fcvAip2OUnbDAjW2k3v9fA==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/table/-/table-6.9.0.tgz", + "integrity": "sha512-9kY+CygyYM6j02t5YFHbNz2FN5QmYGv9zAjVp4lCDjlCw7amdckXlEt/bjMhUIfj4ThGRE4gCUH5+yGnNuPo5A==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "ajv": "^8.0.1", "lodash.truncate": "^4.4.2", @@ -12975,15 +13063,16 @@ } }, "node_modules/table/node_modules/ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, + "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" + "require-from-string": "^2.0.2" }, "funding": { "type": "github", @@ -12994,13 +13083,15 @@ "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/table/node_modules/is-fullwidth-code-point": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -13009,13 +13100,15 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/table/node_modules/slice-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-4.0.0.tgz", "integrity": "sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==", "dev": true, + "license": "MIT", "dependencies": { "ansi-styles": "^4.0.0", "astral-regex": "^2.0.0", @@ -13033,6 +13126,7 @@ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "dev": true, + "license": "MIT", "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -15315,6 +15409,27 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "@keyv/serialize": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@keyv/serialize/-/serialize-1.0.2.tgz", + "integrity": "sha512-+E/LyaAeuABniD/RvUezWVXKpeuvwLEA9//nE9952zBaOdBd2mQ3pPoM8cUe2X6IcMByfuSLzmYqnYshG60+HQ==", + "dev": true, + "requires": { + "buffer": "^6.0.3" + }, + "dependencies": { + "buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "dev": true, + "requires": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + } + } + }, "@ljharb/through": { "version": "2.3.12", "resolved": "https://registry.npmjs.org/@ljharb/through/-/through-2.3.12.tgz", @@ -16289,6 +16404,27 @@ "run-applescript": "^5.0.0" } }, + "cacheable": { + "version": "1.8.8", + "resolved": "https://registry.npmjs.org/cacheable/-/cacheable-1.8.8.tgz", + "integrity": "sha512-OE1/jlarWxROUIpd0qGBSKFLkNsotY8pt4GeiVErUYh/NUeTNrT+SBksUgllQv4m6a0W/VZsLuiHb88maavqEw==", + "dev": true, + "requires": { + "hookified": "^1.7.0", + "keyv": "^5.2.3" + }, + "dependencies": { + "keyv": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-5.2.3.tgz", + "integrity": "sha512-AGKecUfzrowabUv0bH1RIR5Vf7w+l4S3xtQAypKaUpTdIR1EbrAcTxHCrpo9Q+IWeUlFE2palRtgIQcgm+PQJw==", + "dev": true, + "requires": { + "@keyv/serialize": "^1.0.2" + } + } + } + }, "call-bind": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", @@ -16709,12 +16845,12 @@ "dev": true }, "css-tree": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.0.1.tgz", - "integrity": "sha512-8Fxxv+tGhORlshCdCwnNJytvlvq46sOLSYEx2ZIGurahWvMucSRnyjPA3AmrMq4VPRYbHVpWj5VkiVasrM2H4Q==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-3.1.0.tgz", + "integrity": "sha512-0eW44TGN5SQXU1mWSkKwFstI/22X2bG1nYzZTYMAWjylYURhse752YgbE4Cx46AC+bAvI+/dYTPRk1LqSUnu6w==", "dev": true, "requires": { - "mdn-data": "2.12.1", + "mdn-data": "2.12.2", "source-map-js": "^1.0.1" } }, @@ -17460,16 +17596,16 @@ "dev": true }, "fast-glob": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", - "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", + "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", "dev": true, "requires": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", "glob-parent": "^5.1.2", "merge2": "^1.3.0", - "micromatch": "^4.0.4" + "micromatch": "^4.0.8" }, "dependencies": { "glob-parent": { @@ -17495,6 +17631,12 @@ "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", "dev": true }, + "fast-uri": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.6.tgz", + "integrity": "sha512-Atfo14OibSv5wAp4VWNsFYE1AchQRTv9cBGWET4pZWHzYshFSS9NQI6I57rdKn9croWVMbYFbLhJ+yJvmZIIHw==", + "dev": true + }, "fastest-levenshtein": { "version": "1.0.16", "resolved": "https://registry.npmjs.org/fastest-levenshtein/-/fastest-levenshtein-1.0.16.tgz", @@ -17590,9 +17732,9 @@ } }, "flatted": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", - "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.2.tgz", + "integrity": "sha512-AiwGJM8YcNOaobumgtng+6NHuOqC3A7MixFeDafM3X9cIUM+xUXoS5Vfgf+OihAYe20fxqNM9yPBXJzRtZ/4eA==", "dev": true }, "foreground-child": { @@ -17913,6 +18055,12 @@ "function-bind": "^1.1.2" } }, + "hookified": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/hookified/-/hookified-1.7.0.tgz", + "integrity": "sha512-XQdMjqC1AyeOzfs+17cnIk7Wdfu1hh2JtcyNfBf5u9jHrT3iZUlGHxLTntFBuk5lwkqJ6l3+daeQdHK5yByHVA==", + "dev": true + }, "hosted-git-info": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-7.0.1.tgz", @@ -20809,9 +20957,9 @@ } }, "mdn-data": { - "version": "2.12.1", - "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.12.1.tgz", - "integrity": "sha512-rsfnCbOHjqrhWxwt5/wtSLzpoKTzW7OXdT5lLOIH1OTYhWu9rRJveGq0sKvDZODABH7RX+uoR+DYcpFnq4Tf6Q==", + "version": "2.12.2", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.12.2.tgz", + "integrity": "sha512-IEn+pegP1aManZuckezWCO+XZQDplx1366JoVhTpMpBB1sPey/SbveZQUosKiKiGYjg1wH4pMlNgXbCiYgihQA==", "dev": true }, "memorystream": { @@ -22058,12 +22206,12 @@ "dev": true }, "postcss": { - "version": "8.4.49", - "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.49.tgz", - "integrity": "sha512-OCVPnIObs4N29kxTjzLfUryOkvZEq+pf8jTF0lg8E7uETuWHA+v7j3c/xJmiqpX450191LlmZfUKkXxkTry7nA==", + "version": "8.5.1", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.1.tgz", + "integrity": "sha512-6oz2beyjc5VMn/KV1pPw8fliQkhBXrVn1Z3TVyqZxU8kZpzEKhBdmCFqI6ZbmGtamQvQGuU1sgPTk8ZrXDD7jQ==", "dev": true, "requires": { - "nanoid": "^3.3.7", + "nanoid": "^3.3.8", "picocolors": "^1.1.1", "source-map-js": "^1.2.1" } @@ -23228,9 +23376,9 @@ "dev": true }, "stylelint": { - "version": "16.11.0", - "resolved": "https://registry.npmjs.org/stylelint/-/stylelint-16.11.0.tgz", - "integrity": "sha512-zrl4IrKmjJQ+h9FoMp69UMCq5SxeHk0URhxUBj4d3ISzo/DplOFBJZc7t7Dr6otB+1bfbbKNLOmCDpzKSlW+Nw==", + "version": "16.14.0", + "resolved": "https://registry.npmjs.org/stylelint/-/stylelint-16.14.0.tgz", + "integrity": "sha512-orePw2dKxzXC0hd1VmxrDBqgf1KUV9DYsZY4guKLE9XcQD7m0BxVnWMaoQqMNsQIG14MyyTHf6zoajvOnDra8g==", "dev": true, "requires": { "@csstools/css-parser-algorithms": "^3.0.4", @@ -23242,16 +23390,16 @@ "colord": "^2.9.3", "cosmiconfig": "^9.0.0", "css-functions-list": "^3.2.3", - "css-tree": "^3.0.1", + "css-tree": "^3.1.0", "debug": "^4.3.7", - "fast-glob": "^3.3.2", + "fast-glob": "^3.3.3", "fastest-levenshtein": "^1.0.16", - "file-entry-cache": "^9.1.0", + "file-entry-cache": "^10.0.5", "global-modules": "^2.0.0", "globby": "^11.1.0", "globjoin": "^0.1.4", "html-tags": "^3.3.1", - "ignore": "^6.0.2", + "ignore": "^7.0.3", "imurmurhash": "^0.1.4", "is-plain-object": "^5.0.0", "known-css-properties": "^0.35.0", @@ -23260,7 +23408,7 @@ "micromatch": "^4.0.8", "normalize-path": "^3.0.0", "picocolors": "^1.1.1", - "postcss": "^8.4.49", + "postcss": "^8.5.1", "postcss-resolve-nested-selector": "^0.1.6", "postcss-safe-parser": "^7.0.1", "postcss-selector-parser": "^7.0.0", @@ -23269,7 +23417,7 @@ "string-width": "^4.2.3", "supports-hyperlinks": "^3.1.0", "svg-tags": "^1.0.0", - "table": "^6.8.2", + "table": "^6.9.0", "write-file-atomic": "^5.0.1" }, "dependencies": { @@ -23298,28 +23446,29 @@ "dev": true }, "file-entry-cache": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-9.1.0.tgz", - "integrity": "sha512-/pqPFG+FdxWQj+/WSuzXSDaNzxgTLr/OrR1QuqfEZzDakpdYE70PwUxL7BPUa8hpjbvY1+qvCl8k+8Tq34xJgg==", + "version": "10.0.5", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-10.0.5.tgz", + "integrity": "sha512-umpQsJrBNsdMDgreSryMEXvJh66XeLtZUwA8Gj7rHGearGufUFv6rB/bcXRFsiGWw/VeSUgUofF4Rf2UKEOrTA==", "dev": true, "requires": { - "flat-cache": "^5.0.0" + "flat-cache": "^6.1.5" } }, "flat-cache": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-5.0.0.tgz", - "integrity": "sha512-JrqFmyUl2PnPi1OvLyTVHnQvwQ0S+e6lGSwu8OkAZlSaNIZciTY2H/cOOROxsBA1m/LZNHDsqAgDZt6akWcjsQ==", + "version": "6.1.5", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-6.1.5.tgz", + "integrity": "sha512-QR+2kN38f8nMfiIQ1LHYjuDEmZNZVjxuxY+HufbS3BW0EX01Q5OnH7iduOYRutmgiXb797HAKcXUeXrvRjjgSQ==", "dev": true, "requires": { - "flatted": "^3.3.1", - "keyv": "^4.5.4" + "cacheable": "^1.8.7", + "flatted": "^3.3.2", + "hookified": "^1.6.0" } }, "ignore": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-6.0.2.tgz", - "integrity": "sha512-InwqeHHN2XpumIkMvpl/DCJVrAHgCsG5+cn1XlnLWGwtZBm8QJfSusItfrwx81CTp5agNZqpKU2J/ccC5nGT4A==", + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.3.tgz", + "integrity": "sha512-bAH5jbK/F3T3Jls4I0SO1hmPR0dKU0a7+SY6n1yzRtG54FLO8d6w/nxLFX2Nb7dBu6cCWXPaAME6cYqFUMmuCA==", "dev": true }, "is-fullwidth-code-point": { @@ -23432,9 +23581,9 @@ } }, "table": { - "version": "6.8.2", - "resolved": "https://registry.npmjs.org/table/-/table-6.8.2.tgz", - "integrity": "sha512-w2sfv80nrAh2VCbqR5AK27wswXhqcck2AhfnNW76beQXskGZ1V12GwS//yYVa3d3fcvAip2OUnbDAjW2k3v9fA==", + "version": "6.9.0", + "resolved": "https://registry.npmjs.org/table/-/table-6.9.0.tgz", + "integrity": "sha512-9kY+CygyYM6j02t5YFHbNz2FN5QmYGv9zAjVp4lCDjlCw7amdckXlEt/bjMhUIfj4ThGRE4gCUH5+yGnNuPo5A==", "dev": true, "requires": { "ajv": "^8.0.1", @@ -23445,15 +23594,15 @@ }, "dependencies": { "ajv": { - "version": "8.13.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.13.0.tgz", - "integrity": "sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, "requires": { "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" + "require-from-string": "^2.0.2" } }, "emoji-regex": { diff --git a/package.json b/package.json index 6531ca6..475912b 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "npm-run-all": "^4.1.5", "prettier": "^3.4.1", "remark-cli": "^12.0.1", - "stylelint": "^16.11.0", + "stylelint": "^16.14.0", "typescript": "^5.7.2" }, "peerDependencies": { From 279486911106e17dc93755503179777b744402c8 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 25 Jan 2025 16:40:50 +0100 Subject: [PATCH 4/6] add a few tests --- __tests__/fixtures/plugin-foo.mjs | 10 ++++++++++ __tests__/getTestRule.test.mjs | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/__tests__/fixtures/plugin-foo.mjs b/__tests__/fixtures/plugin-foo.mjs index ece3db8..d4bb44f 100644 --- a/__tests__/fixtures/plugin-foo.mjs +++ b/__tests__/fixtures/plugin-foo.mjs @@ -63,6 +63,12 @@ const ruleFunction = (primary, secondaryOptions) => { ruleName, message: messages.rejected(selector), node: rule, + fix: { + apply: () => { + rule.selector = primary; + }, + node: rule, + }, }); } }); @@ -71,5 +77,9 @@ const ruleFunction = (primary, secondaryOptions) => { ruleFunction.ruleName = ruleName; ruleFunction.messages = messages; +ruleFunction.meta = { + url: 'plugin/foo', + fixable: true, +}; export default createPlugin(ruleName, ruleFunction); diff --git a/__tests__/getTestRule.test.mjs b/__tests__/getTestRule.test.mjs index 52081d1..4ac9e1a 100644 --- a/__tests__/getTestRule.test.mjs +++ b/__tests__/getTestRule.test.mjs @@ -72,3 +72,32 @@ testRuleWithLoadLint({ config: ['.a'], accept: [{ code: '.a {}' }], }); + +testRule({ + plugins, + ruleName, + config: ['.a'], + computeEditInfo: true, + + accept: [], + + reject: [ + { + code: '#a {}', + message: messages.rejected('#a'), + fix: { + range: [0, 1], + text: '.', + }, + }, + { + code: '.a {} #a {}', + message: messages.rejected('#a'), + description: 'with description', + fix: { + range: [6, 7], + text: '.', + }, + }, + ], +}); From e43f9ed2c1d039d0e712f0d3bfee261ce72d290d Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 25 Jan 2025 16:50:39 +0100 Subject: [PATCH 5/6] docs --- index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.d.ts b/index.d.ts index b89258b..966ebe9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -58,6 +58,11 @@ export type Warning = { */ endColumn?: number; + /** + * Expected `EditInfo` of the warning. + * + * @experimental + */ fix?: { range: Range; text: string }; }; From 2dc336010837dcdc62bc161136787060addec267 Mon Sep 17 00:00:00 2001 From: Romain Menke Date: Sat, 25 Jan 2025 16:52:04 +0100 Subject: [PATCH 6/6] fix type --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 966ebe9..5e394db 100644 --- a/index.d.ts +++ b/index.d.ts @@ -63,7 +63,7 @@ export type Warning = { * * @experimental */ - fix?: { range: Range; text: string }; + fix?: { range: [number, number]; text: string }; }; /**