From a973f3e1d3d1bcde51d6b41232439ce07eef4e2e Mon Sep 17 00:00:00 2001 From: adman00199 Date: Thu, 12 Oct 2023 11:33:59 +1100 Subject: [PATCH 1/5] feat: attr value rule to disallow certain attribute value combinations --- docs/rules/no-restricted-attr-values.md | 71 +++++++++ packages/eslint-plugin/lib/rules/index.js | 2 + .../lib/rules/no-restricted-attr-values.js | 135 ++++++++++++++++++ .../rules/no-restricted-attr-values.test.js | 98 +++++++++++++ 4 files changed, 306 insertions(+) create mode 100644 docs/rules/no-restricted-attr-values.md create mode 100644 packages/eslint-plugin/lib/rules/no-restricted-attr-values.js create mode 100644 packages/eslint-plugin/tests/rules/no-restricted-attr-values.test.js diff --git a/docs/rules/no-restricted-attr-values.md b/docs/rules/no-restricted-attr-values.md new file mode 100644 index 00000000..875d8603 --- /dev/null +++ b/docs/rules/no-restricted-attr-values.md @@ -0,0 +1,71 @@ +--- +id: no-restricted-attr-values +title: "no-restricted-attr-values" +--- + +# no-restricted-attrs + +Disallow specified attribute values + +## How to use + +.eslintrc.js + +```js +module.exports = { + rules: { + '@html-eslint/no-restricted-attr-values': ["error", { + attrPatterns: ["class"], + attrValues: ["data-.*"] + message: "\'data-x\' is restricted." + }] + } +}; +``` + +## Rule Details + +This rule allows you to specify attribute values that you don't want to use in your application. + +### Options + +This rule takes an array of option objects, where the `attrPatterns` and `attrValues` are specified. + +- `attrPatterns`: an array of strings representing regular expression pattern, disallows atrribute names that match any of the patterns. +- `attrValues`: an array of strings representing regular expression pattern, disallows attribute values that match any of the patterns. +- `message` (optional): a string for custom message. + +```js +module.exports = { + "rules": { + "@html-eslint/no-restricted-attrs": [ + "error", + { + attrPatterns: ["class", "alt"], + attrValues: ["data-.*"] + message: "\'data-x\' is restricted." + }, + { + attrPatterns: [".*"], + attrValues: ["^foo$"] + message: "\'foo\' is restricted." + } + ], + } +}; +``` + +Examples of **incorrect** code for this rule with the option below: + +```json +{ + "attrPatterns": ["data-.*"], + "attrValues": ["foo"], + "message": "Do not use foo attr value" +} +``` + +```html +
+ +``` diff --git a/packages/eslint-plugin/lib/rules/index.js b/packages/eslint-plugin/lib/rules/index.js index 1f9a4d3b..6167a201 100644 --- a/packages/eslint-plugin/lib/rules/index.js +++ b/packages/eslint-plugin/lib/rules/index.js @@ -30,6 +30,7 @@ const noAccesskeyAttrs = require("./no-accesskey-attrs"); const noRestrictedAttrs = require("./no-restricted-attrs"); const noTrailingSpaces = require("./no-trailing-spaces"); const requireAttrs = require("./require-attrs"); +const noRestrictedAttrValues = require("./no-restricted-attr-values"); module.exports = { "require-lang": requireLang, @@ -64,4 +65,5 @@ module.exports = { "no-accesskey-attrs": noAccesskeyAttrs, "no-restricted-attrs": noRestrictedAttrs, "no-trailing-spaces": noTrailingSpaces, + "no-restricted-attr-values": noRestrictedAttrValues, }; diff --git a/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js b/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js new file mode 100644 index 00000000..1d1f0f96 --- /dev/null +++ b/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js @@ -0,0 +1,135 @@ +/** + * @typedef {import("../types").Rule} Rule + * @typedef {{attrPatterns: string[], attrValues: string[], message?: string}[]} Options + */ + +const { RULE_CATEGORY } = require("../constants"); + +const MESSAGE_IDS = { + RESTRICTED: "restricted", +}; + +/** + * @type {Rule} + */ +module.exports = { + meta: { + type: "code", + + docs: { + description: "Disallow specified attributes", + category: RULE_CATEGORY.BEST_PRACTICE, + recommended: false, + }, + + fixable: null, + schema: { + type: "array", + + items: { + type: "object", + required: ["attrPatterns", "attrValues"], + properties: { + attrPatterns: { + type: "array", + items: { + type: "string", + }, + }, + attrValues: { + type: "array", + items: { + type: "string", + }, + }, + message: { + type: "string", + }, + }, + }, + }, + messages: { + [MESSAGE_IDS.RESTRICTED]: + "'{{attrValues}}' is restricted from being used.", + }, + }, + + create(context) { + /** + * @type {Options} + */ + const options = context.options; + const checkers = options.map((option) => new PatternChecker(option)); + + return { + [["Tag", "StyleTag", "ScriptTag"].join(",")](node) { + node.attributes.forEach((attr) => { + if (!attr.key || !attr.value?.value || !attr.key?.value) { + return; + } + const matched = checkers.find((checker) => + checker.test(attr.key.value, attr.value.value) + ); + + if (!matched) { + return; + } + + const result = { + node: attr, + message: "", + }; + + const customMessage = matched.getMessage(); + + if (customMessage) { + result.message = customMessage; + } else { + result.messageId = MESSAGE_IDS.RESTRICTED; + } + + context.report({ + ...result, + data: { attrValues: attr.value.value }, + }); + }); + }, + }; + }, +}; + +class PatternChecker { + /** + * @param {Options[number]} option + */ + constructor(option) { + this.option = option; + this.attrRegExps = option.attrPatterns.map( + (pattern) => new RegExp(pattern, "u") + ); + + this.valueRegExps = option.attrValues.map( + (pattern) => new RegExp(pattern, "u") + ); + this.message = option.message; + } + + /** + * @param {string} attrName + * @param {string} attrValue + * @returns {boolean} + */ + test(attrName, attrValue) { + const result = + this.attrRegExps.some((exp) => exp.test(attrName)) && + this.valueRegExps.some((exp) => exp.test(attrValue)); + return result; + } + + /** + * @returns {string} + */ + getMessage() { + return this.message || ""; + } +} diff --git a/packages/eslint-plugin/tests/rules/no-restricted-attr-values.test.js b/packages/eslint-plugin/tests/rules/no-restricted-attr-values.test.js new file mode 100644 index 00000000..a08376b7 --- /dev/null +++ b/packages/eslint-plugin/tests/rules/no-restricted-attr-values.test.js @@ -0,0 +1,98 @@ +const createRuleTester = require("../rule-tester"); +const rule = require("../../lib/rules/no-restricted-attr-values"); + +const ruleTester = createRuleTester(); + +ruleTester.run("no-restricted-attr-values", rule, { + valid: [ + { + code: `
`, + options: [ + { + attrPatterns: [".*"], + attrValues: ["data-.*"], + }, + ], + }, + { + code: `
`, + options: [ + { + attrPatterns: ["class"], + attrValues: ["data-.*"], + }, + ], + }, + ], + invalid: [ + { + code: `
`, + options: [ + { + attrPatterns: [".*"], + attrValues: ["data-.*"], + }, + ], + errors: [ + { + messageId: "restricted", + data: { + attrValues: "data-x", + }, + }, + ], + }, + { + code: `
`, + options: [ + { + attrPatterns: ["alt"], + attrValues: ["foo"], + }, + ], + errors: [ + { + messageId: "restricted", + data: { + attrValues: "foo", + }, + }, + ], + }, + { + code: `
`, + options: [ + { + attrPatterns: ["alt", "class"], + attrValues: ["^foo$"], + message: "no foo for alt or class", + }, + ], + errors: [ + { + message: "no foo for alt or class", + }, + { + message: "no foo for alt or class", + }, + ], + }, + // custom message + { + code: `
`, + options: [ + { + attrPatterns: [".*"], + attrValues: ["data.*"], + message: "please do not use 'data-x'", + }, + ], + errors: [ + { + message: "please do not use 'data-x'", + }, + ], + }, + ], +}); +///^a$/ From dd2f3910e39e1ed8b417b1685e21bcbce01c5d64 Mon Sep 17 00:00:00 2001 From: adman00199 Date: Thu, 12 Oct 2023 11:37:32 +1100 Subject: [PATCH 2/5] chore: spelling error --- docs/rules/no-restricted-attr-values.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/no-restricted-attr-values.md b/docs/rules/no-restricted-attr-values.md index 875d8603..f6beb0a9 100644 --- a/docs/rules/no-restricted-attr-values.md +++ b/docs/rules/no-restricted-attr-values.md @@ -31,7 +31,7 @@ This rule allows you to specify attribute values that you don't want to use in y This rule takes an array of option objects, where the `attrPatterns` and `attrValues` are specified. -- `attrPatterns`: an array of strings representing regular expression pattern, disallows atrribute names that match any of the patterns. +- `attrPatterns`: an array of strings representing regular expression pattern, disallows attribute names that match any of the patterns. - `attrValues`: an array of strings representing regular expression pattern, disallows attribute values that match any of the patterns. - `message` (optional): a string for custom message. From 221e41194f7f6464f614f5025167d158c5cd1799 Mon Sep 17 00:00:00 2001 From: Adam Gillespie <75661002+Adam-Gillespie345@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:31:35 +1100 Subject: [PATCH 3/5] Update packages/eslint-plugin/lib/rules/no-restricted-attr-values.js Co-authored-by: YeonJuan --- packages/eslint-plugin/lib/rules/no-restricted-attr-values.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js b/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js index 1d1f0f96..545a4684 100644 --- a/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js +++ b/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js @@ -64,7 +64,7 @@ module.exports = { return { [["Tag", "StyleTag", "ScriptTag"].join(",")](node) { node.attributes.forEach((attr) => { - if (!attr.key || !attr.value?.value || !attr.key?.value) { + if (!attr.key || typeof attr.value?.value !== "string" || !attr.key?.value) { return; } const matched = checkers.find((checker) => From 8e39aa7dccb54028b2bdbfbec0d3ef101dff223e Mon Sep 17 00:00:00 2001 From: adman00199 Date: Fri, 13 Oct 2023 14:47:34 +1100 Subject: [PATCH 4/5] chore: addressing feedback and upgrading lint --- .eslintrc.js | 2 +- docs/rules/no-restricted-attr-values.md | 12 +- package-lock.json | 198 +----------------- package.json | 2 +- .../lib/rules/no-restricted-attr-values.js | 18 +- packages/eslint-plugin/package.json | 1 + .../rules/no-restricted-attr-values.test.js | 36 +++- 7 files changed, 48 insertions(+), 221 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8f44e89e..7b49535f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,7 +2,7 @@ module.exports = { extends: ["eslint:recommended"], plugins: ["jest", "node"], parserOptions: { - ecmaVersion: 9, + ecmaVersion: 2020, }, env: { node: true, diff --git a/docs/rules/no-restricted-attr-values.md b/docs/rules/no-restricted-attr-values.md index f6beb0a9..d86f5287 100644 --- a/docs/rules/no-restricted-attr-values.md +++ b/docs/rules/no-restricted-attr-values.md @@ -16,7 +16,7 @@ module.exports = { rules: { '@html-eslint/no-restricted-attr-values': ["error", { attrPatterns: ["class"], - attrValues: ["data-.*"] + attrValuePatterns: ["data-.*"] message: "\'data-x\' is restricted." }] } @@ -29,10 +29,10 @@ This rule allows you to specify attribute values that you don't want to use in y ### Options -This rule takes an array of option objects, where the `attrPatterns` and `attrValues` are specified. +This rule takes an array of option objects, where the `attrPatterns` and `attrValuePatterns` are specified. - `attrPatterns`: an array of strings representing regular expression pattern, disallows attribute names that match any of the patterns. -- `attrValues`: an array of strings representing regular expression pattern, disallows attribute values that match any of the patterns. +- `attrValuePatterns`: an array of strings representing regular expression pattern, disallows attribute values that match any of the patterns. - `message` (optional): a string for custom message. ```js @@ -42,12 +42,12 @@ module.exports = { "error", { attrPatterns: ["class", "alt"], - attrValues: ["data-.*"] + attrValuePatterns: ["data-.*"] message: "\'data-x\' is restricted." }, { attrPatterns: [".*"], - attrValues: ["^foo$"] + attrValuePatterns: ["^foo$"] message: "\'foo\' is restricted." } ], @@ -60,7 +60,7 @@ Examples of **incorrect** code for this rule with the option below: ```json { "attrPatterns": ["data-.*"], - "attrValues": ["foo"], + "attrValuePatterns": ["foo"], "message": "Do not use foo attr value" } ``` diff --git a/package-lock.json b/package-lock.json index adaade6c..fc367064 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ ], "devDependencies": { "cspell": "^6.19.2", - "eslint": "^7.14.0", + "eslint": "^7.32.0", "eslint-plugin-jest": "^24.1.3", "eslint-plugin-node": "^11.1.0", "gh-pages": "^3.1.0", @@ -23593,6 +23593,7 @@ "@types/eslint": "^7.2.10", "@types/estree": "^0.0.47", "es-html-parser": "^0.0.8", + "eslint": "^7.32.0", "typescript": "^4.4.4" }, "engines": { @@ -24472,201 +24473,6 @@ "postcss": "^8.4.19", "tailwindcss": "^3.2.4" } - }, - "node_modules/@next/swc-android-arm-eabi": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-13.0.6.tgz", - "integrity": "sha512-FGFSj3v2Bluw8fD/X+1eXIEB0PhoJE0zfutsAauRhmNpjjZshLDgoXMWm1jTRL/04K/o9gwwO2+A8+sPVCH1uw==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-android-arm64": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-android-arm64/-/swc-android-arm64-13.0.6.tgz", - "integrity": "sha512-7MgbtU7kimxuovVsd7jSJWMkIHBDBUsNLmmlkrBRHTvgzx5nDBXogP0hzZm7EImdOPwVMPpUHRQMBP9mbsiJYQ==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-darwin-arm64": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.0.6.tgz", - "integrity": "sha512-AUVEpVTxbP/fxdFsjVI9d5a0CFn6NVV7A/RXOb0Y+pXKIIZ1V5rFjPwpYfIfyOo2lrqgehMNQcyMRoTrhq04xg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-darwin-x64": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.0.6.tgz", - "integrity": "sha512-SasCDJlshglsPnbzhWaIF6VEGkQy2NECcAOxPwaPr0cwbbt4aUlZ7QmskNzgolr5eAjFS/xTr7CEeKJtZpAAtQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-freebsd-x64": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-freebsd-x64/-/swc-freebsd-x64-13.0.6.tgz", - "integrity": "sha512-6Lbxd9gAdXneTkwHyYW/qtX1Tdw7ND9UbiGsGz/SP43ZInNWnW6q0au4hEVPZ9bOWWRKzcVoeTBdoMpQk9Hx9w==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm-gnueabihf": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-13.0.6.tgz", - "integrity": "sha512-wNdi5A519e1P+ozEuYOhWPzzE6m1y7mkO6NFwn6watUwO0X9nZs7fT9THmnekvmFQpaZ6U+xf2MQ9poQoCh6jQ==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm64-gnu": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.0.6.tgz", - "integrity": "sha512-e8KTRnleQY1KLk5PwGV5hrmvKksCc74QRpHl5ffWnEEAtL2FE0ave5aIkXqErsPdXkiKuA/owp3LjQrP+/AH7Q==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-arm64-musl": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.0.6.tgz", - "integrity": "sha512-/7RF03C3mhjYpHN+pqOolgME3guiHU5T3TsejuyteqyEyzdEyLHod+jcYH6ft7UZ71a6TdOewvmbLOtzHW2O8A==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-x64-gnu": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.0.6.tgz", - "integrity": "sha512-kxyEXnYHpOEkFnmrlwB1QlzJtjC6sAJytKcceIyFUHbCaD3W/Qb5tnclcnHKTaFccizZRePXvV25Ok/eUSpKTw==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-linux-x64-musl": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.0.6.tgz", - "integrity": "sha512-N0c6gubS3WW1oYYgo02xzZnNatfVQP/CiJq2ax+DJ55ePV62IACbRCU99TZNXXg+Kos6vNW4k+/qgvkvpGDeyA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-arm64-msvc": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.0.6.tgz", - "integrity": "sha512-QjeMB2EBqBFPb/ac0CYr7GytbhUkrG4EwFWbcE0vsRp4H8grt25kYpFQckL4Jak3SUrp7vKfDwZ/SwO7QdO8vw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-ia32-msvc": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.0.6.tgz", - "integrity": "sha512-EQzXtdqRTcmhT/tCq81rIwE36Y3fNHPInaCuJzM/kftdXfa0F+64y7FAoMO13npX8EG1+SamXgp/emSusKrCXg==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "node_modules/@next/swc-win32-x64-msvc": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.0.6.tgz", - "integrity": "sha512-pSkqZ//UP/f2sS9T7IvHLfEWDPTX0vRyXJnAUNisKvO3eF3e1xdhDX7dix/X3Z3lnN4UjSwOzclAI87JFbOwmQ==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } } } } diff --git a/package.json b/package.json index b6a4d3cb..b6a70e0f 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "license": "MIT", "devDependencies": { "cspell": "^6.19.2", - "eslint": "^7.14.0", + "eslint": "^7.32.0", "eslint-plugin-jest": "^24.1.3", "eslint-plugin-node": "^11.1.0", "gh-pages": "^3.1.0", diff --git a/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js b/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js index 545a4684..062c9524 100644 --- a/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js +++ b/packages/eslint-plugin/lib/rules/no-restricted-attr-values.js @@ -1,6 +1,6 @@ /** * @typedef {import("../types").Rule} Rule - * @typedef {{attrPatterns: string[], attrValues: string[], message?: string}[]} Options + * @typedef {{attrPatterns: string[], attrValuePatterns: string[], message?: string}[]} Options */ const { RULE_CATEGORY } = require("../constants"); @@ -28,7 +28,7 @@ module.exports = { items: { type: "object", - required: ["attrPatterns", "attrValues"], + required: ["attrPatterns", "attrValuePatterns"], properties: { attrPatterns: { type: "array", @@ -36,7 +36,7 @@ module.exports = { type: "string", }, }, - attrValues: { + attrValuePatterns: { type: "array", items: { type: "string", @@ -50,7 +50,7 @@ module.exports = { }, messages: { [MESSAGE_IDS.RESTRICTED]: - "'{{attrValues}}' is restricted from being used.", + "'{{attrValuePatterns}}' is restricted from being used.", }, }, @@ -64,7 +64,11 @@ module.exports = { return { [["Tag", "StyleTag", "ScriptTag"].join(",")](node) { node.attributes.forEach((attr) => { - if (!attr.key || typeof attr.value?.value !== "string" || !attr.key?.value) { + if ( + !attr.key || + typeof attr.value?.value !== "string" || + !attr.key?.value + ) { return; } const matched = checkers.find((checker) => @@ -90,7 +94,7 @@ module.exports = { context.report({ ...result, - data: { attrValues: attr.value.value }, + data: { attrValuePatterns: attr.value.value }, }); }); }, @@ -108,7 +112,7 @@ class PatternChecker { (pattern) => new RegExp(pattern, "u") ); - this.valueRegExps = option.attrValues.map( + this.valueRegExps = option.attrValuePatterns.map( (pattern) => new RegExp(pattern, "u") ); this.message = option.message; diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 8cce7aec..00eac875 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -44,6 +44,7 @@ "@types/eslint": "^7.2.10", "@types/estree": "^0.0.47", "es-html-parser": "^0.0.8", + "eslint": "^7.32.0", "typescript": "^4.4.4" } } diff --git a/packages/eslint-plugin/tests/rules/no-restricted-attr-values.test.js b/packages/eslint-plugin/tests/rules/no-restricted-attr-values.test.js index a08376b7..97b73d26 100644 --- a/packages/eslint-plugin/tests/rules/no-restricted-attr-values.test.js +++ b/packages/eslint-plugin/tests/rules/no-restricted-attr-values.test.js @@ -10,16 +10,16 @@ ruleTester.run("no-restricted-attr-values", rule, { options: [ { attrPatterns: [".*"], - attrValues: ["data-.*"], + attrValuePatterns: ["data-.*"], }, ], }, { - code: `
`, + code: `
`, options: [ { attrPatterns: ["class"], - attrValues: ["data-.*"], + attrValuePatterns: ["data-.*"], }, ], }, @@ -30,14 +30,31 @@ ruleTester.run("no-restricted-attr-values", rule, { options: [ { attrPatterns: [".*"], - attrValues: ["data-.*"], + attrValuePatterns: ["data-.*"], + }, + ], + errors: [ + { + messageId: "restricted", + data: { + attrValuePatterns: "data-x", + }, + }, + ], + }, + { + code: `
`, + options: [ + { + attrPatterns: [".*"], + attrValuePatterns: [""], }, ], errors: [ { messageId: "restricted", data: { - attrValues: "data-x", + attrValuePatterns: "", }, }, ], @@ -47,14 +64,14 @@ ruleTester.run("no-restricted-attr-values", rule, { options: [ { attrPatterns: ["alt"], - attrValues: ["foo"], + attrValuePatterns: ["foo"], }, ], errors: [ { messageId: "restricted", data: { - attrValues: "foo", + attrValuePatterns: "foo", }, }, ], @@ -64,7 +81,7 @@ ruleTester.run("no-restricted-attr-values", rule, { options: [ { attrPatterns: ["alt", "class"], - attrValues: ["^foo$"], + attrValuePatterns: ["^foo$"], message: "no foo for alt or class", }, ], @@ -83,7 +100,7 @@ ruleTester.run("no-restricted-attr-values", rule, { options: [ { attrPatterns: [".*"], - attrValues: ["data.*"], + attrValuePatterns: ["data.*"], message: "please do not use 'data-x'", }, ], @@ -95,4 +112,3 @@ ruleTester.run("no-restricted-attr-values", rule, { }, ], }); -///^a$/ From 36cbe114a6400f39c6ef2891588db5121bac7494 Mon Sep 17 00:00:00 2001 From: adman00199 Date: Fri, 13 Oct 2023 14:55:37 +1100 Subject: [PATCH 5/5] chore: reverting extra changes to package files --- package-lock.json | 196 +++++++++++++++++++++++++++- packages/eslint-plugin/package.json | 1 - 2 files changed, 195 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index fc367064..99926243 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23593,7 +23593,6 @@ "@types/eslint": "^7.2.10", "@types/estree": "^0.0.47", "es-html-parser": "^0.0.8", - "eslint": "^7.32.0", "typescript": "^4.4.4" }, "engines": { @@ -24473,6 +24472,201 @@ "postcss": "^8.4.19", "tailwindcss": "^3.2.4" } + }, + "node_modules/@next/swc-android-arm-eabi": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-android-arm-eabi/-/swc-android-arm-eabi-13.0.6.tgz", + "integrity": "sha512-FGFSj3v2Bluw8fD/X+1eXIEB0PhoJE0zfutsAauRhmNpjjZshLDgoXMWm1jTRL/04K/o9gwwO2+A8+sPVCH1uw==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-android-arm64": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-android-arm64/-/swc-android-arm64-13.0.6.tgz", + "integrity": "sha512-7MgbtU7kimxuovVsd7jSJWMkIHBDBUsNLmmlkrBRHTvgzx5nDBXogP0hzZm7EImdOPwVMPpUHRQMBP9mbsiJYQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-darwin-arm64": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.0.6.tgz", + "integrity": "sha512-AUVEpVTxbP/fxdFsjVI9d5a0CFn6NVV7A/RXOb0Y+pXKIIZ1V5rFjPwpYfIfyOo2lrqgehMNQcyMRoTrhq04xg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-darwin-x64": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.0.6.tgz", + "integrity": "sha512-SasCDJlshglsPnbzhWaIF6VEGkQy2NECcAOxPwaPr0cwbbt4aUlZ7QmskNzgolr5eAjFS/xTr7CEeKJtZpAAtQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-freebsd-x64": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-freebsd-x64/-/swc-freebsd-x64-13.0.6.tgz", + "integrity": "sha512-6Lbxd9gAdXneTkwHyYW/qtX1Tdw7ND9UbiGsGz/SP43ZInNWnW6q0au4hEVPZ9bOWWRKzcVoeTBdoMpQk9Hx9w==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm-gnueabihf": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm-gnueabihf/-/swc-linux-arm-gnueabihf-13.0.6.tgz", + "integrity": "sha512-wNdi5A519e1P+ozEuYOhWPzzE6m1y7mkO6NFwn6watUwO0X9nZs7fT9THmnekvmFQpaZ6U+xf2MQ9poQoCh6jQ==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.0.6.tgz", + "integrity": "sha512-e8KTRnleQY1KLk5PwGV5hrmvKksCc74QRpHl5ffWnEEAtL2FE0ave5aIkXqErsPdXkiKuA/owp3LjQrP+/AH7Q==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.0.6.tgz", + "integrity": "sha512-/7RF03C3mhjYpHN+pqOolgME3guiHU5T3TsejuyteqyEyzdEyLHod+jcYH6ft7UZ71a6TdOewvmbLOtzHW2O8A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.0.6.tgz", + "integrity": "sha512-kxyEXnYHpOEkFnmrlwB1QlzJtjC6sAJytKcceIyFUHbCaD3W/Qb5tnclcnHKTaFccizZRePXvV25Ok/eUSpKTw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.0.6.tgz", + "integrity": "sha512-N0c6gubS3WW1oYYgo02xzZnNatfVQP/CiJq2ax+DJ55ePV62IACbRCU99TZNXXg+Kos6vNW4k+/qgvkvpGDeyA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.0.6.tgz", + "integrity": "sha512-QjeMB2EBqBFPb/ac0CYr7GytbhUkrG4EwFWbcE0vsRp4H8grt25kYpFQckL4Jak3SUrp7vKfDwZ/SwO7QdO8vw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.0.6.tgz", + "integrity": "sha512-EQzXtdqRTcmhT/tCq81rIwE36Y3fNHPInaCuJzM/kftdXfa0F+64y7FAoMO13npX8EG1+SamXgp/emSusKrCXg==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "13.0.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.0.6.tgz", + "integrity": "sha512-pSkqZ//UP/f2sS9T7IvHLfEWDPTX0vRyXJnAUNisKvO3eF3e1xdhDX7dix/X3Z3lnN4UjSwOzclAI87JFbOwmQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } } } } diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 00eac875..8cce7aec 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -44,7 +44,6 @@ "@types/eslint": "^7.2.10", "@types/estree": "^0.0.47", "es-html-parser": "^0.0.8", - "eslint": "^7.32.0", "typescript": "^4.4.4" } }