Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rule-tester): support multipass fixes #8883

Merged
merged 8 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -206,8 +206,18 @@ const test = [
},
{
code: wrap`'for (const x of y) {}'`,
output: wrap`\`for (const x of y) {
output: [
wrap`\`for (const x of y) {
}\``,
wrap`\`
for (const x of y) {
}
\``,
wrap`\`
for (const x of y) {
}
${PARENT_INDENT}\``,
],
errors: [
{
messageId: 'invalidFormatting',
Expand All @@ -217,8 +227,18 @@ const test = [
{
code: wrap`'for (const x of \`asdf\`) {}'`,
// make sure it escapes the backticks
output: wrap`\`for (const x of \\\`asdf\\\`) {
output: [
wrap`\`for (const x of \\\`asdf\\\`) {
}\``,
wrap`\`
for (const x of \\\`asdf\\\`) {
}
\``,
wrap`\`
for (const x of \\\`asdf\\\`) {
}
${PARENT_INDENT}\``,
],
errors: [
{
messageId: 'invalidFormatting',
Expand All @@ -238,7 +258,7 @@ const test = [
},
{
code: wrap`\`const a = '1'\``,
output: wrap`"const a = '1'"`,
output: [wrap`"const a = '1'"`, wrap`"const a = '1';"`],
errors: [
{
messageId: 'singleLineQuotes',
Expand All @@ -247,7 +267,7 @@ const test = [
},
{
code: wrap`\`const a = "1";\``,
output: wrap`'const a = "1";'`,
output: [wrap`'const a = "1";'`, wrap`"const a = '1';"`],
errors: [
{
messageId: 'singleLineQuotes',
Expand All @@ -258,9 +278,14 @@ const test = [
{
code: wrap`\`const a = "1";
${PARENT_INDENT}\``,
output: wrap`\`
output: [
wrap`\`
const a = "1";
${PARENT_INDENT}\``,
wrap`\`
const a = '1';
${PARENT_INDENT}\``,
],
errors: [
{
messageId: 'templateLiteralEmptyEnds',
Expand All @@ -270,9 +295,17 @@ ${PARENT_INDENT}\``,
{
code: wrap`\`
${CODE_INDENT}const a = "1";\``,
output: wrap`\`
output: [
wrap`\`
${CODE_INDENT}const a = "1";
\``,
wrap`\`
${CODE_INDENT}const a = "1";
${PARENT_INDENT}\``,
wrap`\`
${CODE_INDENT}const a = '1';
${PARENT_INDENT}\``,
],
errors: [
{
messageId: 'templateLiteralEmptyEnds',
Expand All @@ -282,10 +315,20 @@ ${CODE_INDENT}const a = "1";
{
code: wrap`\`const a = "1";
${CODE_INDENT}const b = "2";\``,
output: wrap`\`
output: [
wrap`\`
const a = "1";
${CODE_INDENT}const b = "2";
\``,
wrap`\`
const a = "1";
${CODE_INDENT}const b = "2";
${PARENT_INDENT}\``,
wrap`\`
const a = '1';
const b = '2';
${PARENT_INDENT}\``,
],
errors: [
{
messageId: 'templateLiteralEmptyEnds',
Expand All @@ -297,9 +340,14 @@ ${CODE_INDENT}const b = "2";
code: wrap`\`
${CODE_INDENT}const a = "1";
\``,
output: wrap`\`
output: [
wrap`\`
${CODE_INDENT}const a = "1";
${PARENT_INDENT}\``,
wrap`\`
${CODE_INDENT}const a = '1';
${PARENT_INDENT}\``,
],
errors: [
{
messageId: 'templateLiteralLastLineIndent',
Expand All @@ -310,9 +358,14 @@ ${PARENT_INDENT}\``,
code: wrap`\`
${CODE_INDENT}const a = "1";
\``,
output: wrap`\`
output: [
wrap`\`
${CODE_INDENT}const a = "1";
${PARENT_INDENT}\``,
wrap`\`
${CODE_INDENT}const a = '1';
${PARENT_INDENT}\``,
],
errors: [
{
messageId: 'templateLiteralLastLineIndent',
Expand Down Expand Up @@ -483,7 +536,8 @@ ruleTester.run({
],
});
`,
output: `
output: [
`
ruleTester.run({
valid: [
{
Expand Down Expand Up @@ -517,6 +571,75 @@ foo
],
});
`,
`
ruleTester.run({
valid: [
{
code: 'foo;',
},
{
code: \`
foo
\`,
},
{
code: \`
foo
\`,
},
],
invalid: [
{
code: 'foo;',
},
{
code: \`
foo
\`,
},
{
code: \`
foo
\`,
},
],
});
`,
`
ruleTester.run({
valid: [
{
code: 'foo;',
},
{
code: \`
foo;
\`,
},
{
code: \`
foo
\`,
},
],
invalid: [
{
code: 'foo;',
},
{
code: \`
foo;
\`,
},
{
code: \`
foo
\`,
},
],
});
`,
],
errors: [
{
messageId: 'singleLineQuotes',
Expand Down
6 changes: 5 additions & 1 deletion packages/eslint-plugin/tests/RuleTester.ts
Expand Up @@ -44,7 +44,11 @@ export function batchedSingleLineTests<
MessageIds extends string,
Options extends readonly unknown[],
>(
options: InvalidTestCase<MessageIds, Options> | ValidTestCase<Options>,
options:
| (Omit<InvalidTestCase<MessageIds, Options>, 'output'> & {
output?: string | null;
})
| ValidTestCase<Options>,
): (InvalidTestCase<MessageIds, Options> | ValidTestCase<Options>)[] {
// -- eslint counts lines from 1
const lineOffset = options.code.startsWith('\n') ? 2 : 1;
Expand Down
Expand Up @@ -409,11 +409,16 @@ declare const nested: string, interpolation: string;
\`le\${ \`ss\` }\`
}\`;
`,
output: `
output: [
kirkwaiblinger marked this conversation as resolved.
Show resolved Hide resolved
`
\`use\${
\`less\`
}\`;
`,
`
\`useless\`;
`,
],
errors: [
{
messageId: 'noUselessTemplateLiteral',
Expand Down