prettier-solidity / prettier-plugin-solidity

A Prettier plugin for automatically formatting your Solidity code.
https://t.me/+kgTgkFgIwJkwMjcx
MIT License
729 stars 73 forks source link

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

Open fvictorio opened 2 years ago

fvictorio commented 2 years ago

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:

OmarTawfik commented 2 years ago

+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.

mattiaerre commented 2 years ago

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

fvictorio commented 2 years ago

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.

OmarTawfik commented 2 years ago

Found another one: byte is rewritten as bytes1.

sambacha commented 2 years ago

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