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

[bug]: pragma semver change after running prettier #581

Closed sambacha closed 3 years ago

sambacha commented 3 years ago

pragma versioning not respecting

I brought this issue up in the chat on telegram, here is a repo that reproduces the bug:

https://github.com/sambacha/prettier-pragma-issue/pull/1/files#diff-ad2dec38bedc47f194ab485f62b403cbc54ac972d7412ec546149e0afb43a754L2

TLDR

-pragma solidity ^0.5.0 || ^0.6.0 || ^0.7.0;
+pragma solidity >=0.5.0 <0.6.0-0||>=0.6.0 <0.7.0-0||>=0.7.0 <0.8.0-0;

Debug output

However this repo does not trigger the same STDERR output as I saw in the original instance as shown below:

[error] contracts/base64.sol: Error: mismatched input '-' expecting {';', '||', '^', '~', '>=', '>', '<', '<=', '=', DecimalNumber, VersionLiteral} (2:30)
[error]     at Object.parse (/Users/sbacha/base64/node_modules/prettier-plugin-solidity/node_modules/@solidity-parser/parser/dist/index.cjs.js:36867:11)
[error]     at Object.parse (/Users/sbacha/base64/node_modules/prettier-plugin-solidity/src/parser.js:18:25)
[error]     at Object.parse$a [as parse] (/Users/sbacha/base64/node_modules/prettier/index.js:13684:19)
[error]     at coreFormat (/Users/sbacha/base64/node_modules/prettier/index.js:15215:16)
[error]     at formatWithCursor$1 (/Users/sbacha/base64/node_modules/prettier/index.js:15455:14)
[error]     at Object.formatWithCursor (/Users/sbacha/base64/node_modules/prettier/index.js:60228:12)
[error]     at format$1 (/Users/sbacha/base64/node_modules/prettier/bin-prettier.js:16827:21)
[error]     at Object.formatFiles$1 [as formatFiles] (/Users/sbacha/base64/node_modules/prettier/bin-prettier.js:16941:16)
[error]     at async main (/Users/sbacha/base64/node_modules/prettier/bin-prettier.js:18802:5)
[error]     at async Object.run (/Users/sbacha/base64/node_modules/prettier/bin-prettier.js:18745:5)

Most notably the line:

[error] contracts/base64.sol: Error: mismatched input '-' expecting {';', '||', '^', '~', '>=', '>', '<', '<=', '=', DecimalNumber, VersionLiteral} (2:30)

Is not generated, and I tried --loglevel=debug to no avail.

What do? 🙇‍♂️

sambacha commented 3 years ago

Thanks @fvictorio , appreciate the temporary fix!

If would like an additional test case as well for @solidity-parser:

This also returns an issue:

pragma solidity *;

However I do not know who exactly would be using this to be fair (I use them on test files).

Thanks, I will close this issue, much appreciated!

fvictorio commented 3 years ago

Thanks @sambacha, I think that's a bug in the parser, I'll open an issue there.