diff --git a/scripts/tools/eslint-plugin-prettier-internal-rules/no-identifier-n.js b/scripts/tools/eslint-plugin-prettier-internal-rules/no-identifier-n.js index e10c64481..2b2ad7c10 100644 --- a/scripts/tools/eslint-plugin-prettier-internal-rules/no-identifier-n.js +++ b/scripts/tools/eslint-plugin-prettier-internal-rules/no-identifier-n.js @@ -30,7 +30,7 @@ module.exports = { const variables = new Map(); return { [selector](node) { - const scope = context.getScope(); + const scope = context.sourceCode.getScope(node); const variable = findVariable(scope, node); /* istanbul ignore next */ diff --git a/scripts/tools/eslint-plugin-prettier-internal-rules/test.js b/scripts/tools/eslint-plugin-prettier-internal-rules/test.js index 369430c75..9c4ef375a 100644 --- a/scripts/tools/eslint-plugin-prettier-internal-rules/test.js +++ b/scripts/tools/eslint-plugin-prettier-internal-rules/test.js @@ -7,11 +7,7 @@ const { RuleTester } = require("eslint"); const { rules } = require("./index.js"); const test = (ruleId, tests) => { - new RuleTester({ parserOptions: { ecmaVersion: 2021 } }).run( - ruleId, - rules[ruleId], - tests, - ); + new RuleTester().run(ruleId, rules[ruleId], tests); }; test("await-cli-tests", { @@ -74,7 +70,9 @@ test("better-parent-property-check-in-needs-parens", { ].map((testCase) => ({ ...testCase, code: `function needsParens() {${testCase.code}}`, - output: `function needsParens() {${testCase.output || testCase.code}}`, + output: testCase.output + ? `function needsParens() {${testCase.output}}` + : null, filename: "needs-parens.js", })), }); @@ -236,19 +234,13 @@ test("no-identifier-n", { alert(n) } `, - output: outdent` - const n = 1; - function a(node) { - alert(n, node) - } - function b() { - alert(n) - } - `, + output: null, errors: [ { + messageId: "error", suggestions: [ { + messageId: "suggestion", output: outdent` const node = 1; function a(node) { @@ -263,11 +255,22 @@ test("no-identifier-n", { }, ], }, - { - code: "const n = 1;const node = 2;", - output: "const n = 1;const node = 2;", - errors: [{ suggestions: [{ output: "const node = 1;const node = 2;" }] }], - }, + // ESLint 8 doesn't allow suggest invalid code + // { + // code: "const n = 1;const node = 2;", + // output: null, + // errors: [ + // { + // messageId: "error", + // suggestions: [ + // { + // messageId: "suggestion", + // output: "const node = 1;const node = 2;", + // }, + // ], + // }, + // ], + // }, ], }); @@ -275,7 +278,7 @@ test("no-legacy-format-test", { valid: [ "runFormatTest(import.meta, ['babel'])", "runFormatTest({importMeta: import.meta}, ['babel'])", - ].map((code) => ({ code, parserOptions: { sourceType: "module" } })), + ], invalid: [ { code: "run_spec(import.meta, ['babel'])", @@ -298,7 +301,7 @@ test("no-legacy-format-test", { output: "runFormatTest({snippets: ['x'], importMeta: import.meta}, ['babel'])", }, - ].map((test) => ({ ...test, parserOptions: { sourceType: "module" } })), + ], }); test("no-node-comments", { @@ -322,12 +325,12 @@ test("no-node-comments", { "const {comments: nodeComments} = node", ].map((code) => ({ code, - output: code, + output: null, errors: [{ message: "Do not access node.comments." }], })), { code: "function notFunctionName() {return node.comments;}", - output: "function notFunctionName() {return node.comments;}", + output: null, filename: path.join(__dirname, "../../..", "a.js"), options: [{ file: "a.js", functions: ["functionName"] }], errors: [{ message: "Do not access node.comments." }], @@ -557,10 +560,7 @@ test("prefer-create-type-check-function", { const foo = node => node.type === "Identifier" || /* comment */ node.type === "FunctionExpression"; `, - output: outdent` - const foo = node => - node.type === "Identifier" || /* comment */ node.type === "FunctionExpression"; - `, + output: null, errors: 1, }, { @@ -573,10 +573,7 @@ test("prefer-create-type-check-function", { 'const isClassProperty = createTypeCheckFunction(["ClassProperty", "PropertyDefinition"]);', errors: 1, }, - ].map((testCase) => ({ - ...testCase, - parserOptions: { sourceType: "module" }, - })), + ], }); test("prefer-indent-if-break", { @@ -708,7 +705,7 @@ test("no-unnecessary-ast-path-call", { }, { code: "foo.call(() => bar)", - output: "foo.call(() => bar)", + output: null, errors: 1, }, ], @@ -720,7 +717,7 @@ test("prefer-fs-promises-submodule", { "import fs from 'node:fs/promises';", "import fs, { promises as fsPromises } from 'node:fs';", "import { promises as fs, statSync } from 'node:fs';", - ].map((code) => ({ code, parserOptions: { sourceType: "module" } })), + ], invalid: [ { code: "import { promises as fsPromises } from 'node:fs';", @@ -730,10 +727,7 @@ test("prefer-fs-promises-submodule", { code: "import { promises as fs } from 'node:fs';", errors: 1, }, - ].map((testCase) => ({ - ...testCase, - parserOptions: { sourceType: "module" }, - })), + ], }); test("prefer-ast-path-getters", { @@ -828,24 +822,6 @@ test("prefer-ast-path-getters", { }, ], }, - { - code: "path.getParentNode()", - output: "path.parent", - errors: [ - { - message: "Prefer `AstPath#parent` over `AstPath#getParentNode()`.", - }, - ], - }, - { - code: "const node = path.getParentNode()", - output: "const node = path.parent", - errors: [ - { - message: "Prefer `AstPath#parent` over `AstPath#getParentNode()`.", - }, - ], - }, { code: "fooPath.getParentNode()", output: "fooPath.parent", @@ -875,24 +851,6 @@ test("prefer-ast-path-getters", { }, ], }, - { - code: "path.getParentNode(0)", - output: "path.parent", - errors: [ - { - message: "Prefer `AstPath#parent` over `AstPath#getParentNode(0)`.", - }, - ], - }, - { - code: "const node = path.getParentNode(0)", - output: "const node = path.parent", - errors: [ - { - message: "Prefer `AstPath#parent` over `AstPath#getParentNode(0)`.", - }, - ], - }, { code: "fooPath.getParentNode(0)", output: "fooPath.parent", @@ -924,26 +882,6 @@ test("prefer-ast-path-getters", { }, ], }, - { - code: "path.getParentNode(1)", - output: "path.grandparent", - errors: [ - { - message: - "Prefer `AstPath#grandparent` over `AstPath#getParentNode(1)`.", - }, - ], - }, - { - code: "const node = path.getParentNode(1)", - output: "const node = path.grandparent", - errors: [ - { - message: - "Prefer `AstPath#grandparent` over `AstPath#getParentNode(1)`.", - }, - ], - }, { code: "fooPath.getParentNode(1)", output: "fooPath.grandparent", @@ -956,7 +894,7 @@ test("prefer-ast-path-getters", { }, { code: "path.getName()", - output: "path.getName()", + output: null, errors: [ { message: