Skip to content

Commit d51f400

Browse files
committed
test(extensions): add failing tests to expose broken autofix behavior
Follow-up to #391 These tests demonstrate that the `import-x/extensions` rule only applies autofixes when both `fix: true` and a `pattern` object are set—even if the pattern is empty. This behavior is unintuitive, undocumented, and inconsistent with how autofix typically works in ESLint. The tests assert on the `output` field to document the current (broken) behavior and provide a basis for resolving the issue. In addition to fixing the logic, I recommend removing the `fix` option entirely, as it is undocumented and not used in any other rule in the plugin.
1 parent 10cf017 commit d51f400

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

test/rules/extensions.spec.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,73 @@ ruleTester.run('extensions', rule, {
173173
],
174174

175175
invalid: [
176+
tInvalid({
177+
name: 'extensions should autofix by default',
178+
code: 'import a from "a/foo.js"',
179+
options: ['never'],
180+
errors: [
181+
{
182+
messageId: 'unexpected',
183+
data: { extension: 'js', importPath: 'a/foo.js' },
184+
line: 1,
185+
column: 15,
186+
},
187+
],
188+
output: 'import a from "a/foo"',
189+
}),
190+
tInvalid({
191+
name: 'extensions should autofix when fix is set to true',
192+
code: 'import a from "a/foo.js"',
193+
options: ['never', {fix: true}],
194+
errors: [
195+
{
196+
messageId: 'unexpected',
197+
data: { extension: 'js', importPath: 'a/foo.js' },
198+
line: 1,
199+
column: 15,
200+
},
201+
],
202+
output: 'import a from "a/foo"',
203+
}),
204+
tInvalid({
205+
name: 'extensions should autofix when fix is set to true and a pattern object is provided',
206+
code: 'import a from "a/foo.js"',
207+
options: ['never', {fix: true, pattern: {}}],
208+
errors: [
209+
{
210+
messageId: 'unexpected',
211+
data: { extension: 'js', importPath: 'a/foo.js' },
212+
line: 1,
213+
column: 15,
214+
},
215+
],
216+
output: 'import a from "a/foo"',
217+
}),
218+
tInvalid({
219+
name: 'extensions should not autofix when fix is set to false',
220+
code: 'import a from "a/foo.js"',
221+
options: ['never', {fix: false}],
222+
errors: [
223+
{
224+
messageId: 'unexpected',
225+
data: { extension: 'js', importPath: 'a/foo.js' },
226+
line: 1,
227+
column: 15,
228+
suggestions: [
229+
{
230+
messageId: 'removeUnexpected',
231+
data: {
232+
extension: 'js',
233+
importPath: 'a/foo.js',
234+
fixedImportPath: 'a/foo',
235+
},
236+
output: 'import a from "a/foo"',
237+
},
238+
],
239+
},
240+
],
241+
output: null,
242+
}),
176243
tInvalid({
177244
code: 'import a from "a/index.js"',
178245
errors: [

0 commit comments

Comments
 (0)