[CI] Feature: Add a fixer for the no-imports-from-self lint #7284
+98
−39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When an invalid import is generated (usually by vscode heuristics) we generally know what the import should be so we might as well provide a fixer at the same time.
Test plan
Before
Get a lint error when circularly importing a module
After
Also get a lint error, but make it fixable by replacing the package name with
.
, e.g. inpackages/lexical/src/LexicalNodeState.ts
Error: Exported module 'lexical' should not import from itself. Use a relative import instead.
Suggestion: Rename import 'lexical' to '.' (lexical/no-imports-from-self)
An also correct fix (and what is actually in that particular module right now) would be to do the import directly from the module that defines it:
But given the toolchains we use either should work and produce the same build artifact. Worst case the user then gets a different error and they can track down which file actually exports that name.