Repository navigation
fix: keep unit aliases in imports-order autofix - #803
SahilRajputdotexe wants to merge 2 commits into
Conversation
The autofix rebuilt every import without symbol aliases as a bare import 'path', so import * as X from 'path' and import 'path' as X lost their alias and the fixed file no longer compiled. Rebuild those imports with the alias, in the form it was written.
vschernoff
left a comment
There was a problem hiding this comment.
Approving. Verified by running it rather than only reading the diff.
The bug reproduces on develop — --fix drops the alias entirely:
before import * as Utils from './libraries/Utils.sol';
after import "./libraries/Utils.sol";
Both forms are preserved with this PR:
import * as Utils from "./libraries/Utils.sol";
import "./Types.sol" as Types;
The implementation is safe. I checked the parser output directly: whenever unitAlias is set, both unitAliasIdentifier and pathLiteral are present with ranges, so the range[0] comparison cannot throw — and it is guarded inside if (node.unitAlias) regardless. The comparison correctly distinguishes the two forms.
One thing to note, not a blocker and not caused by this PR: no-unused-import --fix produces import * as from "..." — invalid Solidity — on the same import shape. imports-order reports no violation on that file, so it is a different rule entirely. Filed as #806 so it is not assumed fixed by this.
The
imports-orderautofix rebuilds every import statement, but it only knows two shapes:import { A } from 'path'and a bareimport 'path'. An import with a unit alias falls into the second one, so--fixdrops the alias:becomes
and the fixed file no longer compiles.
This rebuilds those imports with their alias, in the form they were written. Both forms are added to the
imports-ordere2e fixture.