Skip to content
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