Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fvictorio opened this issue Apr 4, 2022 · 5 comments
Open

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

fvictorio opened this issue Apr 4, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@fvictorio
Copy link
Member

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 😅

@OmarTawfik
Copy link

+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
Copy link
Member

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

@mattiaerre mattiaerre added the enhancement New feature or request label Apr 16, 2022
@fvictorio
Copy link
Member Author

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
Copy link

Found another one: byte is rewritten as bytes1.

@sambacha
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants