Skip to content

feat: [extensions] add error message instead of failing silently #403

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/rules/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,18 @@ export default createRule<Options, MessageId>({
})
const fixOrSuggest = {
fix(fixer: TSESLint.RuleFixer) {
return fixer.replaceText(
source,
replaceImportPath(source.raw, fixedImportPath),
const newImportPath = replaceImportPath(
source.raw,
fixedImportPath,
)

if (newImportPath === source.raw) {
throw new Error(
'Failed to automatically determine the type of extension to add. Try configuring this rule with an object that includes the explicit extension that you want the autofixer to use. (See the docs for an example.)',
)
}

return fixer.replaceText(source, newImportPath)
},
}
context.report({
Expand Down