From d485783e6f80a4ec7bef0592f2377fd2c8b54f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 17:13:54 +0800 Subject: [PATCH] chore: add a few todos --- lib/rules/fixer-return.js | 10 +++++----- lib/rules/meta-property-ordering.js | 2 +- lib/rules/no-deprecated-context-methods.js | 2 +- lib/rules/no-deprecated-report-api.js | 2 +- lib/rules/no-identical-tests.js | 2 +- lib/rules/no-missing-message-ids.js | 2 +- lib/rules/no-missing-placeholders.js | 2 +- lib/rules/no-only-tests.js | 2 +- lib/rules/no-unused-message-ids.js | 2 +- lib/rules/no-unused-placeholders.js | 2 +- lib/rules/no-useless-token-range.js | 2 +- lib/rules/prefer-message-ids.js | 2 +- lib/rules/prefer-object-rule.js | 2 +- lib/rules/prefer-output-null.js | 2 +- lib/rules/prefer-placeholders.js | 2 +- lib/rules/prefer-replace-text.js | 2 +- lib/rules/report-message-format.js | 2 +- lib/rules/require-meta-docs-description.js | 2 +- lib/rules/require-meta-docs-url.js | 4 ++-- lib/rules/require-meta-fixable.js | 2 +- lib/rules/require-meta-has-suggestions.js | 2 +- lib/rules/require-meta-schema.js | 2 +- lib/rules/require-meta-type.js | 2 +- lib/rules/test-case-property-ordering.js | 2 +- lib/rules/test-case-shorthand-strings.js | 2 +- lib/utils.js | 6 +++--- 26 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/rules/fixer-return.js b/lib/rules/fixer-return.js index fa14b905..ac231d8f 100644 --- a/lib/rules/fixer-return.js +++ b/lib/rules/fixer-return.js @@ -76,13 +76,12 @@ module.exports = { * @returns {boolean} */ function isFix(node) { + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: use context.sourceCode when dropping eslint < v9 if (node.type === 'ArrayExpression' && node.elements.length === 0) { // An empty array is not a fix. return false; } - const scope = - (context.sourceCode || context.getSourceCode()).getScope?.(node) || - context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0 + const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0 const staticValue = getStaticValue(node, scope); if (!staticValue) { // If we can't find a static value, assume it's a real fix value. @@ -100,7 +99,7 @@ module.exports = { return { Program(ast) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 contextIdentifiers = utils.getContextIdentifiers( sourceCode.scopeManager, ast @@ -150,7 +149,8 @@ module.exports = { // Ensure the current (arrow) fixer function returned a fix. 'ArrowFunctionExpression:exit'(node) { if (funcInfo.shouldCheck) { - const loc = context.getSourceCode().getTokenBefore(node.body).loc; // Show violation on arrow (=>). + const sourceCode = context.sourceCode || context.getSourceCode(); + const loc = sourceCode.getTokenBefore(node.body).loc; // Show violation on arrow (=>). if (node.expression) { // When the return is implied (no curly braces around the body), we have to check the single body node directly. if (!isFix(node.body)) { diff --git a/lib/rules/meta-property-ordering.js b/lib/rules/meta-property-ordering.js index e4480411..d07215d3 100644 --- a/lib/rules/meta-property-ordering.js +++ b/lib/rules/meta-property-ordering.js @@ -34,7 +34,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const ruleInfo = getRuleInfo(sourceCode); if (!ruleInfo) { return {}; diff --git a/lib/rules/no-deprecated-context-methods.js b/lib/rules/no-deprecated-context-methods.js index a1772d26..3d68edbb 100644 --- a/lib/rules/no-deprecated-context-methods.js +++ b/lib/rules/no-deprecated-context-methods.js @@ -54,7 +54,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 // ---------------------------------------------------------------------- // Public diff --git a/lib/rules/no-deprecated-report-api.js b/lib/rules/no-deprecated-report-api.js index 4ad45d96..59ff825d 100644 --- a/lib/rules/no-deprecated-report-api.js +++ b/lib/rules/no-deprecated-report-api.js @@ -30,7 +30,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 let contextIdentifiers; // ---------------------------------------------------------------------- diff --git a/lib/rules/no-identical-tests.js b/lib/rules/no-identical-tests.js index 5a1c0573..429eb626 100644 --- a/lib/rules/no-identical-tests.js +++ b/lib/rules/no-identical-tests.js @@ -32,7 +32,7 @@ module.exports = { // ---------------------------------------------------------------------- // Public // ---------------------------------------------------------------------- - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 // ---------------------------------------------------------------------- // Helpers diff --git a/lib/rules/no-missing-message-ids.js b/lib/rules/no-missing-message-ids.js index a4528d5d..73d12dd9 100644 --- a/lib/rules/no-missing-message-ids.js +++ b/lib/rules/no-missing-message-ids.js @@ -26,7 +26,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const { scopeManager } = sourceCode; const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { diff --git a/lib/rules/no-missing-placeholders.js b/lib/rules/no-missing-placeholders.js index 893700a6..f505d4f4 100644 --- a/lib/rules/no-missing-placeholders.js +++ b/lib/rules/no-missing-placeholders.js @@ -31,7 +31,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const { scopeManager } = sourceCode; let contextIdentifiers; diff --git a/lib/rules/no-only-tests.js b/lib/rules/no-only-tests.js index 264ac78e..fc016cc8 100644 --- a/lib/rules/no-only-tests.js +++ b/lib/rules/no-only-tests.js @@ -52,7 +52,7 @@ module.exports = { messageId: 'removeOnly', *fix(fixer) { const sourceCode = - context.sourceCode || context.getSourceCode(); + context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const tokenBefore = sourceCode.getTokenBefore(onlyProperty); diff --git a/lib/rules/no-unused-message-ids.js b/lib/rules/no-unused-message-ids.js index 7eded242..86840d15 100644 --- a/lib/rules/no-unused-message-ids.js +++ b/lib/rules/no-unused-message-ids.js @@ -24,7 +24,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const { scopeManager } = sourceCode; const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { diff --git a/lib/rules/no-unused-placeholders.js b/lib/rules/no-unused-placeholders.js index 9dcd9d4d..edace9c3 100644 --- a/lib/rules/no-unused-placeholders.js +++ b/lib/rules/no-unused-placeholders.js @@ -31,7 +31,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const { scopeManager } = sourceCode; let contextIdentifiers; diff --git a/lib/rules/no-useless-token-range.js b/lib/rules/no-useless-token-range.js index f3adb197..ea488190 100644 --- a/lib/rules/no-useless-token-range.js +++ b/lib/rules/no-useless-token-range.js @@ -30,7 +30,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 // ---------------------------------------------------------------------- // Helpers diff --git a/lib/rules/prefer-message-ids.js b/lib/rules/prefer-message-ids.js index 88cf2c1b..48bf348a 100644 --- a/lib/rules/prefer-message-ids.js +++ b/lib/rules/prefer-message-ids.js @@ -29,7 +29,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { return {}; diff --git a/lib/rules/prefer-object-rule.js b/lib/rules/prefer-object-rule.js index 5aa0942d..4cb11fcd 100644 --- a/lib/rules/prefer-object-rule.js +++ b/lib/rules/prefer-object-rule.js @@ -32,7 +32,7 @@ module.exports = { // Public // ---------------------------------------------------------------------- - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { return {}; diff --git a/lib/rules/prefer-output-null.js b/lib/rules/prefer-output-null.js index df2f4240..d58e4307 100644 --- a/lib/rules/prefer-output-null.js +++ b/lib/rules/prefer-output-null.js @@ -35,7 +35,7 @@ module.exports = { // Public // ---------------------------------------------------------------------- - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 return { Program(ast) { diff --git a/lib/rules/prefer-placeholders.js b/lib/rules/prefer-placeholders.js index 7f8bc122..bd3457c3 100644 --- a/lib/rules/prefer-placeholders.js +++ b/lib/rules/prefer-placeholders.js @@ -33,7 +33,7 @@ module.exports = { create(context) { let contextIdentifiers; - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const { scopeManager } = sourceCode; // ---------------------------------------------------------------------- diff --git a/lib/rules/prefer-replace-text.js b/lib/rules/prefer-replace-text.js index 615b3d33..a9517ed2 100644 --- a/lib/rules/prefer-replace-text.js +++ b/lib/rules/prefer-replace-text.js @@ -30,7 +30,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 let funcInfo = { upper: null, codePath: null, diff --git a/lib/rules/report-message-format.js b/lib/rules/report-message-format.js index 15da50ce..d22d9cfa 100644 --- a/lib/rules/report-message-format.js +++ b/lib/rules/report-message-format.js @@ -57,7 +57,7 @@ module.exports = { } } - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { return {}; diff --git a/lib/rules/require-meta-docs-description.js b/lib/rules/require-meta-docs-description.js index b724f5bf..3afd6d8d 100644 --- a/lib/rules/require-meta-docs-description.js +++ b/lib/rules/require-meta-docs-description.js @@ -45,7 +45,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { return {}; diff --git a/lib/rules/require-meta-docs-url.js b/lib/rules/require-meta-docs-url.js index 4f62556b..d52f1984 100644 --- a/lib/rules/require-meta-docs-url.js +++ b/lib/rules/require-meta-docs-url.js @@ -54,7 +54,7 @@ module.exports = { */ create(context) { const options = context.options[0] || {}; - const filename = context.filename || context.getFilename(); + const filename = context.filename || context.getFilename(); // TODO: just use context.filename when dropping eslint < v9 const ruleName = filename === '' ? undefined @@ -76,7 +76,7 @@ module.exports = { ); } - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const ruleInfo = util.getRuleInfo(sourceCode); if (!ruleInfo) { return {}; diff --git a/lib/rules/require-meta-fixable.js b/lib/rules/require-meta-fixable.js index 1375a1a9..3b9ec681 100644 --- a/lib/rules/require-meta-fixable.js +++ b/lib/rules/require-meta-fixable.js @@ -49,7 +49,7 @@ module.exports = { const catchNoFixerButFixableProperty = context.options[0] && context.options[0].catchNoFixerButFixableProperty; - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const { scopeManager } = sourceCode; const ruleInfo = utils.getRuleInfo(sourceCode); let contextIdentifiers; diff --git a/lib/rules/require-meta-has-suggestions.js b/lib/rules/require-meta-has-suggestions.js index 0a5014e3..3c9a0050 100644 --- a/lib/rules/require-meta-has-suggestions.js +++ b/lib/rules/require-meta-has-suggestions.js @@ -29,7 +29,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const { scopeManager } = sourceCode; const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { diff --git a/lib/rules/require-meta-schema.js b/lib/rules/require-meta-schema.js index 5c61531d..30d24109 100644 --- a/lib/rules/require-meta-schema.js +++ b/lib/rules/require-meta-schema.js @@ -43,7 +43,7 @@ module.exports = { }, create(context) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const { scopeManager } = sourceCode; const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { diff --git a/lib/rules/require-meta-type.js b/lib/rules/require-meta-type.js index 25bd58a3..1b3a14c4 100644 --- a/lib/rules/require-meta-type.js +++ b/lib/rules/require-meta-type.js @@ -38,7 +38,7 @@ module.exports = { // Public // ---------------------------------------------------------------------- - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const ruleInfo = utils.getRuleInfo(sourceCode); if (!ruleInfo) { return {}; diff --git a/lib/rules/test-case-property-ordering.js b/lib/rules/test-case-property-ordering.js index 099232fb..73cb700f 100644 --- a/lib/rules/test-case-property-ordering.js +++ b/lib/rules/test-case-property-ordering.js @@ -50,7 +50,7 @@ module.exports = { 'env', 'errors', ]; - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 return { Program(ast) { diff --git a/lib/rules/test-case-shorthand-strings.js b/lib/rules/test-case-shorthand-strings.js index 0594d4cc..84b16e20 100644 --- a/lib/rules/test-case-shorthand-strings.js +++ b/lib/rules/test-case-shorthand-strings.js @@ -34,7 +34,7 @@ module.exports = { create(context) { const shorthandOption = context.options[0] || 'as-needed'; - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 // ---------------------------------------------------------------------- // Helpers diff --git a/lib/utils.js b/lib/utils.js index e9142b92..219a04c6 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -444,6 +444,7 @@ module.exports = { statements, variableIdentifiers = new Set() ) { + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: just use context.sourceCode when dropping eslint < v9 const runCalls = []; for (const statement of statements) { @@ -612,9 +613,8 @@ module.exports = { } let keys; - const scope = - (context.sourceCode || context.getSourceCode()).getScope?.(node) || - context.getScope(); // TODO: just use sourceCode.getScope() when dropping eslint < v9 + const sourceCode = context.sourceCode || context.getSourceCode(); // TODO: use context.sourceCode when dropping eslint < v9 + const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when dropping eslint < v9 const secondArgStaticValue = getStaticValue(reportArgs[1], scope); if (