From 7b7b4cead55fb8bcd6d3a57191c5b2c0b64c53b9 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Wed, 29 Nov 2023 22:08:45 +0900 Subject: [PATCH] Improve compatibility with ESLint v9 (#2331) --- .../shim/eslint/use-at-your-own-risk.mjs | 3 + docs/.vitepress/config.mts | 4 + eslint.config.js | 14 +++ lib/rules/block-order.js | 5 +- lib/rules/block-tag-newline.js | 7 +- lib/rules/comment-directive.js | 5 +- .../component-name-in-template-casing.js | 5 +- lib/rules/custom-event-name-casing.js | 15 ++- lib/rules/first-attribute-linebreak.js | 5 +- lib/rules/html-closing-bracket-newline.js | 5 +- lib/rules/html-closing-bracket-spacing.js | 4 +- lib/rules/html-indent.js | 5 +- lib/rules/html-self-closing.js | 4 +- lib/rules/max-attributes-per-line.js | 4 +- lib/rules/max-len.js | 4 +- lib/rules/max-lines-per-block.js | 5 +- .../multiline-html-element-content-newline.js | 6 +- lib/rules/mustache-interpolation-spacing.js | 5 +- lib/rules/next-tick-style.js | 5 +- lib/rules/no-async-in-computed-properties.js | 5 +- lib/rules/no-child-content.js | 4 +- lib/rules/no-dupe-keys.js | 7 +- lib/rules/no-dupe-v-else-if.js | 5 +- lib/rules/no-empty-component-block.js | 5 +- lib/rules/no-expose-after-await.js | 10 +- lib/rules/no-extra-parens.js | 5 +- lib/rules/no-lifecycle-after-await.js | 5 +- lib/rules/no-multi-spaces.js | 6 +- lib/rules/no-multiple-slot-args.js | 2 +- lib/rules/no-mutating-props.js | 2 +- lib/rules/no-restricted-block.js | 5 +- lib/rules/no-restricted-call-after-await.js | 2 +- lib/rules/no-restricted-custom-event.js | 10 +- lib/rules/no-setup-props-reactivity-loss.js | 18 +++- .../no-side-effects-in-computed-properties.js | 7 +- lib/rules/no-unused-emit-declarations.js | 9 +- lib/rules/no-useless-mustaches.js | 3 +- lib/rules/no-useless-v-bind.js | 2 +- lib/rules/no-watch-after-await.js | 5 +- lib/rules/padding-line-between-blocks.js | 5 +- lib/rules/prefer-separate-static-class.js | 3 +- lib/rules/require-explicit-emits.js | 9 +- lib/rules/require-expose.js | 9 +- lib/rules/require-slots-as-functions.js | 2 +- lib/rules/require-typed-ref.js | 6 +- lib/rules/return-in-computed-property.js | 5 +- ...singleline-html-element-content-newline.js | 6 +- lib/rules/syntaxes/slot-attribute.js | 4 +- lib/rules/syntaxes/slot-scope-attribute.js | 4 +- lib/rules/v-for-delimiter-style.js | 5 +- lib/rules/v-on-function-call.js | 4 +- lib/rules/v-on-handler-style.js | 7 +- lib/rules/valid-define-emits.js | 2 +- lib/rules/valid-define-options.js | 2 +- lib/rules/valid-define-props.js | 2 +- lib/rules/valid-next-tick.js | 2 +- lib/rules/valid-v-slot.js | 4 +- lib/utils/index.js | 92 +++++++++---------- lib/utils/scope.js | 30 ++++++ lib/utils/style-variables/index.js | 5 +- lib/utils/ts-utils/ts-ast.js | 11 ++- lib/utils/ts-utils/ts-types.js | 9 +- 62 files changed, 290 insertions(+), 165 deletions(-) create mode 100644 docs/.vitepress/build-system/shim/eslint/use-at-your-own-risk.mjs create mode 100644 lib/utils/scope.js diff --git a/docs/.vitepress/build-system/shim/eslint/use-at-your-own-risk.mjs b/docs/.vitepress/build-system/shim/eslint/use-at-your-own-risk.mjs new file mode 100644 index 000000000..0db0b01c2 --- /dev/null +++ b/docs/.vitepress/build-system/shim/eslint/use-at-your-own-risk.mjs @@ -0,0 +1,3 @@ +export default { + /* empty */ +} diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 66e0f3e3a..0e1e21730 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -145,6 +145,10 @@ export default async () => { plugins: [vitePluginRequireResolve(), viteCommonjs()], resolve: { alias: { + 'eslint/use-at-your-own-risk': path.join( + dirname, + './build-system/shim/eslint/use-at-your-own-risk.mjs' + ), eslint: path.join(dirname, './build-system/shim/eslint.mjs'), assert: path.join(dirname, './build-system/shim/assert.mjs'), path: path.join(dirname, './build-system/shim/path.mjs'), diff --git a/eslint.config.js b/eslint.config.js index abedce70b..3407dd3b4 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -160,6 +160,20 @@ module.exports = [ 'dot-notation': 'error', 'arrow-body-style': 'error', + 'no-restricted-properties': [ + 'error', + { + object: 'context', + property: 'parserServices', + message: 'Use sourceCode.parserServices' + }, + { + object: 'context', + property: 'getScope', + message: 'Use utils.getScope' + } + ], + 'unicorn/consistent-function-scoping': [ 'error', { checkArrowFunctions: false } diff --git a/lib/rules/block-order.js b/lib/rules/block-order.js index 91d3eaa6f..c93de09b2 100644 --- a/lib/rules/block-order.js +++ b/lib/rules/block-order.js @@ -106,9 +106,10 @@ module.exports = { function getOrderElement(element) { return orders.find((o) => o.selector.test(element)) } + const sourceCode = context.getSourceCode() const documentFragment = - context.parserServices.getDocumentFragment && - context.parserServices.getDocumentFragment() + sourceCode.parserServices.getDocumentFragment && + sourceCode.parserServices.getDocumentFragment() function getTopLevelHTMLElements() { if (documentFragment) { diff --git a/lib/rules/block-tag-newline.js b/lib/rules/block-tag-newline.js index bccecd834..22fb12870 100644 --- a/lib/rules/block-tag-newline.js +++ b/lib/rules/block-tag-newline.js @@ -84,15 +84,14 @@ module.exports = { }, /** @param {RuleContext} context */ create(context) { + const sourceCode = context.getSourceCode() const df = - context.parserServices.getDocumentFragment && - context.parserServices.getDocumentFragment() + sourceCode.parserServices.getDocumentFragment && + sourceCode.parserServices.getDocumentFragment() if (!df) { return {} } - const sourceCode = context.getSourceCode() - /** * @param {VStartTag} startTag * @param {string} beforeText diff --git a/lib/rules/comment-directive.js b/lib/rules/comment-directive.js index aeca98aef..655e222bd 100644 --- a/lib/rules/comment-directive.js +++ b/lib/rules/comment-directive.js @@ -313,9 +313,10 @@ module.exports = { const options = context.options[0] || {} /** @type {boolean} */ const reportUnusedDisableDirectives = options.reportUnusedDisableDirectives + const sourceCode = context.getSourceCode() const documentFragment = - context.parserServices.getDocumentFragment && - context.parserServices.getDocumentFragment() + sourceCode.parserServices.getDocumentFragment && + sourceCode.parserServices.getDocumentFragment() return { Program(node) { diff --git a/lib/rules/component-name-in-template-casing.js b/lib/rules/component-name-in-template-casing.js index 487af7714..629f51209 100644 --- a/lib/rules/component-name-in-template-casing.js +++ b/lib/rules/component-name-in-template-casing.js @@ -86,9 +86,10 @@ module.exports = { /** @type {string[]} */ const globals = (options.globals || []).map(casing.pascalCase) const registeredComponentsOnly = options.registeredComponentsOnly !== false + const sourceCode = context.getSourceCode() const tokens = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() /** @type { Set } */ const registeredComponents = new Set(globals) diff --git a/lib/rules/custom-event-name-casing.js b/lib/rules/custom-event-name-casing.js index 2361badb1..09cc2fc36 100644 --- a/lib/rules/custom-event-name-casing.js +++ b/lib/rules/custom-event-name-casing.js @@ -210,7 +210,10 @@ module.exports = { return } // const emit = defineEmits() - const variable = findVariable(context.getScope(), emitParam) + const variable = findVariable( + utils.getScope(context, emitParam), + emitParam + ) if (!variable) { return } @@ -251,7 +254,10 @@ module.exports = { } const emitParam = emitProperty.value // `setup(props, {emit})` - const variable = findVariable(context.getScope(), emitParam) + const variable = findVariable( + utils.getScope(context, emitParam), + emitParam + ) if (!variable) { return } @@ -260,7 +266,10 @@ module.exports = { } } else { // `setup(props, context)` - const variable = findVariable(context.getScope(), contextParam) + const variable = findVariable( + utils.getScope(context, contextParam), + contextParam + ) if (!variable) { return } diff --git a/lib/rules/first-attribute-linebreak.js b/lib/rules/first-attribute-linebreak.js index bdaf078c9..c023762d4 100644 --- a/lib/rules/first-attribute-linebreak.js +++ b/lib/rules/first-attribute-linebreak.js @@ -39,9 +39,10 @@ module.exports = { const multiline = (context.options[0] && context.options[0].multiline) || 'below' + const sourceCode = context.getSourceCode() const template = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() /** * Report attribute diff --git a/lib/rules/html-closing-bracket-newline.js b/lib/rules/html-closing-bracket-newline.js index e1a746e42..c353c35d3 100644 --- a/lib/rules/html-closing-bracket-newline.js +++ b/lib/rules/html-closing-bracket-newline.js @@ -59,9 +59,10 @@ module.exports = { }, context.options[0] || {} ) + const sourceCode = context.getSourceCode() const template = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() return utils.defineDocumentVisitor(context, { /** @param {VStartTag | VEndTag} node */ diff --git a/lib/rules/html-closing-bracket-spacing.js b/lib/rules/html-closing-bracket-spacing.js index 0d5d477ba..daf42d540 100644 --- a/lib/rules/html-closing-bracket-spacing.js +++ b/lib/rules/html-closing-bracket-spacing.js @@ -80,8 +80,8 @@ module.exports = { create(context) { const sourceCode = context.getSourceCode() const tokens = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() const options = parseOptions(context.options[0], tokens) return utils.defineDocumentVisitor(context, { diff --git a/lib/rules/html-indent.js b/lib/rules/html-indent.js index 1670a3308..6a423ecca 100644 --- a/lib/rules/html-indent.js +++ b/lib/rules/html-indent.js @@ -11,9 +11,10 @@ const utils = require('../utils') module.exports = { /** @param {RuleContext} context */ create(context) { + const sourceCode = context.getSourceCode() const tokenStore = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() const visitor = indentCommon.defineVisitor(context, tokenStore, { baseIndent: 1 }) diff --git a/lib/rules/html-self-closing.js b/lib/rules/html-self-closing.js index 621cde6d1..9e626f41d 100644 --- a/lib/rules/html-self-closing.js +++ b/lib/rules/html-self-closing.js @@ -159,7 +159,7 @@ module.exports = { }, fix(fixer) { const tokens = - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore() const close = tokens.getLastToken(node.startTag) if (close.type !== 'HTMLTagClose') { return null @@ -183,7 +183,7 @@ module.exports = { }, fix(fixer) { const tokens = - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore() const close = tokens.getLastToken(node.startTag) if (close.type !== 'HTMLSelfClosingTagClose') { return null diff --git a/lib/rules/max-attributes-per-line.js b/lib/rules/max-attributes-per-line.js index b1665c17d..443826fe0 100644 --- a/lib/rules/max-attributes-per-line.js +++ b/lib/rules/max-attributes-per-line.js @@ -124,8 +124,8 @@ module.exports = { const multilineMaximum = configuration.multiline const singlelinemMaximum = configuration.singleline const template = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() return utils.defineTemplateBodyVisitor(context, { VStartTag(node) { diff --git a/lib/rules/max-len.js b/lib/rules/max-len.js index 588f2de75..9347ea78b 100644 --- a/lib/rules/max-len.js +++ b/lib/rules/max-len.js @@ -307,8 +307,8 @@ module.exports = { const scriptTokens = sourceCode.ast.tokens const scriptComments = sourceCode.getAllComments() - if (context.parserServices.getTemplateBodyTokenStore && templateBody) { - const tokenStore = context.parserServices.getTemplateBodyTokenStore() + if (sourceCode.parserServices.getTemplateBodyTokenStore && templateBody) { + const tokenStore = sourceCode.parserServices.getTemplateBodyTokenStore() const templateTokens = tokenStore.getTokens(templateBody, { includeComments: true diff --git a/lib/rules/max-lines-per-block.js b/lib/rules/max-lines-per-block.js index bcb82d563..c778ef40b 100644 --- a/lib/rules/max-lines-per-block.js +++ b/lib/rules/max-lines-per-block.js @@ -65,9 +65,10 @@ module.exports = { } const code = context.getSourceCode() + const sourceCode = context.getSourceCode() const documentFragment = - context.parserServices.getDocumentFragment && - context.parserServices.getDocumentFragment() + sourceCode.parserServices.getDocumentFragment && + sourceCode.parserServices.getDocumentFragment() function getTopLevelHTMLElements() { if (documentFragment) { diff --git a/lib/rules/multiline-html-element-content-newline.js b/lib/rules/multiline-html-element-content-newline.js index dc4111864..bfe0c79f7 100644 --- a/lib/rules/multiline-html-element-content-newline.js +++ b/lib/rules/multiline-html-element-content-newline.js @@ -98,10 +98,10 @@ module.exports = { const ignores = options.ignores const ignoreWhenEmpty = options.ignoreWhenEmpty const allowEmptyLines = options.allowEmptyLines - const template = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() const sourceCode = context.getSourceCode() + const template = + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() /** @type {VElement | null} */ let inIgnoreElement = null diff --git a/lib/rules/mustache-interpolation-spacing.js b/lib/rules/mustache-interpolation-spacing.js index 51b19c616..79bae0543 100644 --- a/lib/rules/mustache-interpolation-spacing.js +++ b/lib/rules/mustache-interpolation-spacing.js @@ -30,9 +30,10 @@ module.exports = { /** @param {RuleContext} context */ create(context) { const options = context.options[0] || 'always' + const sourceCode = context.getSourceCode() const template = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() return utils.defineTemplateBodyVisitor(context, { /** @param {VExpressionContainer} node */ diff --git a/lib/rules/next-tick-style.js b/lib/rules/next-tick-style.js index 34e0c3db6..08cc85a1b 100644 --- a/lib/rules/next-tick-style.js +++ b/lib/rules/next-tick-style.js @@ -43,7 +43,10 @@ function getVueNextTickCallExpression(identifier, context) { identifier.parent.type === 'CallExpression' && identifier.parent.callee === identifier ) { - const variable = findVariable(context.getScope(), identifier) + const variable = findVariable( + utils.getScope(context, identifier), + identifier + ) if (variable != null && variable.defs.length === 1) { const def = variable.defs[0] diff --git a/lib/rules/no-async-in-computed-properties.js b/lib/rules/no-async-in-computed-properties.js index 2df1e55c0..6ee4373f1 100644 --- a/lib/rules/no-async-in-computed-properties.js +++ b/lib/rules/no-async-in-computed-properties.js @@ -260,8 +260,9 @@ module.exports = { return utils.compositingVisitors( { - Program() { - const tracker = new ReferenceTracker(context.getScope()) + /** @param {Program} program */ + Program(program) { + const tracker = new ReferenceTracker(utils.getScope(context, program)) const traceMap = utils.createCompositionApiTraceMap({ [ReferenceTracker.ESM]: true, computed: { diff --git a/lib/rules/no-child-content.js b/lib/rules/no-child-content.js index 6ccf10d18..62de865b8 100644 --- a/lib/rules/no-child-content.js +++ b/lib/rules/no-child-content.js @@ -123,8 +123,8 @@ module.exports = { if (elementNode.endTag === null) { return } - - const tokenStore = context.parserServices.getTemplateBodyTokenStore() + const sourceCode = context.getSourceCode() + const tokenStore = sourceCode.parserServices.getTemplateBodyTokenStore() const elementComments = tokenStore.getTokensBetween( elementNode.startTag, elementNode.endTag, diff --git a/lib/rules/no-dupe-keys.js b/lib/rules/no-dupe-keys.js index c690d8aa5..dd8b51c6d 100644 --- a/lib/rules/no-dupe-keys.js +++ b/lib/rules/no-dupe-keys.js @@ -118,7 +118,10 @@ module.exports = { for (const prop of props) { if (!prop.propName) continue - const variable = findVariable(context.getScope(), prop.propName) + const variable = findVariable( + utils.getScope(context, node), + prop.propName + ) if (!variable || variable.defs.length === 0) continue if ( @@ -149,7 +152,7 @@ module.exports = { */ function extractReferences(node) { if (node.type === 'Identifier') { - const variable = findVariable(context.getScope(), node) + const variable = findVariable(utils.getScope(context, node), node) if (!variable) { return [] } diff --git a/lib/rules/no-dupe-v-else-if.js b/lib/rules/no-dupe-v-else-if.js index 5102f6dc4..dc7c18c0b 100644 --- a/lib/rules/no-dupe-v-else-if.js +++ b/lib/rules/no-dupe-v-else-if.js @@ -83,9 +83,10 @@ module.exports = { }, /** @param {RuleContext} context */ create(context) { + const sourceCode = context.getSourceCode() const tokenStore = - context.parserServices.getTemplateBodyTokenStore && - context.parserServices.getTemplateBodyTokenStore() + sourceCode.parserServices.getTemplateBodyTokenStore && + sourceCode.parserServices.getTemplateBodyTokenStore() /** * Determines whether the two given nodes are considered to be equal. In particular, given that the nodes * represent expressions in a boolean context, `||` and `&&` can be considered as commutative operators. diff --git a/lib/rules/no-empty-component-block.js b/lib/rules/no-empty-component-block.js index 8a9420fc2..b2e428bc7 100644 --- a/lib/rules/no-empty-component-block.js +++ b/lib/rules/no-empty-component-block.js @@ -57,10 +57,11 @@ module.exports = { * @returns {RuleListener} AST event handlers. */ create(context) { - if (!context.parserServices.getDocumentFragment) { + const sourceCode = context.getSourceCode() + if (!sourceCode.parserServices.getDocumentFragment) { return {} } - const documentFragment = context.parserServices.getDocumentFragment() + const documentFragment = sourceCode.parserServices.getDocumentFragment() if (!documentFragment) { return {} } diff --git a/lib/rules/no-expose-after-await.js b/lib/rules/no-expose-after-await.js index 64661f1f3..e5ede6444 100644 --- a/lib/rules/no-expose-after-await.js +++ b/lib/rules/no-expose-after-await.js @@ -192,7 +192,10 @@ module.exports = { // `setup(props, {emit})` const variable = exposeParam.type === 'Identifier' - ? findVariable(context.getScope(), exposeParam) + ? findVariable( + utils.getScope(context, exposeParam), + exposeParam + ) : null if (!variable) { return @@ -205,7 +208,10 @@ module.exports = { } } else if (contextParam.type === 'Identifier') { // `setup(props, context)` - const variable = findVariable(context.getScope(), contextParam) + const variable = findVariable( + utils.getScope(context, contextParam), + contextParam + ) if (!variable) { return } diff --git a/lib/rules/no-extra-parens.js b/lib/rules/no-extra-parens.js index 7264677cc..afd0e061b 100644 --- a/lib/rules/no-extra-parens.js +++ b/lib/rules/no-extra-parens.js @@ -84,10 +84,11 @@ function isIIFE(node) { * @returns {TemplateListener} AST event handlers. */ function createForVueSyntax(context) { - if (!context.parserServices.getTemplateBodyTokenStore) { + const sourceCode = context.getSourceCode() + if (!sourceCode.parserServices.getTemplateBodyTokenStore) { return {} } - const tokenStore = context.parserServices.getTemplateBodyTokenStore() + const tokenStore = sourceCode.parserServices.getTemplateBodyTokenStore() /** * Checks if the given node turns into a filter when unwraped. diff --git a/lib/rules/no-lifecycle-after-await.js b/lib/rules/no-lifecycle-after-await.js index 6a54f1c58..21416f893 100644 --- a/lib/rules/no-lifecycle-after-await.js +++ b/lib/rules/no-lifecycle-after-await.js @@ -60,8 +60,9 @@ module.exports = { return utils.compositingVisitors( { - Program() { - const tracker = new ReferenceTracker(context.getScope()) + /** @param {Program} program */ + Program(program) { + const tracker = new ReferenceTracker(utils.getScope(context, program)) const traceMap = { /** @type {TraceMap} */ vue: { diff --git a/lib/rules/no-multi-spaces.js b/lib/rules/no-multi-spaces.js index 1dbac86e2..7e8f192a1 100644 --- a/lib/rules/no-multi-spaces.js +++ b/lib/rules/no-multi-spaces.js @@ -52,7 +52,8 @@ module.exports = { return { Program(node) { - if (context.parserServices.getTemplateBodyTokenStore == null) { + const sourceCode = context.getSourceCode() + if (sourceCode.parserServices.getTemplateBodyTokenStore == null) { const filename = context.getFilename() if (path.extname(filename) === '.vue') { context.report({ @@ -65,8 +66,7 @@ module.exports = { if (!node.templateBody) { return } - const sourceCode = context.getSourceCode() - const tokenStore = context.parserServices.getTemplateBodyTokenStore() + const tokenStore = sourceCode.parserServices.getTemplateBodyTokenStore() const tokens = tokenStore.getTokens(node.templateBody, { includeComments: true }) diff --git a/lib/rules/no-multiple-slot-args.js b/lib/rules/no-multiple-slot-args.js index 1b57832af..86bd63037 100644 --- a/lib/rules/no-multiple-slot-args.js +++ b/lib/rules/no-multiple-slot-args.js @@ -75,7 +75,7 @@ module.exports = { * @param {Identifier} node The node to verify */ function verifyReferences(node) { - const variable = findVariable(context.getScope(), node) + const variable = findVariable(utils.getScope(context, node), node) if (!variable) { return } diff --git a/lib/rules/no-mutating-props.js b/lib/rules/no-mutating-props.js index 57a191991..c00a92242 100644 --- a/lib/rules/no-mutating-props.js +++ b/lib/rules/no-mutating-props.js @@ -224,7 +224,7 @@ module.exports = { * @param {string[]} path */ function verifyPropVariable(prop, path) { - const variable = findVariable(context.getScope(), prop) + const variable = findVariable(utils.getScope(context, prop), prop) if (!variable) { return } diff --git a/lib/rules/no-restricted-block.js b/lib/rules/no-restricted-block.js index 8fc2b51be..87b4bda3e 100644 --- a/lib/rules/no-restricted-block.js +++ b/lib/rules/no-restricted-block.js @@ -90,9 +90,10 @@ module.exports = { /** @type {ParsedOption[]} */ const options = context.options.map(parseOption) + const sourceCode = context.getSourceCode() const documentFragment = - context.parserServices.getDocumentFragment && - context.parserServices.getDocumentFragment() + sourceCode.parserServices.getDocumentFragment && + sourceCode.parserServices.getDocumentFragment() function getTopLevelHTMLElements() { if (documentFragment) { diff --git a/lib/rules/no-restricted-call-after-await.js b/lib/rules/no-restricted-call-after-await.js index d2b2a1414..b235896a3 100644 --- a/lib/rules/no-restricted-call-after-await.js +++ b/lib/rules/no-restricted-call-after-await.js @@ -144,7 +144,7 @@ module.exports = { { /** @param {Program} node */ Program(node) { - const tracker = new ReferenceTracker(context.getScope()) + const tracker = new ReferenceTracker(utils.getScope(context, node)) for (const option of context.options) { const modules = normalizeModules(option.module, node) diff --git a/lib/rules/no-restricted-custom-event.js b/lib/rules/no-restricted-custom-event.js index f153b6921..98a87d807 100644 --- a/lib/rules/no-restricted-custom-event.js +++ b/lib/rules/no-restricted-custom-event.js @@ -213,7 +213,10 @@ module.exports = { } const emitParam = emitProperty.value // `setup(props, {emit})` - const variable = findVariable(context.getScope(), emitParam) + const variable = findVariable( + utils.getScope(context, emitParam), + emitParam + ) if (!variable) { return } @@ -222,7 +225,10 @@ module.exports = { } } else { // `setup(props, context)` - const variable = findVariable(context.getScope(), contextParam) + const variable = findVariable( + utils.getScope(context, contextParam), + contextParam + ) if (!variable) { return } diff --git a/lib/rules/no-setup-props-reactivity-loss.js b/lib/rules/no-setup-props-reactivity-loss.js index 1292ace7a..fc0406ba9 100644 --- a/lib/rules/no-setup-props-reactivity-loss.js +++ b/lib/rules/no-setup-props-reactivity-loss.js @@ -123,9 +123,10 @@ module.exports = { /** * @param {Pattern | null} node * @param {FunctionDeclaration | FunctionExpression | ArrowFunctionExpression | Program} scopeNode + * @param {import('eslint').Scope.Scope} currentScope * @param {string} scopeName */ - function processPattern(node, scopeNode, scopeName) { + function processPattern(node, scopeNode, currentScope, scopeName) { if (!node) { // no arguments return @@ -143,14 +144,14 @@ module.exports = { return } - const variable = findVariable(context.getScope(), node) + const variable = findVariable(currentScope, node) if (!variable) { return } const propsReferenceIds = new Set() for (const reference of variable.references) { // If reference is in another scope, we can't check it. - if (reference.from !== context.getScope()) { + if (reference.from !== currentScope) { continue } @@ -258,13 +259,20 @@ module.exports = { } else if (target.parent.type === 'AssignmentExpression') { id = target.parent.right === target ? target.parent.left : null } - processPattern(id, context.getSourceCode().ast, '