Skip to content

Commit

Permalink
fix: ignore imports with search params
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 12, 2023
1 parent 545558a commit 0f9c153
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/rules/requireExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ export default createRule<Options, MessageIds>({

const importPath = node.source.value;

if (importPath.includes('?')) {
// import { foo } from './foo.svg?url';
return;
}

const importPathHasExtension = endsWith(importPath, extensions);

if (importPathHasExtension) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-expect-error ignore search params
import { foo } from './foo.svg?url';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": [
"*"
]
}
},
"include": [
"."
]
}
1 change: 1 addition & 0 deletions tests/rules/requireExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ ruleTester.run('require-extension', rule, {
invalidTest('exportAllDeclaration'),
],
valid: [
validTest('pathsImportIgnoreSearchParams'),
validTest('pathsImportIgnoreUnknownExtensions'),
validTest('pathsImportWithExtension'),
validTest('relativeImportIgnoreUnknownExtensions'),
Expand Down

0 comments on commit 0f9c153

Please sign in to comment.