Skip to content

fix: remove the whole import in no-unused-import fix for unit aliases - #807

Open
SahilRajputdotexe wants to merge 2 commits into
protofire:developfrom
SahilRajputdotexe:fix/no-unused-import-unit-alias
Open

SahilRajputdotexe wants to merge 2 commits into
protofire:developfrom
SahilRajputdotexe:fix/no-unused-import-unit-alias

Conversation

@SahilRajputdotexe

Copy link
Copy Markdown

Fixes #806

For an unused unit alias, the no-unused-import fix removed only the alias identifier, so import * as U from './aaa.sol'; became import * as from './aaa.sol';, which doesn't parse. Same for import './aaa.sol' as U;.

The alias is the only name these imports bring in, so the fix now removes the whole statement, the same way it already does for import { A } from ... when A is the last name left. Both forms are added to the no-unused-import e2e fixture.

For `import * as U from 'x.sol'` and `import 'x.sol' as U`, the fix
removed only the alias identifier, leaving `import * as  from "x.sol"`,
which does not parse. The alias is the only name such an import brings
in, so the whole statement is removed instead.

Fixes protofire#806

@vschernoff vschernoff left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Verified by running it, not only reading the diff.

The bug reproduces on develop — both unit-alias forms become unparseable:

import * as U from './aaa.sol';   →   import * as  from "./aaa.sol";
import './bbb.sol' as V;          →   import "./bbb.sol" as ;
missing 'from' at '"./aaa.sol"' (4:18)

With this PR both statements are removed entirely and the file parses. Checked alongside a named import in the same file, so the two paths do not interfere:

import * as U from './aaa.sol';            // removed
import './bbb.sol' as V;                   // removed
import { Used, Unused } from './ccc.sol';  // → import { Used } from "./ccc.sol";

Also checked:

  • A used unit alias is left alone — import * as Lib from './lib.sol'; with Lib.value() in the body survives untouched.
  • No leftover whitespace. The removed statements leave no blank lines; [start, end + 1] is the right boundary, since node.range is inclusive of the final ;.

Removing the whole statement is the right call rather than patching the identifier: the alias is the only name these forms bring in, so once it is unused there is nothing left for the statement to do — which matches what the rule already does for the last name in import { A } from ....

One note: I could not run e2e/autofix-test.js locally — it fails on Node 26 with the yargs ESM loader error, identically on an untouched develop. CI on Node 20/22 is the real check for the added fixtures.

@dbale-arg

Copy link
Copy Markdown
Collaborator

@SahilRajputdotexe thanks a lot for the collaboration. !!!!
Will be reviewed and included in next release (6.2.6) if everything is working fine.

@dbale-arg dbale-arg assigned dbale-arg and unassigned dbale-arg Oct 8, 2026
@SahilRajputdotexe

Copy link
Copy Markdown
Author

Looking forward to it X )

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

no-unused-import --fix produces invalid Solidity for unit-alias imports

3 participants