Repository navigation
fix: remove the whole import in no-unused-import fix for unit aliases - #807
SahilRajputdotexe wants to merge 2 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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';withLib.value()in the body survives untouched. - No leftover whitespace. The removed statements leave no blank lines;
[start, end + 1]is the right boundary, sincenode.rangeis 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.
|
@SahilRajputdotexe thanks a lot for the collaboration. !!!! |
|
Looking forward to it X ) |
Fixes #806
For an unused unit alias, the
no-unused-importfix removed only the alias identifier, soimport * as U from './aaa.sol';becameimport * as from './aaa.sol';, which doesn't parse. Same forimport './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 ...whenAis the last name left. Both forms are added to theno-unused-importe2e fixture.