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

[New] `extensions`: add possibility to auto fix extensions errors #1574

wants to merge 1 commit into
base: master


Copy link

orlov-vo commented Dec 17, 2019

No description provided.


This comment has been minimized.

Copy link

coveralls commented Dec 17, 2019

Coverage Status

Coverage decreased (-2.4%) to 93.837% when pulling cfdf00b on orlov-vo:extensions-autofix into 4e8960d on benmosher:master.

Copy link

ljharb left a comment

This is only a safe autofix if the following criteria are true:

  • the current path does not resolve to an existing file, under any extension, or a directory name.
  • the new path with an extension does resolve to a single file.
  • the new path without an extension resolves unambiguously to a single file

This autofixer would require a lot of test cases that include actual file fixtures.

} else if (extension) {
if (isUseOfExtensionForbidden(extension) && isResolvableWithoutExtension(importPath)) {{
node: source,
message: `Unexpected use of file extension "${extension}" for "${importPath}"`,
fix: (fixer) => fixer.replaceText(
JSON.stringify(importPath.replace(new RegExp(`\\.${extension}$`), ''))

This comment has been minimized.

Copy link

ljharb Jan 1, 2020

Suggested change
JSON.stringify(importPath.replace(new RegExp(`\\.${extension}$`), ''))
JSON.stringify(path.basename(importPath, `.${extension}`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.