Test: Rename run_spec to runFormatTest (#15943)

This commit is contained in:
fisker Cheung authored and GitHub committed 2024-01-19 17:20:24 +08:00
1 parent ed23dacc9e
commit 6eda34db44
1236 files changed
+1549 -1486

No files matched your search

@@ -11,7 +11,7 @@ module.exports = {
"no-doc-public-import": require("./no-doc-public-import.js"),
"no-empty-flat-contents-for-if-break": require("./no-empty-flat-contents-for-if-break.js"),
"no-identifier-n": require("./no-identifier-n.js"),
"no-legacy-format-test-fixtures": require("./no-legacy-format-test-fixtures.js"),
"no-legacy-format-test": require("./no-legacy-format-test.js"),
"no-node-comments": require("./no-node-comments.js"),
"no-unnecessary-ast-path-call": require("./no-unnecessary-ast-path-call.js"),
"prefer-ast-path-each": require("./prefer-ast-path-each.js"),
@@ -1,18 +1,26 @@
"use strict";
const dirnameArgumentSelector = [
const legacyRunFormatTestCall = [
"CallExpression",
'[callee.type="Identifier"]',
'[callee.name="run_spec"]',
].join("");
const runFormatTestCall = [
"CallExpression",
'[callee.type="Identifier"]',
'[callee.name="runFormatTest"]',
].join("");
const dirnameArgumentSelector = [
runFormatTestCall,
" > ",
"Identifier.arguments:first-child",
'[name="__dirname"]',
].join("");
const dirnamePropertySelector = [
"CallExpression",
'[callee.type="Identifier"]',
'[callee.name="run_spec"]',
runFormatTestCall,
" > ",
"ObjectExpression.arguments:first-child",
" > ",
@@ -23,6 +31,7 @@ const dirnamePropertySelector = [
'[value.name="__dirname"]',
].join("");
const MESSAGE_ID_LEGACY_FUNCTION_NAME = "legacy-function-name";
const MESSAGE_ID_ARGUMENT = "dirname-argument";
const MESSAGE_ID_PROPERTY = "dirname-property";
@@ -30,9 +39,11 @@ module.exports = {
meta: {
type: "suggestion",
docs: {
url: "https://github.com/prettier/prettier/blob/main/scripts/tools/eslint-plugin-prettier-internal-rules/no-legacy-format-test-fixtures.js",
url: "https://github.com/prettier/prettier/blob/main/scripts/tools/eslint-plugin-prettier-internal-rules/no-legacy-format-test.js",
},
messages: {
[MESSAGE_ID_LEGACY_FUNCTION_NAME]:
"Use `runFormatTest(…)` instead of `run_spec(…)`.",
[MESSAGE_ID_ARGUMENT]: "Use `import.meta` instead of `__dirname`.",
[MESSAGE_ID_PROPERTY]:
"Use `importMeta: import.meta` instead of `dirname: __dirname`.",
@@ -42,6 +53,14 @@ module.exports = {
},
create(context) {
return {
[legacyRunFormatTestCall](callExpression) {
context.report({
node: callExpression.callee,
messageId: MESSAGE_ID_LEGACY_FUNCTION_NAME,
fix: (fixer) =>
fixer.replaceText(callExpression.callee, "runFormatTest"),
});
},
[dirnameArgumentSelector](node) {
context.report({
node,
@@ -271,26 +271,32 @@ test("no-identifier-n", {
],
});
test("no-legacy-format-test-fixtures", {
test("no-legacy-format-test", {
valid: [
"run_spec(import.meta, ['babel'])",
"run_spec({importMeta: import.meta}, ['babel'])",
"runFormatTest(import.meta, ['babel'])",
"runFormatTest({importMeta: import.meta}, ['babel'])",
].map((code) => ({ code, parserOptions: { sourceType: "module" } })),
invalid: [
{
code: "run_spec(__dirname, ['babel'])",
errors: [{ message: "Use `import.meta` instead of `__dirname`." }],
output: "run_spec(import.meta, ['babel'])",
code: "run_spec(import.meta, ['babel'])",
errors: [{ message: "Use `runFormatTest(…)` instead of `run_spec(…)`." }],
output: "runFormatTest(import.meta, ['babel'])",
},
{
code: "run_spec({snippets: ['x'], dirname: __dirname}, ['babel'])",
code: "runFormatTest(__dirname, ['babel'])",
errors: [{ message: "Use `import.meta` instead of `__dirname`." }],
output: "runFormatTest(import.meta, ['babel'])",
},
{
code: "runFormatTest({snippets: ['x'], dirname: __dirname}, ['babel'])",
errors: [
{
message:
"Use `importMeta: import.meta` instead of `dirname: __dirname`.",
},
],
output: "run_spec({snippets: ['x'], importMeta: import.meta}, ['babel'])",
output:
"runFormatTest({snippets: ['x'], importMeta: import.meta}, ['babel'])",
},
].map((test) => ({ ...test, parserOptions: { sourceType: "module" } })),
});