Skip to content

Commit 537e85d

Browse files
committed
♻️ use named args
1 parent a49e44d commit 537e85d

File tree

5 files changed

+75
-35
lines changed

5 files changed

+75
-35
lines changed

eslint-config-cli/test/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ describe('eslint-config-node', () => {
1313

1414
describe('passes', () => {
1515
it(`should pass radix`, async () =>
16-
testNoFail(linter, `parseInt('10');\n`));
16+
testNoFail({ linter, code: `parseInt('10');\n` }));
1717

1818
it(`should pass no-console`, () =>
19-
testNoFail(linter, `console.log('foo');\n`));
19+
testNoFail({ linter, code: `console.log('foo');\n` }));
2020
});
2121

2222
describe('fails', () => {});

eslint-config-node/test/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ describe('eslint-config-node', () => {
1313

1414
describe('passes', () => {
1515
it(`should pass radix`, async () =>
16-
testNoFail(linter, `parseInt('10');\n`));
16+
testNoFail({ linter, code: `parseInt('10');\n` }));
1717
});
1818

1919
describe('fails', () => {
2020
it(`should fail no-console`, () =>
21-
testRuleFail(linter, `console.log('foo');\n`, 'no-console'));
21+
testRuleFail({
22+
linter,
23+
code: `console.log('foo');\n`,
24+
ruleId: 'no-console',
25+
}));
2226
});
2327
});

eslint-config-typescript/test/index.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,35 @@ describe('eslint-config-typescript', () => {
1313

1414
describe('passes', () => {
1515
it(`should parse typescript`, () =>
16-
testNoFail(linter, `((a: string): string[] => a.split(''))()\n`, true));
16+
testNoFail({
17+
linter,
18+
code: `((a: string): string[] => a.split(''))()\n`,
19+
typescript: true,
20+
}));
1721

1822
it(`should not give eslint error on use before define`, () =>
19-
testNoFail(linter, `Number(a);\nconst a = 10;\n`, true));
23+
testNoFail({
24+
linter,
25+
code: `Number(a);\nconst a = 10;\n`,
26+
typescript: true,
27+
}));
2028
});
2129

2230
describe('fails', () => {
2331
it(`should fail radix`, async () =>
24-
testRuleFail(linter, `parseInt('10');\n`, 'radix', true));
32+
testRuleFail({
33+
linter,
34+
code: `parseInt('10');\n`,
35+
ruleId: 'radix',
36+
typescript: true,
37+
}));
2538

2639
it(`should fail @typescript-eslint/strict-boolean-expressions`, async () =>
27-
testRuleFail(
40+
testRuleFail({
2841
linter,
29-
`let foo: unknown = 'foo';\nfoo = 'bar';\nif (foo) Number();\n`,
30-
'@typescript-eslint/strict-boolean-expressions',
31-
true,
32-
));
42+
code: `let foo: unknown = 'foo';\nfoo = 'bar';\nif (foo) Number();\n`,
43+
ruleId: '@typescript-eslint/strict-boolean-expressions',
44+
typescript: true,
45+
}));
3346
});
3447
});

eslint-config/test/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('eslint-config', () => {
1717

1818
describe('fails', () => {
1919
it(`should fail radix`, async () =>
20-
testRuleFail(linter, `parseInt('10');\n`, 'radix'));
20+
testRuleFail({ linter, code: `parseInt('10');\n`, ruleId: 'radix' }));
2121

2222
it(`should not parse typescript`, () =>
2323
linter

utils/testing/eslint.ts

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,37 @@ export function filePath(typescript: boolean = false): string {
99
export function defaultTestSet(linter: ESLint) {
1010
describe('[standard tests] passes', () => {
1111
it(`should parse javascript`, () =>
12-
testNoFail(
12+
testNoFail({
1313
linter,
14-
`
14+
code: `
1515
(
1616
/** @param {string} a */
1717
(a) => a.split('')
1818
)('test');
1919
`,
20-
));
20+
}));
2121

2222
it(`should allow nested ternaries`, () =>
23-
testNoFail(
23+
testNoFail({
2424
linter,
25-
`(() => (Number === true ? 'a' : Boolean === true ? 'b' : 'c'))();\n`,
26-
true,
27-
));
25+
code: `(() => (Number === true ? 'a' : Boolean === true ? 'b' : 'c'))();\n`,
26+
typescript: true,
27+
}));
2828
});
2929
describe('[standard tests] fails', () => {
3030
it(`should fail eqeqeq`, () =>
31-
testRuleFail(linter, `if (Number == true) Number();\n`, 'eqeqeq'));
31+
testRuleFail({
32+
linter,
33+
code: `if (Number == true) Number();\n`,
34+
ruleId: 'eqeqeq',
35+
}));
3236

3337
it(`should warn on prettier`, () =>
34-
testRuleFail(linter, `Number( '5')`, 'prettier/prettier'));
38+
testRuleFail({
39+
linter,
40+
code: `Number( '5')`,
41+
ruleId: 'prettier/prettier',
42+
}));
3543

3644
// TODO: test for shopify rule
3745
});
@@ -63,27 +71,42 @@ export function singleLintMessage(lint_results: ESLint.LintResult[]) {
6371
);
6472
}
6573

66-
export async function testRuleFail(
67-
linter: ESLint,
68-
code: string,
69-
ruleId: string,
70-
typescript: boolean = false,
71-
) {
74+
interface TestRuleFailOpts {
75+
linter: ESLint;
76+
code: string;
77+
ruleId: string;
78+
typescript?: boolean;
79+
file_path?: string;
80+
}
81+
export async function testRuleFail({
82+
linter,
83+
code,
84+
ruleId,
85+
typescript = false,
86+
file_path = filePath(typescript),
87+
}: TestRuleFailOpts) {
7288
const res = await linter.lintText(code, {
73-
filePath: filePath(typescript),
89+
filePath: file_path,
7490
});
7591
singleLintMessage(res);
7692
strictEqual(res[0]?.source, code);
7793
strictEqual(res[0]?.messages[0]?.ruleId, ruleId);
7894
}
7995

80-
export async function testNoFail(
81-
linter: ESLint,
82-
code: string,
83-
typescript: boolean = false,
84-
) {
96+
interface TestNoFailOpts {
97+
linter: ESLint;
98+
code: string;
99+
typescript?: boolean;
100+
file_path?: string;
101+
}
102+
export async function testNoFail({
103+
linter,
104+
code,
105+
typescript = false,
106+
file_path = filePath(typescript),
107+
}: TestNoFailOpts) {
85108
const res = await linter.lintText(code, {
86-
filePath: filePath(typescript),
109+
filePath: file_path,
87110
});
88111
noLintMessage(res);
89112
}

0 commit comments

Comments
 (0)