From c5c353f6cfa0db4ee1e215cc3e4b4ed5991524b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 14:39:44 +0800 Subject: [PATCH 01/12] refactor: getReportInfo() now takes the ASTNode of context.report() as the node is required to use the new `sourceCode.getScope(node)` API. --- lib/rules/no-deprecated-report-api.js | 2 +- lib/rules/no-missing-message-ids.js | 2 +- lib/rules/no-missing-placeholders.js | 2 +- lib/rules/no-unused-message-ids.js | 2 +- lib/rules/no-unused-placeholders.js | 2 +- lib/rules/prefer-message-ids.js | 2 +- lib/rules/prefer-placeholders.js | 2 +- lib/rules/report-message-format.js | 2 +- lib/utils.js | 12 +++++++----- tests/lib/utils.js | 9 +++++---- 10 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/rules/no-deprecated-report-api.js b/lib/rules/no-deprecated-report-api.js index d6c7b373..cc862a12 100644 --- a/lib/rules/no-deprecated-report-api.js +++ b/lib/rules/no-deprecated-report-api.js @@ -60,7 +60,7 @@ module.exports = { fix(fixer) { const openingParen = sourceCode.getTokenBefore(node.arguments[0]); const closingParen = sourceCode.getLastToken(node); - const reportInfo = utils.getReportInfo(node.arguments, context); + const reportInfo = utils.getReportInfo(node, context); if (!reportInfo) { return null; diff --git a/lib/rules/no-missing-message-ids.js b/lib/rules/no-missing-message-ids.js index dec2f17b..10c6c461 100644 --- a/lib/rules/no-missing-message-ids.js +++ b/lib/rules/no-missing-message-ids.js @@ -55,7 +55,7 @@ module.exports = { node.callee.property.type === 'Identifier' && node.callee.property.name === 'report' ) { - const reportInfo = utils.getReportInfo(node.arguments, context); + const reportInfo = utils.getReportInfo(node, context); if (!reportInfo) { return; } diff --git a/lib/rules/no-missing-placeholders.js b/lib/rules/no-missing-placeholders.js index a70fbd92..9033c349 100644 --- a/lib/rules/no-missing-placeholders.js +++ b/lib/rules/no-missing-placeholders.js @@ -54,7 +54,7 @@ module.exports = { node.callee.property.type === 'Identifier' && node.callee.property.name === 'report' ) { - const reportInfo = utils.getReportInfo(node.arguments, context); + const reportInfo = utils.getReportInfo(node, context); if (!reportInfo) { return; } diff --git a/lib/rules/no-unused-message-ids.js b/lib/rules/no-unused-message-ids.js index 2bd1b451..240db5d3 100644 --- a/lib/rules/no-unused-message-ids.js +++ b/lib/rules/no-unused-message-ids.js @@ -82,7 +82,7 @@ module.exports = { node.callee.property.type === 'Identifier' && node.callee.property.name === 'report' ) { - const reportInfo = utils.getReportInfo(node.arguments, context); + const reportInfo = utils.getReportInfo(node, context); if (!reportInfo) { return; } diff --git a/lib/rules/no-unused-placeholders.js b/lib/rules/no-unused-placeholders.js index 51defefb..f41ca997 100644 --- a/lib/rules/no-unused-placeholders.js +++ b/lib/rules/no-unused-placeholders.js @@ -53,7 +53,7 @@ module.exports = { node.callee.property.type === 'Identifier' && node.callee.property.name === 'report' ) { - const reportInfo = utils.getReportInfo(node.arguments, context); + const reportInfo = utils.getReportInfo(node, context); if (!reportInfo) { return; } diff --git a/lib/rules/prefer-message-ids.js b/lib/rules/prefer-message-ids.js index 539d7104..a708ff5d 100644 --- a/lib/rules/prefer-message-ids.js +++ b/lib/rules/prefer-message-ids.js @@ -90,7 +90,7 @@ module.exports = { node.callee.property.type === 'Identifier' && node.callee.property.name === 'report' ) { - const reportInfo = utils.getReportInfo(node.arguments, context); + const reportInfo = utils.getReportInfo(node, context); if (!reportInfo) { return; } diff --git a/lib/rules/prefer-placeholders.js b/lib/rules/prefer-placeholders.js index cc29d4b4..fbd29d67 100644 --- a/lib/rules/prefer-placeholders.js +++ b/lib/rules/prefer-placeholders.js @@ -51,7 +51,7 @@ module.exports = { node.callee.property.type === 'Identifier' && node.callee.property.name === 'report' ) { - const reportInfo = utils.getReportInfo(node.arguments, context); + const reportInfo = utils.getReportInfo(node, context); if (!reportInfo) { return; diff --git a/lib/rules/report-message-format.js b/lib/rules/report-message-format.js index 770524c0..36f1bdd4 100644 --- a/lib/rules/report-message-format.js +++ b/lib/rules/report-message-format.js @@ -102,7 +102,7 @@ module.exports = { node.callee.property.type === 'Identifier' && node.callee.property.name === 'report' ) { - const reportInfo = utils.getReportInfo(node.arguments, context); + const reportInfo = utils.getReportInfo(node, context); const message = reportInfo && reportInfo.message; const suggest = reportInfo && reportInfo.suggest; diff --git a/lib/utils.js b/lib/utils.js index 19f6b7fd..cf084037 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -579,11 +579,13 @@ module.exports = { }, /** - * Gets information on a report, given the arguments passed to context.report(). - * @param {ASTNode[]} reportArgs The arguments passed to context.report() + * Gets information on a report, given the ASTNode of context.report(). + * @param {ASTNode} reportArgs The ASTNode of context.report() * @param {Context} context */ - getReportInfo(reportArgs, context) { + getReportInfo(node, context) { + const reportArgs = node.arguments + // If there is exactly one argument, the API expects an object. // Otherwise, if the second argument is a string, the arguments are interpreted as // ['node', 'message', 'data', 'fix']. @@ -736,7 +738,7 @@ module.exports = { parent.parent.parent.type === 'CallExpression' && contextIdentifiers.has(parent.parent.parent.callee.object) && parent.parent.parent.callee.property.name === 'report' && - module.exports.getReportInfo(parent.parent.parent.arguments).fix === node + module.exports.getReportInfo(parent.parent.parent).fix === node ); }, @@ -767,7 +769,7 @@ module.exports = { parent.parent.parent.parent.parent.parent.callee.property.name === 'report' && module.exports.getReportInfo( - parent.parent.parent.parent.parent.parent.arguments + parent.parent.parent.parent.parent.parent ).suggest === parent.parent.parent ); }, diff --git a/tests/lib/utils.js b/tests/lib/utils.js index ebebacca..985ed8b2 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -1094,13 +1094,14 @@ describe('utils', () => { for (const args of CASES.keys()) { it(args.join(', '), () => { - const parsedArgs = espree.parse(`context.report(${args.join(', ')})`, { + const node = espree.parse(`context.report(${args.join(', ')})`, { ecmaVersion: 6, loc: false, range: false, - }).body[0].expression.arguments; + }).body[0].expression; + const parsedArgs = node.arguments const context = { getScope() {} }; // mock object - const reportInfo = utils.getReportInfo(parsedArgs, context); + const reportInfo = utils.getReportInfo(node, context); assert.deepEqual(reportInfo, CASES.get(args)(parsedArgs)); }); @@ -1274,7 +1275,7 @@ describe('utils', () => { }); const context = { getScope() {} }; // mock object const reportNode = ast.body[0].expression; - const reportInfo = utils.getReportInfo(reportNode.arguments, context); + const reportInfo = utils.getReportInfo(reportNode, context); const data = utils.collectReportViolationAndSuggestionData(reportInfo); assert( lodash.isMatch(data, testCase.shouldMatch), From 7c3103a443f8faae7c620bb31ba602e8cb9de14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 14:50:16 +0800 Subject: [PATCH 02/12] fix: use sourceCode.getScope() if available --- lib/utils.js | 2 +- tests/lib/utils.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index cf084037..2573b077 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -613,7 +613,7 @@ module.exports = { const secondArgStaticValue = getStaticValue( reportArgs[1], - context.getScope() + (context.sourceCode || context.getSourceCode()).getScope?.(node) || context.getScope() // TODO: just use sourceCode.getScope() when dropping eslint < v9 ); if ( (secondArgStaticValue && diff --git a/tests/lib/utils.js b/tests/lib/utils.js index 985ed8b2..e60b0be8 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -1100,7 +1100,7 @@ describe('utils', () => { range: false, }).body[0].expression; const parsedArgs = node.arguments - const context = { getScope() {} }; // mock object + const context = { sourceCode: { getScope() { return {} } } }; // mock object const reportInfo = utils.getReportInfo(node, context); assert.deepEqual(reportInfo, CASES.get(args)(parsedArgs)); @@ -1273,7 +1273,7 @@ describe('utils', () => { ecmaVersion: 6, range: true, }); - const context = { getScope() {} }; // mock object + const context = { sourceCode: { getScope() { return {} } } }; // mock object const reportNode = ast.body[0].expression; const reportInfo = utils.getReportInfo(reportNode, context); const data = utils.collectReportViolationAndSuggestionData(reportInfo); From d9dd64d573a5010865e07fdd1526f3533b59190e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 14:53:21 +0800 Subject: [PATCH 03/12] fix: use `context.sourceCode` if available --- lib/rules/fixer-return.js | 2 +- 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 | 2 +- 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 +- 25 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/rules/fixer-return.js b/lib/rules/fixer-return.js index 05e6867f..86333e99 100644 --- a/lib/rules/fixer-return.js +++ b/lib/rules/fixer-return.js @@ -98,7 +98,7 @@ module.exports = { return { Program(ast) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); contextIdentifiers = utils.getContextIdentifiers( sourceCode.scopeManager, ast diff --git a/lib/rules/meta-property-ordering.js b/lib/rules/meta-property-ordering.js index 8c19c12e..e4480411 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 97ced0e5..a1772d26 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // ---------------------------------------------------------------------- // Public diff --git a/lib/rules/no-deprecated-report-api.js b/lib/rules/no-deprecated-report-api.js index cc862a12..4ad45d96 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); let contextIdentifiers; // ---------------------------------------------------------------------- diff --git a/lib/rules/no-identical-tests.js b/lib/rules/no-identical-tests.js index d8679c5a..5a1c0573 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // ---------------------------------------------------------------------- // Helpers diff --git a/lib/rules/no-missing-message-ids.js b/lib/rules/no-missing-message-ids.js index 10c6c461..2cd07c43 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 9033c349..f3bc33a2 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); const { scopeManager } = sourceCode; let contextIdentifiers; diff --git a/lib/rules/no-only-tests.js b/lib/rules/no-only-tests.js index 49206f61..4387dbda 100644 --- a/lib/rules/no-only-tests.js +++ b/lib/rules/no-only-tests.js @@ -51,7 +51,7 @@ module.exports = { { messageId: 'removeOnly', *fix(fixer) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); const tokenBefore = sourceCode.getTokenBefore(onlyProperty); diff --git a/lib/rules/no-unused-message-ids.js b/lib/rules/no-unused-message-ids.js index 240db5d3..67dc440d 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 f41ca997..5dde331a 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); const { scopeManager } = sourceCode; let contextIdentifiers; diff --git a/lib/rules/no-useless-token-range.js b/lib/rules/no-useless-token-range.js index e62d7316..f3adb197 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // ---------------------------------------------------------------------- // Helpers diff --git a/lib/rules/prefer-message-ids.js b/lib/rules/prefer-message-ids.js index a708ff5d..101fe053 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 46bc4ceb..5aa0942d 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 4403b7e8..df2f4240 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); return { Program(ast) { diff --git a/lib/rules/prefer-placeholders.js b/lib/rules/prefer-placeholders.js index fbd29d67..7f8bc122 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); const { scopeManager } = sourceCode; // ---------------------------------------------------------------------- diff --git a/lib/rules/prefer-replace-text.js b/lib/rules/prefer-replace-text.js index c83beeaa..615b3d33 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); let funcInfo = { upper: null, codePath: null, diff --git a/lib/rules/report-message-format.js b/lib/rules/report-message-format.js index 36f1bdd4..0cf7be41 100644 --- a/lib/rules/report-message-format.js +++ b/lib/rules/report-message-format.js @@ -57,7 +57,7 @@ module.exports = { } } - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 85a374e8..51a50837 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 862e6dde..07caa554 100644 --- a/lib/rules/require-meta-docs-url.js +++ b/lib/rules/require-meta-docs-url.js @@ -76,7 +76,7 @@ module.exports = { ); } - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 be3edf19..84b14788 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 0a8f5282..143b6ec0 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 26a1cef9..5c61531d 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 9a56066b..125e695d 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); 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 66aa1b57..099232fb 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); return { Program(ast) { diff --git a/lib/rules/test-case-shorthand-strings.js b/lib/rules/test-case-shorthand-strings.js index 5decd6c6..0594d4cc 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.getSourceCode(); + const sourceCode = context.sourceCode || context.getSourceCode(); // ---------------------------------------------------------------------- // Helpers From 33a3ad53172a0947751d633601992cbaa0d924d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 15:16:28 +0800 Subject: [PATCH 04/12] fix: use sourceCode.getScope() when available --- lib/rules/fixer-return.js | 6 ++++-- lib/rules/no-missing-message-ids.js | 2 +- lib/rules/no-missing-placeholders.js | 8 +++----- lib/rules/no-only-tests.js | 3 ++- lib/rules/no-unused-message-ids.js | 9 +++++---- lib/rules/no-unused-placeholders.js | 4 ++-- lib/rules/prefer-message-ids.js | 6 ++---- lib/rules/report-message-format.js | 12 +++++++----- lib/rules/require-meta-docs-description.js | 8 +++----- lib/rules/require-meta-docs-url.js | 5 +++-- lib/rules/require-meta-fixable.js | 8 +++----- lib/rules/require-meta-has-suggestions.js | 3 ++- lib/rules/require-meta-type.js | 5 +++-- lib/utils.js | 15 +++++++-------- 14 files changed, 47 insertions(+), 47 deletions(-) diff --git a/lib/rules/fixer-return.js b/lib/rules/fixer-return.js index 86333e99..78294bd2 100644 --- a/lib/rules/fixer-return.js +++ b/lib/rules/fixer-return.js @@ -80,8 +80,10 @@ module.exports = { // An empty array is not a fix. return false; } - - const staticValue = getStaticValue(node, context.getScope()); + 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 staticValue = getStaticValue(node, scope); if (!staticValue) { // If we can't find a static value, assume it's a real fix value. return true; diff --git a/lib/rules/no-missing-message-ids.js b/lib/rules/no-missing-message-ids.js index 2cd07c43..d90803fb 100644 --- a/lib/rules/no-missing-message-ids.js +++ b/lib/rules/no-missing-message-ids.js @@ -80,7 +80,7 @@ module.exports = { val.value, ruleInfo, scopeManager, - context.getScope() + sourceCode.getScope(node) ) ) // Couldn't find this messageId in `meta.messages`. diff --git a/lib/rules/no-missing-placeholders.js b/lib/rules/no-missing-placeholders.js index f3bc33a2..30f70cb7 100644 --- a/lib/rules/no-missing-placeholders.js +++ b/lib/rules/no-missing-placeholders.js @@ -48,6 +48,7 @@ module.exports = { contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast); }, CallExpression(node) { + const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0 if ( node.callee.type === 'MemberExpression' && contextIdentifiers.has(node.callee.object) && @@ -75,7 +76,7 @@ module.exports = { obj.messageId.value, ruleInfo, scopeManager, - context.getScope() + scope ); if (correspondingMessage) { obj.message = correspondingMessage.value; @@ -89,10 +90,7 @@ module.exports = { messageId, data, } of reportMessagesAndDataArray.filter((obj) => obj.message)) { - const messageStaticValue = getStaticValue( - message, - context.getScope() - ); + const messageStaticValue = getStaticValue(message, scope); if ( ((message.type === 'Literal' && typeof message.value === 'string') || diff --git a/lib/rules/no-only-tests.js b/lib/rules/no-only-tests.js index 4387dbda..264ac78e 100644 --- a/lib/rules/no-only-tests.js +++ b/lib/rules/no-only-tests.js @@ -51,7 +51,8 @@ module.exports = { { messageId: 'removeOnly', *fix(fixer) { - const sourceCode = context.sourceCode || context.getSourceCode(); + const sourceCode = + context.sourceCode || context.getSourceCode(); const tokenBefore = sourceCode.getTokenBefore(onlyProperty); diff --git a/lib/rules/no-unused-message-ids.js b/lib/rules/no-unused-message-ids.js index 67dc440d..6c81af51 100644 --- a/lib/rules/no-unused-message-ids.js +++ b/lib/rules/no-unused-message-ids.js @@ -47,7 +47,7 @@ module.exports = { contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast); }, - 'Program:exit'() { + 'Program:exit'(ast) { if (hasSeenUnknownMessageId || !hasSeenViolationReport) { /* Bail out when the rule is likely to have false positives. @@ -57,9 +57,10 @@ module.exports = { return; } + const scope = sourceCode.getScope(ast); + const messageIdNodesUnused = messageIdNodes.filter( - (node) => - !messageIdsUsed.has(utils.getKeyName(node, context.getScope())) + (node) => !messageIdsUsed.has(utils.getKeyName(node, scope)) ); // Report any messageIds that were never used. @@ -68,7 +69,7 @@ module.exports = { node: messageIdNode, messageId: 'unusedMessage', data: { - messageId: utils.getKeyName(messageIdNode, context.getScope()), + messageId: utils.getKeyName(messageIdNode, scope), }, }); } diff --git a/lib/rules/no-unused-placeholders.js b/lib/rules/no-unused-placeholders.js index 5dde331a..27e91cf1 100644 --- a/lib/rules/no-unused-placeholders.js +++ b/lib/rules/no-unused-placeholders.js @@ -74,7 +74,7 @@ module.exports = { obj.messageId.value, ruleInfo, scopeManager, - context.getScope() + sourceCode.getScope(node) ); if (correspondingMessage) { obj.message = correspondingMessage.value; @@ -88,7 +88,7 @@ module.exports = { )) { const messageStaticValue = getStaticValue( message, - context.getScope() + sourceCode.getScope(node) ); if ( ((message.type === 'Literal' && diff --git a/lib/rules/prefer-message-ids.js b/lib/rules/prefer-message-ids.js index 101fe053..65abada5 100644 --- a/lib/rules/prefer-message-ids.js +++ b/lib/rules/prefer-message-ids.js @@ -43,6 +43,7 @@ module.exports = { return { Program(ast) { + const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 contextIdentifiers = utils.getContextIdentifiers( sourceCode.scopeManager, ast @@ -64,10 +65,7 @@ module.exports = { return; } - const staticValue = getStaticValue( - messagesNode.value, - context.getScope() - ); + const staticValue = getStaticValue(messagesNode.value, scope); if (!staticValue) { return; } diff --git a/lib/rules/report-message-format.js b/lib/rules/report-message-format.js index 0cf7be41..244fa727 100644 --- a/lib/rules/report-message-format.js +++ b/lib/rules/report-message-format.js @@ -38,8 +38,8 @@ module.exports = { * @param {ASTNode} message The message AST node * @returns {void} */ - function processMessageNode(message) { - const staticValue = getStaticValue(message, context.getScope()); + function processMessageNode(message, scope) { + const staticValue = getStaticValue(message, scope); if ( (message.type === 'Literal' && typeof message.value === 'string' && @@ -69,6 +69,7 @@ module.exports = { return { Program(ast) { + const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 contextIdentifiers = utils.getContextIdentifiers( sourceCode.scopeManager, ast @@ -93,9 +94,10 @@ module.exports = { messagesObject.value.properties .filter((prop) => prop.type === 'Property') .map((prop) => prop.value) - .forEach(processMessageNode); + .forEach((it) => processMessageNode(it, scope)); }, CallExpression(node) { + const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 if ( node.callee.type === 'MemberExpression' && contextIdentifiers.has(node.callee.object) && @@ -107,7 +109,7 @@ module.exports = { const suggest = reportInfo && reportInfo.suggest; if (message) { - processMessageNode(message); + processMessageNode(message, scope); } if (suggest && suggest.type === 'ArrayExpression') { @@ -122,7 +124,7 @@ module.exports = { prop.key.name === 'message' ) .map((prop) => prop.value) - .forEach(processMessageNode); + .forEach((it) => processMessageNode(it, scope)); } } }, diff --git a/lib/rules/require-meta-docs-description.js b/lib/rules/require-meta-docs-description.js index 51a50837..756333b3 100644 --- a/lib/rules/require-meta-docs-description.js +++ b/lib/rules/require-meta-docs-description.js @@ -52,7 +52,8 @@ module.exports = { } return { - Program() { + Program(ast) { + const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const { scopeManager } = sourceCode; const pattern = @@ -80,10 +81,7 @@ module.exports = { return; } - const staticValue = getStaticValue( - descriptionNode.value, - context.getScope() - ); + const staticValue = getStaticValue(descriptionNode.value, scope); if (!staticValue) { // Ignore non-static values since we can't determine what they look like. return; diff --git a/lib/rules/require-meta-docs-url.js b/lib/rules/require-meta-docs-url.js index 07caa554..7933319f 100644 --- a/lib/rules/require-meta-docs-url.js +++ b/lib/rules/require-meta-docs-url.js @@ -83,7 +83,8 @@ module.exports = { } return { - Program() { + Program(ast) { + const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const { scopeManager } = sourceCode; const metaNode = ruleInfo.meta; @@ -98,7 +99,7 @@ module.exports = { .find((p) => p.type === 'Property' && util.getKeyName(p) === 'url'); const staticValue = urlPropNode - ? getStaticValue(urlPropNode.value, context.getScope()) + ? getStaticValue(urlPropNode.value, scope) : undefined; if (urlPropNode && !staticValue) { // Ignore non-static values since we can't determine what they look like. diff --git a/lib/rules/require-meta-fixable.js b/lib/rules/require-meta-fixable.js index 84b14788..2181e88c 100644 --- a/lib/rules/require-meta-fixable.js +++ b/lib/rules/require-meta-fixable.js @@ -78,7 +78,8 @@ module.exports = { usesFixFunctions = true; } }, - 'Program:exit'() { + 'Program:exit'(ast) { + const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const metaFixableProp = ruleInfo && utils @@ -86,10 +87,7 @@ module.exports = { .find((prop) => utils.getKeyName(prop) === 'fixable'); if (metaFixableProp) { - const staticValue = getStaticValue( - metaFixableProp.value, - context.getScope() - ); + const staticValue = getStaticValue(metaFixableProp.value, scope); if (!staticValue) { // Ignore non-static values since we can't determine what they look like. return; diff --git a/lib/rules/require-meta-has-suggestions.js b/lib/rules/require-meta-has-suggestions.js index 143b6ec0..0946886b 100644 --- a/lib/rules/require-meta-has-suggestions.js +++ b/lib/rules/require-meta-has-suggestions.js @@ -44,7 +44,8 @@ module.exports = { * @returns {boolean} whether this property should be considered to contain suggestions */ function doesPropertyContainSuggestions(node) { - const staticValue = getStaticValue(node.value, context.getScope()); + const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const staticValue = getStaticValue(node.value, scope); if ( !staticValue || (Array.isArray(staticValue.value) && staticValue.value.length > 0) || diff --git a/lib/rules/require-meta-type.js b/lib/rules/require-meta-type.js index 125e695d..4c515452 100644 --- a/lib/rules/require-meta-type.js +++ b/lib/rules/require-meta-type.js @@ -45,7 +45,8 @@ module.exports = { } return { - Program() { + Program(node) { + const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const { scopeManager } = sourceCode; const metaNode = ruleInfo.meta; @@ -61,7 +62,7 @@ module.exports = { return; } - const staticValue = getStaticValue(typeNode.value, context.getScope()); + const staticValue = getStaticValue(typeNode.value, scope); if (!staticValue) { // Ignore non-static values since we can't determine what they look like. return; diff --git a/lib/utils.js b/lib/utils.js index 2573b077..e33eda20 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -584,7 +584,7 @@ module.exports = { * @param {Context} context */ getReportInfo(node, context) { - const reportArgs = node.arguments + const reportArgs = node.arguments; // If there is exactly one argument, the API expects an object. // Otherwise, if the second argument is a string, the arguments are interpreted as @@ -610,11 +610,11 @@ module.exports = { } let keys; + const scope = + (context.sourceCode || context.getSourceCode()).getScope?.(node) || + context.getScope(); // TODO: just use sourceCode.getScope() when dropping eslint < v9 + const secondArgStaticValue = getStaticValue(reportArgs[1], scope); - const secondArgStaticValue = getStaticValue( - reportArgs[1], - (context.sourceCode || context.getSourceCode()).getScope?.(node) || context.getScope() // TODO: just use sourceCode.getScope() when dropping eslint < v9 - ); if ( (secondArgStaticValue && typeof secondArgStaticValue.value === 'string') || @@ -768,9 +768,8 @@ module.exports = { ) && parent.parent.parent.parent.parent.parent.callee.property.name === 'report' && - module.exports.getReportInfo( - parent.parent.parent.parent.parent.parent - ).suggest === parent.parent.parent + module.exports.getReportInfo(parent.parent.parent.parent.parent.parent) + .suggest === parent.parent.parent ); }, From b5c3d7d3c72dd1987c021fa43b0a36a84e2ea981 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 15:40:02 +0800 Subject: [PATCH 05/12] chore: add nyc config it set the coverage threshold to 95% for branches, 99% for lines. --- .nycrc | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .nycrc diff --git a/.nycrc b/.nycrc new file mode 100644 index 00000000..92813ab0 --- /dev/null +++ b/.nycrc @@ -0,0 +1,6 @@ +{ + "branches": 95, + "lines": 99, + "functions": 99, + "statements": 99 +} From 458b751d6db97c2303c60e171e398cbf90743176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 15:44:37 +0800 Subject: [PATCH 06/12] chore: apply prettier -w --- tests/lib/utils.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/lib/utils.js b/tests/lib/utils.js index e60b0be8..ae8dd427 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -1099,8 +1099,14 @@ describe('utils', () => { loc: false, range: false, }).body[0].expression; - const parsedArgs = node.arguments - const context = { sourceCode: { getScope() { return {} } } }; // mock object + const parsedArgs = node.arguments; + const context = { + sourceCode: { + getScope() { + return {}; + }, + }, + }; // mock object const reportInfo = utils.getReportInfo(node, context); assert.deepEqual(reportInfo, CASES.get(args)(parsedArgs)); @@ -1273,7 +1279,13 @@ describe('utils', () => { ecmaVersion: 6, range: true, }); - const context = { sourceCode: { getScope() { return {} } } }; // mock object + const context = { + sourceCode: { + getScope() { + return {}; + }, + }, + }; // mock object const reportNode = ast.body[0].expression; const reportInfo = utils.getReportInfo(reportNode, context); const data = utils.collectReportViolationAndSuggestionData(reportInfo); From 5b85dc46e08441fdbafba5fb741a3bb66c91f80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 15:50:04 +0800 Subject: [PATCH 07/12] fix: sourceCode.getScope?.() --- lib/rules/fixer-return.js | 2 +- lib/rules/no-missing-message-ids.js | 3 ++- lib/rules/no-missing-placeholders.js | 2 +- lib/rules/no-unused-message-ids.js | 2 +- lib/rules/no-unused-placeholders.js | 8 +++----- lib/rules/prefer-message-ids.js | 2 +- lib/rules/report-message-format.js | 4 ++-- lib/rules/require-meta-docs-description.js | 2 +- lib/rules/require-meta-docs-url.js | 2 +- lib/rules/require-meta-fixable.js | 2 +- lib/rules/require-meta-has-suggestions.js | 2 +- lib/rules/require-meta-type.js | 2 +- 12 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/rules/fixer-return.js b/lib/rules/fixer-return.js index 78294bd2..fa14b905 100644 --- a/lib/rules/fixer-return.js +++ b/lib/rules/fixer-return.js @@ -81,7 +81,7 @@ module.exports = { return false; } const scope = - (context.sourceCode || context.getSourceCode())?.getScope(node) || + (context.sourceCode || context.getSourceCode()).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) { diff --git a/lib/rules/no-missing-message-ids.js b/lib/rules/no-missing-message-ids.js index d90803fb..a4528d5d 100644 --- a/lib/rules/no-missing-message-ids.js +++ b/lib/rules/no-missing-message-ids.js @@ -48,6 +48,7 @@ module.exports = { }, CallExpression(node) { + const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0 // Check for messageId properties used in known calls to context.report(); if ( node.callee.type === 'MemberExpression' && @@ -80,7 +81,7 @@ module.exports = { val.value, ruleInfo, scopeManager, - sourceCode.getScope(node) + scope ) ) // Couldn't find this messageId in `meta.messages`. diff --git a/lib/rules/no-missing-placeholders.js b/lib/rules/no-missing-placeholders.js index 30f70cb7..893700a6 100644 --- a/lib/rules/no-missing-placeholders.js +++ b/lib/rules/no-missing-placeholders.js @@ -48,7 +48,7 @@ module.exports = { contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast); }, CallExpression(node) { - const scope = sourceCode.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 if ( node.callee.type === 'MemberExpression' && contextIdentifiers.has(node.callee.object) && diff --git a/lib/rules/no-unused-message-ids.js b/lib/rules/no-unused-message-ids.js index 6c81af51..7eded242 100644 --- a/lib/rules/no-unused-message-ids.js +++ b/lib/rules/no-unused-message-ids.js @@ -57,7 +57,7 @@ module.exports = { return; } - const scope = sourceCode.getScope(ast); + const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0 const messageIdNodesUnused = messageIdNodes.filter( (node) => !messageIdsUsed.has(utils.getKeyName(node, scope)) diff --git a/lib/rules/no-unused-placeholders.js b/lib/rules/no-unused-placeholders.js index 27e91cf1..9dcd9d4d 100644 --- a/lib/rules/no-unused-placeholders.js +++ b/lib/rules/no-unused-placeholders.js @@ -47,6 +47,7 @@ module.exports = { contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast); }, CallExpression(node) { + const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < 9.0.0 if ( node.callee.type === 'MemberExpression' && contextIdentifiers.has(node.callee.object) && @@ -74,7 +75,7 @@ module.exports = { obj.messageId.value, ruleInfo, scopeManager, - sourceCode.getScope(node) + scope ); if (correspondingMessage) { obj.message = correspondingMessage.value; @@ -86,10 +87,7 @@ module.exports = { for (const { message, data } of reportMessagesAndDataArray.filter( (obj) => obj.message )) { - const messageStaticValue = getStaticValue( - message, - sourceCode.getScope(node) - ); + const messageStaticValue = getStaticValue(message, scope); if ( ((message.type === 'Literal' && typeof message.value === 'string') || diff --git a/lib/rules/prefer-message-ids.js b/lib/rules/prefer-message-ids.js index 65abada5..88cf2c1b 100644 --- a/lib/rules/prefer-message-ids.js +++ b/lib/rules/prefer-message-ids.js @@ -43,7 +43,7 @@ module.exports = { return { Program(ast) { - const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 contextIdentifiers = utils.getContextIdentifiers( sourceCode.scopeManager, ast diff --git a/lib/rules/report-message-format.js b/lib/rules/report-message-format.js index 244fa727..15da50ce 100644 --- a/lib/rules/report-message-format.js +++ b/lib/rules/report-message-format.js @@ -69,7 +69,7 @@ module.exports = { return { Program(ast) { - const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 contextIdentifiers = utils.getContextIdentifiers( sourceCode.scopeManager, ast @@ -97,7 +97,7 @@ module.exports = { .forEach((it) => processMessageNode(it, scope)); }, CallExpression(node) { - const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 if ( node.callee.type === 'MemberExpression' && contextIdentifiers.has(node.callee.object) && diff --git a/lib/rules/require-meta-docs-description.js b/lib/rules/require-meta-docs-description.js index 756333b3..b724f5bf 100644 --- a/lib/rules/require-meta-docs-description.js +++ b/lib/rules/require-meta-docs-description.js @@ -53,7 +53,7 @@ module.exports = { return { Program(ast) { - const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const { scopeManager } = sourceCode; const pattern = diff --git a/lib/rules/require-meta-docs-url.js b/lib/rules/require-meta-docs-url.js index 7933319f..79bd6a34 100644 --- a/lib/rules/require-meta-docs-url.js +++ b/lib/rules/require-meta-docs-url.js @@ -84,7 +84,7 @@ module.exports = { return { Program(ast) { - const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const { scopeManager } = sourceCode; const metaNode = ruleInfo.meta; diff --git a/lib/rules/require-meta-fixable.js b/lib/rules/require-meta-fixable.js index 2181e88c..1375a1a9 100644 --- a/lib/rules/require-meta-fixable.js +++ b/lib/rules/require-meta-fixable.js @@ -79,7 +79,7 @@ module.exports = { } }, 'Program:exit'(ast) { - const scope = sourceCode.getScope(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const scope = sourceCode.getScope?.(ast) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const metaFixableProp = ruleInfo && utils diff --git a/lib/rules/require-meta-has-suggestions.js b/lib/rules/require-meta-has-suggestions.js index 0946886b..0a5014e3 100644 --- a/lib/rules/require-meta-has-suggestions.js +++ b/lib/rules/require-meta-has-suggestions.js @@ -44,7 +44,7 @@ module.exports = { * @returns {boolean} whether this property should be considered to contain suggestions */ function doesPropertyContainSuggestions(node) { - const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const staticValue = getStaticValue(node.value, scope); if ( !staticValue || diff --git a/lib/rules/require-meta-type.js b/lib/rules/require-meta-type.js index 4c515452..25bd58a3 100644 --- a/lib/rules/require-meta-type.js +++ b/lib/rules/require-meta-type.js @@ -46,7 +46,7 @@ module.exports = { return { Program(node) { - const scope = sourceCode.getScope(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 + const scope = sourceCode.getScope?.(node) || context.getScope(); // TODO: just use sourceCode.getScope() when we drop support for ESLint < v9.0.0 const { scopeManager } = sourceCode; const metaNode = ruleInfo.meta; From e4759a7c3f4bed615aefc0c0e1348ad4d143059e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 8 Dec 2023 17:09:57 +0800 Subject: [PATCH 08/12] fix: other apis for eslint v9 --- lib/rules/require-meta-docs-url.js | 2 +- lib/utils.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/rules/require-meta-docs-url.js b/lib/rules/require-meta-docs-url.js index 79bd6a34..4f62556b 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.getFilename(); + const filename = context.filename || context.getFilename(); const ruleName = filename === '' ? undefined diff --git a/lib/utils.js b/lib/utils.js index e33eda20..e9142b92 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -467,7 +467,9 @@ module.exports = { isRuleTesterConstruction(declarator.init) && declarator.id.type === 'Identifier' ) { - context.getDeclaredVariables(declarator).forEach((variable) => { + (sourceCode.getDeclaredVariables || context.getDeclaredVariables)( + declarator + ).forEach((variable) => { variable.references .filter((ref) => ref.isRead()) .forEach((ref) => variableIdentifiers.add(ref.identifier)); 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 09/12] 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 ( From 0faa4e6cf7738b7aef8df4eccbcc14163c8c7d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Sun, 10 Dec 2023 04:42:46 +0800 Subject: [PATCH 10/12] test: mock context --- .nycrc | 2 +- lib/utils.js | 7 ++++--- tests/lib/utils.js | 24 +++++++++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.nycrc b/.nycrc index 92813ab0..8c611b4a 100644 --- a/.nycrc +++ b/.nycrc @@ -1,5 +1,5 @@ { - "branches": 95, + "branches": 94, "lines": 99, "functions": 99, "statements": 99 diff --git a/lib/utils.js b/lib/utils.js index 219a04c6..3bf809af 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -468,9 +468,10 @@ module.exports = { isRuleTesterConstruction(declarator.init) && declarator.id.type === 'Identifier' ) { - (sourceCode.getDeclaredVariables || context.getDeclaredVariables)( - declarator - ).forEach((variable) => { + const vars = sourceCode.getDeclaredVariables + ? sourceCode.getDeclaredVariables(declarator) + : context.getDeclaredVariables(declarator); + vars.forEach((variable) => { variable.references .filter((ref) => ref.isRead()) .forEach((ref) => variableIdentifiers.add(ref.identifier)); diff --git a/tests/lib/utils.js b/tests/lib/utils.js index ae8dd427..fe771824 100644 --- a/tests/lib/utils.js +++ b/tests/lib/utils.js @@ -761,8 +761,14 @@ describe('utils', () => { sourceType: 'script', nodejsScope: true, }); + const context = { + sourceCode: { + getDeclaredVariables: + scopeManager.getDeclaredVariables.bind(scopeManager), + }, + }; // mock object assert.deepEqual( - utils.getTestInfo(scopeManager, ast), + utils.getTestInfo(context, ast), [], 'Expected no tests to be found' ); @@ -827,7 +833,13 @@ describe('utils', () => { sourceType: 'script', nodejsScope: true, }); - const testInfo = utils.getTestInfo(scopeManager, ast); + const context = { + sourceCode: { + getDeclaredVariables: + scopeManager.getDeclaredVariables.bind(scopeManager), + }, + }; // mock object + const testInfo = utils.getTestInfo(context, ast); assert.strictEqual( testInfo.length, @@ -1021,7 +1033,13 @@ describe('utils', () => { sourceType: 'script', nodejsScope: true, }); - const testInfo = utils.getTestInfo(scopeManager, ast); + const context = { + sourceCode: { + getDeclaredVariables: + scopeManager.getDeclaredVariables.bind(scopeManager), + }, + }; // mock object + const testInfo = utils.getTestInfo(context, ast); assert.strictEqual( testInfo.length, From bfaf2d9b643b365a1f2250ea7e67636788454dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 11 Dec 2023 10:09:22 +0800 Subject: [PATCH 11/12] fix: update nyc config to match coverage --- .nycrc | 6 ------ package.json | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 .nycrc diff --git a/.nycrc b/.nycrc deleted file mode 100644 index 8c611b4a..00000000 --- a/.nycrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "branches": 94, - "lines": 99, - "functions": 99, - "statements": 99 -} diff --git a/package.json b/package.json index 08133907..1ec72bb2 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "estraverse": "^5.3.0" }, "nyc": { - "branches": 99, + "branches": 94, "functions": 99, "lines": 99, "statements": 99 From 3f0edbcbe7d0f58bb3ed1394d5507e3c27e3cdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 11 Dec 2023 10:11:26 +0800 Subject: [PATCH 12/12] chore: update jsdoc --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 3bf809af..4ad42c24 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -584,7 +584,7 @@ module.exports = { /** * Gets information on a report, given the ASTNode of context.report(). - * @param {ASTNode} reportArgs The ASTNode of context.report() + * @param {ASTNode} node The ASTNode of context.report() * @param {Context} context */ getReportInfo(node, context) {