@@ -9,29 +9,37 @@ export function filePath(typescript: boolean = false): string {
9
9
export function defaultTestSet ( linter : ESLint ) {
10
10
describe ( '[standard tests] passes' , ( ) => {
11
11
it ( `should parse javascript` , ( ) =>
12
- testNoFail (
12
+ testNoFail ( {
13
13
linter,
14
- `
14
+ code : `
15
15
(
16
16
/** @param {string} a */
17
17
(a) => a.split('')
18
18
)('test');
19
19
` ,
20
- ) ) ;
20
+ } ) ) ;
21
21
22
22
it ( `should allow nested ternaries` , ( ) =>
23
- testNoFail (
23
+ testNoFail ( {
24
24
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
+ } ) ) ;
28
28
} ) ;
29
29
describe ( '[standard tests] fails' , ( ) => {
30
30
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
+ } ) ) ;
32
36
33
37
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
+ } ) ) ;
35
43
36
44
// TODO: test for shopify rule
37
45
} ) ;
@@ -63,27 +71,42 @@ export function singleLintMessage(lint_results: ESLint.LintResult[]) {
63
71
) ;
64
72
}
65
73
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 ) {
72
88
const res = await linter . lintText ( code , {
73
- filePath : filePath ( typescript ) ,
89
+ filePath : file_path ,
74
90
} ) ;
75
91
singleLintMessage ( res ) ;
76
92
strictEqual ( res [ 0 ] ?. source , code ) ;
77
93
strictEqual ( res [ 0 ] ?. messages [ 0 ] ?. ruleId , ruleId ) ;
78
94
}
79
95
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 ) {
85
108
const res = await linter . lintText ( code , {
86
- filePath : filePath ( typescript ) ,
109
+ filePath : file_path ,
87
110
} ) ;
88
111
noLintMessage ( res ) ;
89
112
}
0 commit comments