From 22d5483127f90d3fd24dc50ce72e7d34d42b56d4 Mon Sep 17 00:00:00 2001 From: ST-DDT Date: Sat, 28 Jun 2025 21:13:37 +0200 Subject: [PATCH 1/9] feat(no-deprecated-slot-attribute): regex ignore patterns --- docs/rules/no-deprecated-slot-attribute.md | 2 +- lib/rules/syntaxes/slot-attribute.js | 24 +++++-- .../lib/rules/no-deprecated-slot-attribute.js | 72 +++++++++++++++++++ 3 files changed, 93 insertions(+), 5 deletions(-) diff --git a/docs/rules/no-deprecated-slot-attribute.md b/docs/rules/no-deprecated-slot-attribute.md index 64f2c5e00..b65b2de7a 100644 --- a/docs/rules/no-deprecated-slot-attribute.md +++ b/docs/rules/no-deprecated-slot-attribute.md @@ -48,7 +48,7 @@ This rule reports deprecated `slot` attribute in Vue.js v2.6.0+. } ``` -- `"ignore"` (`string[]`) An array of tags that ignore this rules. This option will check both kebab-case and PascalCase versions of the given tag names. Default is empty. +- `"ignore"` (`string[]`) An array of tags or regular expression patterns (e.g. `/^custom-/`) that ignore this rules. This option will check both kebab-case and PascalCase versions of the given tag names. Default is empty. ### `"ignore": ["my-component"]` diff --git a/lib/rules/syntaxes/slot-attribute.js b/lib/rules/syntaxes/slot-attribute.js index 27087cb37..39670d719 100644 --- a/lib/rules/syntaxes/slot-attribute.js +++ b/lib/rules/syntaxes/slot-attribute.js @@ -5,6 +5,7 @@ 'use strict' const canConvertToVSlot = require('./utils/can-convert-to-v-slot') +const regexp = require('../../utils/regexp') const casing = require('../../utils/casing') module.exports = { @@ -12,9 +13,21 @@ module.exports = { supported: '<3.0.0', /** @param {RuleContext} context @returns {TemplateListener} */ createTemplateBodyVisitor(context) { + /** @type {{ ignore: string[]}} */ const options = context.options[0] || {} + const { ignore = [] } = options /** @type {Set} */ - const ignore = new Set(options.ignore) + const ignoreStrings = new Set() + /** @type {RegExp[]} */ + const ignorePatterns = [] + + for (const str of ignore) { + if (regexp.isRegExp(str)) { + ignorePatterns.push(regexp.toRegExp(str)) + } else { + ignoreStrings.add(str) + } + } const sourceCode = context.getSourceCode() const tokenStore = @@ -123,12 +136,15 @@ module.exports = { function reportSlot(slotAttr) { const componentName = slotAttr.parent.parent.rawName if ( - ignore.has(componentName) || - ignore.has(casing.pascalCase(componentName)) || - ignore.has(casing.kebabCase(componentName)) + ignoreStrings.has(componentName) || + ignoreStrings.has(casing.pascalCase(componentName)) || + ignoreStrings.has(casing.kebabCase(componentName)) ) { return } + if (ignorePatterns.some((pattern) => pattern.test(componentName))) { + return + } context.report({ node: slotAttr.key, diff --git a/tests/lib/rules/no-deprecated-slot-attribute.js b/tests/lib/rules/no-deprecated-slot-attribute.js index 2fd5fa401..b0aeca0bf 100644 --- a/tests/lib/rules/no-deprecated-slot-attribute.js +++ b/tests/lib/rules/no-deprecated-slot-attribute.js @@ -55,6 +55,18 @@ tester.run('no-deprecated-slot-attribute', rule, { `, options: [{ ignore: ['one', 'two', 'my-component'] }] + }, + { + code: ``, + options: [{ ignore: ['/one/', '/^Two$/i', '/^my-.*/i'] }] } ], invalid: [ @@ -644,6 +656,66 @@ tester.run('no-deprecated-slot-attribute', rule, { ], errors: ['`slot` attributes are deprecated.'] }, + { + code: ` + `, + output: ` + `, + options: [ + { + ignore: ['/one/'] + } + ], + errors: ['`slot` attributes are deprecated.'] + }, + { + code: ` + `, + output: ` + `, + options: [ + { + ignore: ['/^one$/'] + } + ], + errors: ['`slot` attributes are deprecated.'] + }, { code: `