Skip to content

chore(eslint-plugin): stop linting rule output formatting in tests #5379

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ export default createRule<Options, MessageIds>({
continue;
}

if (prop.key.name === 'code' || prop.key.name === 'output') {
if (prop.key.name === 'code') {
checkExpression(prop.value, isErrorTest);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ baz.symbol.name;
import ts from 'typescript';
declare const thing: ts.Symbol;
thing.declarations.map(decl => {});
`.trimRight(),
`,
errors: [
{
messageId: 'doNotUseWithFixer',
Expand All @@ -53,7 +53,7 @@ thing.declarations.map(decl => {});
import ts from 'typescript';
declare const thing: ts.Symbol;
thing.getDeclarations().map(decl => {});
`.trimRight(),
`,
},
],
},
Expand All @@ -64,7 +64,7 @@ thing.getDeclarations().map(decl => {});
import ts from 'typescript';
declare const thing: ts.Type;
thing.symbol;
`.trimRight(),
`,
errors: [
{
messageId: 'doNotUseWithFixer',
Expand All @@ -85,7 +85,7 @@ thing.symbol;
import ts from 'typescript';
declare const thing: ts.Type;
thing.getSymbol();
`.trimRight(),
`,
},
],
},
Expand All @@ -96,7 +96,7 @@ thing.getSymbol();
import ts from 'typescript';
declare const thing: ts.Type;
thing?.symbol;
`.trimRight(),
`,
errors: [
{
messageId: 'doNotUseWithFixer',
Expand All @@ -117,7 +117,7 @@ thing?.symbol;
import ts from 'typescript';
declare const thing: ts.Type;
thing?.getSymbol();
`.trimRight(),
`,
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@ ruleTester.run({
});
`;
}
function wrapWithOutput(
strings: TemplateStringsArray,
...keys: string[]
): string {
const lastIndex = strings.length - 1;
const code =
strings.slice(0, lastIndex).reduce((p, s, i) => p + s + keys[i], '') +
strings[lastIndex];
return `
ruleTester.run({
invalid: [
{
code: ${code},
output: ${code},
},
],
});
`;
}

ruleTester.run('plugin-test-formatting', rule, {
valid: [
// sanity check for valid tests non-object style
Expand Down Expand Up @@ -365,7 +345,6 @@ ${PARENT_INDENT}\``,
code: wrap`\`
${CODE_INDENT}const a=\\\`\\\${a}\\\`;
${PARENT_INDENT}\``,
// make sure it escapes backticks
output: wrap`\`
${CODE_INDENT}const a = \\\`\\\${a}\\\`;
${PARENT_INDENT}\``,
Expand All @@ -376,26 +355,6 @@ ${PARENT_INDENT}\``,
],
},

// sanity check that it runs on both output and code properties
{
code: wrapWithOutput`\`
${CODE_INDENT}const a="1";
${CODE_INDENT} const b = "2";
${PARENT_INDENT}\``,
output: wrapWithOutput`\`
${CODE_INDENT}const a = '1';
${CODE_INDENT}const b = '2';
${PARENT_INDENT}\``,
errors: [
{
messageId: 'invalidFormattingErrorTest',
},
{
messageId: 'invalidFormattingErrorTest',
},
],
},

// sanity check that it handles suggestion output
{
code: `
Expand Down Expand Up @@ -431,7 +390,7 @@ ruleTester.run({
suggestions: [
{
messageId: 'bar',
output: 'const x = 1;',
output: 'const x=1;',
},
],
},
Expand All @@ -444,9 +403,6 @@ ruleTester.run({
{
messageId: 'invalidFormattingErrorTest',
},
{
messageId: 'invalidFormattingErrorTest',
},
],
},

Expand Down Expand Up @@ -550,28 +506,5 @@ foo
},
],
},

// checks tests with .trimRight calls
{
code: wrap`'const a=1;'.trimRight()`,
output: wrap`'const a = 1;'.trimRight()`,
errors: [
{
messageId: 'invalidFormatting',
},
],
},
{
code: wrap`\`const a = "1";
${CODE_INDENT}\`.trimRight()`,
output: wrap`\`
const a = "1";
${CODE_INDENT}\`.trimRight()`,
errors: [
{
messageId: 'templateLiteralEmptyEnds',
},
],
},
],
});
2 changes: 1 addition & 1 deletion packages/eslint-plugin/tests/rules/ban-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ let baz: object = {};
},
{
code: noFormat`let a: Foo< F >;`,
output: noFormat`let a: Foo< T >;`,
output: `let a: Foo< T >;`,
errors: [
{
messageId: 'bannedTypeMessage',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import rule from '../../src/rules/class-literal-property-style';
import { RuleTester, noFormat } from '../RuleTester';
import { RuleTester } from '../RuleTester';

const ruleTester = new RuleTester({
parser: '@typescript-eslint/parser',
Expand Down Expand Up @@ -311,7 +311,7 @@ class Mx {
public readonly [myValue] = 'a literal value';
}
`,
output: noFormat`
output: `
class Mx {
public get [myValue]() { return 'a literal value'; }
}
Expand All @@ -331,7 +331,7 @@ class Mx {
readonly p1 = 'hello world';
}
`,
output: noFormat`
output: `
class Mx {
get p1() { return 'hello world'; }
}
Expand All @@ -351,7 +351,7 @@ class Mx {
readonly p1 = \`hello world\`;
}
`,
output: noFormat`
output: `
class Mx {
get p1() { return \`hello world\`; }
}
Expand All @@ -371,7 +371,7 @@ class Mx {
static readonly p1 = 'hello world';
}
`,
output: noFormat`
output: `
class Mx {
static get p1() { return 'hello world'; }
}
Expand Down Expand Up @@ -413,7 +413,7 @@ class Mx {
protected readonly p1 = 'hello world';
}
`,
output: noFormat`
output: `
class Mx {
protected get p1() { return 'hello world'; }
}
Expand Down Expand Up @@ -454,7 +454,7 @@ class Mx {
public static readonly p1 = 'hello world';
}
`,
output: noFormat`
output: `
class Mx {
public static get p1() { return 'hello world'; }
}
Expand Down Expand Up @@ -483,7 +483,7 @@ class Mx {
}
}
`,
output: noFormat`
output: `
class Mx {
public readonly myValue = gql\`
{
Expand Down Expand Up @@ -516,7 +516,7 @@ class Mx {
\`;
}
`,
output: noFormat`
output: `
class Mx {
public get myValue() { return gql\`
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Foo {
messageId: 'preferConstructor',
},
],
output: noFormat`const a = new Map<string, number>();`,
output: `const a = new Map<string, number>();`,
},
{
code: noFormat`const a: Map< string, number > = new Map();`,
Expand All @@ -109,7 +109,7 @@ class Foo {
messageId: 'preferConstructor',
},
],
output: noFormat`const a = new Map< string, number >();`,
output: `const a = new Map< string, number >();`,
},
{
code: noFormat`const a: Map<string, number> = new Map ();`,
Expand All @@ -118,7 +118,7 @@ class Foo {
messageId: 'preferConstructor',
},
],
output: noFormat`const a = new Map<string, number> ();`,
output: `const a = new Map<string, number> ();`,
},
{
code: noFormat`const a: Foo<number> = new Foo;`,
Expand All @@ -127,7 +127,7 @@ class Foo {
messageId: 'preferConstructor',
},
],
output: noFormat`const a = new Foo<number>();`,
output: `const a = new Foo<number>();`,
},
{
code: 'const a: /* comment */ Foo/* another */ <string> = new Foo();',
Expand All @@ -136,7 +136,7 @@ class Foo {
messageId: 'preferConstructor',
},
],
output: noFormat`const a = new Foo/* comment *//* another */<string>();`,
output: `const a = new Foo/* comment *//* another */<string>();`,
},
{
code: 'const a: Foo/* comment */ <string> = new Foo /* another */();',
Expand All @@ -145,7 +145,7 @@ class Foo {
messageId: 'preferConstructor',
},
],
output: noFormat`const a = new Foo/* comment */<string> /* another */();`,
output: `const a = new Foo/* comment */<string> /* another */();`,
},
{
code: noFormat`const a: Foo<string> = new \n Foo \n ();`,
Expand All @@ -154,7 +154,7 @@ class Foo {
messageId: 'preferConstructor',
},
],
output: noFormat`const a = new \n Foo<string> \n ();`,
output: `const a = new \n Foo<string> \n ();`,
},
{
code: `
Expand Down Expand Up @@ -218,7 +218,7 @@ class Foo {
messageId: 'preferTypeAnnotation',
},
],
output: noFormat`const a: Map<string, number> = new Map ();`,
output: `const a: Map<string, number> = new Map ();`,
},
{
code: noFormat`const a = new Map< string, number >();`,
Expand All @@ -228,7 +228,7 @@ class Foo {
messageId: 'preferTypeAnnotation',
},
],
output: noFormat`const a: Map< string, number > = new Map();`,
output: `const a: Map< string, number > = new Map();`,
},
{
code: noFormat`const a = new \n Foo<string> \n ();`,
Expand All @@ -238,7 +238,7 @@ class Foo {
messageId: 'preferTypeAnnotation',
},
],
output: noFormat`const a: Foo<string> = new \n Foo \n ();`,
output: `const a: Foo<string> = new \n Foo \n ();`,
},
{
code: 'const a = new Foo/* comment */ <string> /* another */();',
Expand All @@ -248,7 +248,7 @@ class Foo {
messageId: 'preferTypeAnnotation',
},
],
output: noFormat`const a: Foo<string> = new Foo/* comment */ /* another */();`,
output: `const a: Foo<string> = new Foo/* comment */ /* another */();`,
},
{
code: 'const a = new Foo</* comment */ string, /* another */ number>();',
Expand All @@ -258,7 +258,7 @@ class Foo {
messageId: 'preferTypeAnnotation',
},
],
output: noFormat`const a: Foo</* comment */ string, /* another */ number> = new Foo();`,
output: `const a: Foo</* comment */ string, /* another */ number> = new Foo();`,
},
{
code: `
Expand Down
Loading