import-js/eslint-plugin-import

[import/extensions] Test code: checkTypeImports must not be part of the pattern definition

tobbexiv opened this issue · 2 comments

Thanks for the great project.

I had the following line in my project config:

'import/extensions': [`error`, { ts: `never`, js: `never`, json: `always`, checkTypeImports: true }]

I was wondering why I still got errors for json file imports.

When digging deeper, I found that the pattern definitions on the main object are ignored in case certain other properties like checkTypeImports are set:

if (obj.pattern === undefined && obj.ignorePackages === undefined && obj.checkTypeImports === undefined) {
Object.assign(result.pattern, obj);
return;
}

That's totally valid handling but not covered by any test case. Moreover, there are two test cases which have the incorrect logic and still succeed:

test({
code: 'import type T from "./typescript-declare";',
errors: ['Missing file extension for "./typescript-declare"'],
options: [
'always',
{ ts: 'never', tsx: 'never', js: 'never', jsx: 'never', checkTypeImports: true },
],
parser,
}),
test({
code: 'export type { MyType } from "./typescript-declare";',
errors: ['Missing file extension for "./typescript-declare"'],
options: [
'always',
{ ts: 'never', tsx: 'never', js: 'never', jsx: 'never', checkTypeImports: true },
],
parser,
}),

I would suggest to adjust these test cases to the correct configuration.

I'm a bit confused; what's incorrect in the logic for those two test cases?

I missed that the tests are part of the invalid section. So, you can discard this as mistake on my end.