-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.test.js
More file actions
223 lines (217 loc) · 9.45 KB
/
eslint.test.js
File metadata and controls
223 lines (217 loc) · 9.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* ESLint Configuration Tests
*
* This file contains tests for our ESLint configurations.
* Helper functions and constants are available globally through the Jest setup.
*/
/**
* Invalid Test Suite
*
* This test suite verifies that our ESLint configurations correctly identify
* issues in files with intentional errors.
*
* Invalid tests, generally, don't need disabled rules since we want to see
* all issues.
*
* Each test case includes:
* - `file`: The test fixture filename
* - `disableRules`: Rules to filter out from the snapshot to focus on the
* conflict
* - `testNotes`: Optional developer/maintainer reminders
*/
describe('ESLint Configurations', () => {
it.each([
{
file: 'invalid.base.js',
disableRules: []
},
{
file: 'invalid.jest.js',
disableRules: []
},
{
file: 'invalid.json.json',
disableRules: []
},
{
file: 'invalid.node.js',
disableRules: [],
testNotes: [
'Verified that Node.js 22.0.0 features (Array.fromAsync, Import Attributes) are supported.',
'Verified that Node.js 22.11.0 features (Promise.withResolvers) are correctly flagged when targeting 22.0.0.',
'Verified that deprecated APIs and Node-specific path rules are correctly flagged.'
]
},
{
file: 'invalid.react.jsx',
disableRules: []
}
])('$file should have the expected linting issues', async ({ file, disableRules }) => {
const result = await global.lintAndProcessFile(file, { disableRules });
expect(result).toMatchSnapshot();
});
});
/**
* Rule Conflicts Test Suite
*
* This test suite verifies that our ESLint configuration correctly resolves
* known conflicts between different ESLint rules.
*
* We disable documentation rules to focus on conflict resolution.
*
* Each test case includes:
* - `file`: The test fixture filename
* - `description`: What the test is verifying
* - `rules`: Array of ESLint rule IDs that potentially conflict
* - `note`: How the conflict was resolved
* - `disableRules`: Rules to filter out from the snapshot to focus on the conflict
* - `testNotes`: Optional developer/maintainer reminders
*/
describe('Rule Conflicts', () => {
it.each([
{
file: 'conflicts.rule-conflict.js',
description: 'should not have conflicts between padded-blocks and lines-around-comment',
rules: ['@stylistic/padded-blocks', '@stylistic/lines-around-comment'],
note: 'Added allowBlockStart: true to lines-around-comment rule',
disableRules: global.FILTERABLE_RULES.documentation
},
{
file: 'conflicts.arrow-parens.js',
description: 'should not have errors for arrow functions with parentheses',
rules: ['@stylistic/no-confusing-arrow', '@stylistic/no-extra-parens'],
note: 'Handled arrow conditionals via ignoredNodes selectors; rule remains at warning',
disableRules: global.FILTERABLE_RULES.documentation
},
{
file: 'conflicts.cond-assign-parens.js',
description: 'should not have errors for assignments in conditional expressions with parentheses',
rules: ['@stylistic/no-extra-parens', 'no-cond-assign'],
note: 'Added conditionalAssign: false to no-extra-parens rule to allow parentheses around assignments in conditions',
disableRules: global.FILTERABLE_RULES.documentation
}
])('$file $description (Note: $note)', async ({ file, rules, disableRules }) => {
const result = await global.lintAndProcessFile(file, { disableRules });
const conflictErrors = result.messages.filter(msg => rules.includes(msg.ruleId) && msg.severity === 'error');
expect(conflictErrors).toHaveLength(0);
expect(result).toMatchSnapshot();
});
});
/**
* Rule Customizations Test Suite
*
* This test suite verifies that our custom rule configurations work correctly
* for specific programming patterns that we've explicitly allowed.
*
* Each test case includes:
* - `file`: The test fixture filename
* - `description`: What the test is verifying
* - `rule`: The ESLint rule ID being tested
* - `note`: How the rule was customized to allow specific patterns
* - `disableRules`: Rules to filter out from the snapshot to focus on the rule being tested
* - `testNotes`: Optional developer/maintainer reminders
*/
describe('Rule Customizations', () => {
it.each([
{
file: 'custom.cond-assign.js',
description: 'should allow assignments in while loop conditions with parentheses',
rule: 'no-cond-assign',
note: 'Changed from "always" to "except-parens" to allow assignments in parenthesized expressions',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style]
},
{
file: 'custom.function-paren-newline.js',
description: 'should allow consistent function parameter formatting',
rule: '@stylistic/function-paren-newline',
note: 'Changed from "multiline-arguments" to "consistent" to allow more flexible function parameter formatting',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style]
},
{
file: 'custom.jsdoc-undefined-types.js',
description: 'should allow undefined types in JSDoc comments',
rule: 'jsdoc/no-undefined-types',
note: 'Changed from error (2) to off (0) to allow undefined types in JSDoc comments',
disableRules: global.FILTERABLE_RULES.style,
testNotes: 'This test is specific to JSDoc functionality, so we need to keep JSDoc rules enabled.'
},
{
file: 'custom.indent.js',
description: 'should properly indent various code constructs',
rule: '@stylistic/indent',
note: 'Expanded configuration to provide consistent indentation for arrays, function calls, function declarations, imports, and objects',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style]
},
{
file: 'custom.newline-per-chained-call.js',
description: 'should allow up to 4 method calls in a chain without line breaks',
rule: '@stylistic/newline-per-chained-call',
note: 'Increased ignoreChainWithDepth from 3 to 4 to allow more method chaining on a single line',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style]
},
{
file: 'custom.space-before-function-paren.js',
description: 'should enforce consistent spacing in various code constructs',
rule: '@stylistic/space-before-function-paren',
note: 'Configured to require space before function parentheses for anonymous and async arrow functions, no space for named functions',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style]
},
{
file: 'custom.brace-style.js',
description: 'should enforce consistent line breaking and formatting',
rule: '@stylistic/brace-style',
note: 'Configured as 1tbs with allowSingleLine: true to allow consistent brace style with flexibility for single-line blocks',
disableRules: [...global.FILTERABLE_RULES.documentation]
},
{
file: 'custom.comma-dangle.js',
description: 'should enforce consistent punctuation usage',
rule: '@stylistic/comma-dangle',
note: 'Set to "never" to disallow trailing commas in objects and arrays',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style]
},
{
file: 'custom.array-bracket-newline.js',
description: 'should enforce consistent array and object formatting',
rule: '@stylistic/array-bracket-newline',
note: 'Set to "consistent" to require consistent line breaks inside array brackets',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style]
},
{
file: 'custom.no-extra-parens.js',
description: 'should allow parentheses around logical expressions in spread elements',
rule: '@stylistic/no-extra-parens',
note: 'Configured via ignoredNodes selectors to allow parentheses around logical expressions/conditionals/await in spread elements',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style]
},
{
file: 'custom.no-plusplus.js',
description: 'should disallow ++/-- except in for-loop afterthought',
rule: 'no-plusplus',
note: 'Enabled as warning with allowForLoopAfterthoughts: true',
disableRules: [...global.FILTERABLE_RULES.documentation, ...global.FILTERABLE_RULES.style],
testNotes: [
'Expect warnings for count++ and --n outside for-loop afterthoughts',
'Expect no warnings for i++ in for-loop afterthought',
'Expect no issues for the "+= 1" example'
]
},
{
file: 'custom.prefer-logical-operator-over-ternary.js',
description: 'should prefer a logical operator over simple ternary fallbacks',
rule: 'unicorn/prefer-logical-operator-over-ternary',
note: 'Rule enabled without options; the plugin suggests either || or ??',
disableRules: [
...global.FILTERABLE_RULES.documentation,
...global.FILTERABLE_RULES.style
],
testNotes: [
'Ternary fallbacks should be flagged by unicorn/prefer-logical-operator-over-ternary',
'The rule provides suggestions for both || and ?? in this version'
]
}
])('$file $description (Note: $note)', async ({ file, rule, disableRules }) => {
const result = await global.lintAndProcessFile(file, { disableRules, testRule: rule });
expect(result).toMatchSnapshot();
});
});