prettier-plugin-solidity icon indicating copy to clipboard operation
prettier-plugin-solidity copied to clipboard

Don't re-write `import * as ... from ...`

Open fvictorio opened this issue 3 years ago • 5 comments
trafficstars

This

import * as Bar from "./Bar.sol";

is re-written as

import "./Bar.sol" as Bar;

Those two statements are (I think?) semantically equivalent, but I think this is too opinionated. We should keep in mind that prettier solidity is not only being used by smart contract developers. For example, @OmarTawfik is considering using it to generate snippets in an upcoming solidity specification, and re-writes like this one make it impossible to use for that use case.

We could have an option for this, but I think at this point everyone knows I really, really don't like adding new options :sweat_smile:

fvictorio avatar Apr 04 '22 16:04 fvictorio

+1 to not adding new options. If I may suggest, these kind of transformations are more useful in a linter (solhint?), where it works with the user to educate/produce better code. For formatting, I think it should focus on just layout/whitespaces.

OmarTawfik avatar Apr 04 '22 19:04 OmarTawfik

Out of curiosity @fvictorio why are we formatting it this way? is it based on how we read the AST?

mattiaerre avatar Apr 16 '22 00:04 mattiaerre

It can be either a thing we did (consciously or not), or it could be that the AST doesn't have enough information to tell apart between these semantically equivalent statements.

fvictorio avatar Apr 16 '22 11:04 fvictorio

Found another one: byte is rewritten as bytes1.

OmarTawfik avatar May 02 '22 16:05 OmarTawfik

I actually do not think they are semantically the same wrt the solidity compiler, i think if you do:

import * as {Bar} from "./Bar.sol"

and

import "./Bar.sol" as Bar;

they are the same? Imports are not 1:1 wrt the javascript module spec which solidity states its suppose to model after (as you can import via URL)

https://html.spec.whatwg.org/multipage/webappapis.html#integration-with-the-javascript-module-system

sambacha avatar Jun 11 '22 12:06 sambacha