-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(extensions): enhance import extension enforcement with autofix support #3177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
8f6185d
b8e7370
8cd047b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ function buildProperties(context) { | |
defaultConfig: 'never', | ||
pattern: {}, | ||
ignorePackages: false, | ||
fix: false, | ||
}; | ||
|
||
context.options.forEach((obj) => { | ||
|
@@ -72,6 +73,11 @@ function buildProperties(context) { | |
result.ignorePackages = obj.ignorePackages; | ||
} | ||
|
||
// If fix is provided, transfer it to result | ||
if (obj.fix !== undefined) { | ||
result.fix = obj.fix; | ||
} | ||
|
||
if (obj.checkTypeImports !== undefined) { | ||
result.checkTypeImports = obj.checkTypeImports; | ||
} | ||
|
@@ -97,7 +103,7 @@ module.exports = { | |
description: 'Ensure consistent use of file extension within the import path.', | ||
url: docsUrl('extensions'), | ||
}, | ||
|
||
fixable: 'code', | ||
schema: { | ||
anyOf: [ | ||
{ | ||
|
@@ -225,13 +231,32 @@ module.exports = { | |
node: source, | ||
message: | ||
`Missing file extension ${extension ? `"${extension}" ` : ''}for "${importPathWithQueryString}"`, | ||
...props.fix && extension ? { | ||
fix(fixer) { | ||
return fixer.replaceText( | ||
source, | ||
JSON.stringify(`${importPathWithQueryString}.${extension}`), | ||
); | ||
}, | ||
} : {}, | ||
}); | ||
} | ||
} else if (extension) { | ||
if (isUseOfExtensionForbidden(extension) && isResolvableWithoutExtension(importPath)) { | ||
context.report({ | ||
node: source, | ||
message: `Unexpected use of file extension "${extension}" for "${importPathWithQueryString}"`, | ||
...props.fix | ||
? { | ||
fix(fixer) { | ||
return fixer.replaceText( | ||
source, | ||
JSON.stringify( | ||
importPath.slice(0, -(extension.length + 1)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://github.com/un-ts/eslint-plugin-import-x/pull/327/files#r2094298890
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe you are also still using Thanks |
||
), | ||
); | ||
}, | ||
} : {}, | ||
}); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/un-ts/eslint-plugin-import-x/pull/329/files#r2094349587
https://github.com/un-ts/eslint-plugin-import-x/pull/327/files#r2094298890
importPathWithQueryString
could containsquery
andhash
, and could also ends with.
,..
or/
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done thank you