Releases: prettier-solidity/prettier-plugin-solidity
v2.3.1
What's Changed
// prettier-plugin-solidity 2.3.0
address payable public valueInParentheses =
(
FancyLibrary.functionCall(
data.data1,
data.data2,
IERC20(data.token).decimals(),
currency
)
);
// prettier-plugin-solidity 2.3.1
address payable public valueInParentheses = (
FancyLibrary.functionCall(
data.data1,
data.data2,
IERC20(data.token).decimals(),
currency
)
);Full Changelog: v2.3.0...v2.3.1
v2.3.0
What's Changed
Format changes
We had to address formatting choices rather than just fixing formatting bugs thus there was a need to publish a new minor release.
-
standardising all assignment types by @Janther in #1437
There are 4 ways to assign a value to a variable and in each one we used to have a slightly different logic.// Constant Definition uint constant FOO_BAR = 0x1234; contract Foo { // State Variable Definition uint foo = 0x1234; function bar() { // Variable Declaration uint foobar = 0x5678; // Assignment Expression foobar = 0xabcd; } }
This is likely going to impact variable definitions where the initial value was a long expression.
// [email protected] contract Foo { bool success = aggregator1 == address(uint160(SIG_VALIDATION_SUCCESS)) && aggregator2 == address(uint160(SIG_VALIDATION_SUCCESS)); bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,uint8 support,address voter,uint256 nonce)"); } // [email protected] contract Foo { bool success = aggregator1 == address(uint160(SIG_VALIDATION_SUCCESS)) && aggregator2 == address(uint160(SIG_VALIDATION_SUCCESS)); bytes32 public constant BALLOT_TYPEHASH = keccak256( "Ballot(uint256 proposalId,uint8 support,address voter,uint256 nonce)" ); }
-
Variables initiated with a multipart string are now indented by @Janther in #1436
// [email protected] contract Foo { string public constant str = "DeadBeef00" "DeadBeef01" "DeadBeef02"; function bar() public { string str = "DeadBeef03" "DeadBeef04" "DeadBeef05"; str = "DeadBeef0a" "DeadBeef0b" "DeadBeef0c"; } } // [email protected] contract Foo { string public constant str = "DeadBeef00" "DeadBeef01" "DeadBeef02"; function bar() public { string str = "DeadBeef03" "DeadBeef04" "DeadBeef05"; str = "DeadBeef0a" "DeadBeef0b" "DeadBeef0c"; } }
Notice how the state variable was already formatting correctly thus making clear the need to standardise the value assingments.
-
remove indentation of a logical operation if it's the operand of a conditional by @Janther in #1441
// [email protected] uint foo = longCondition1 || longCondition2 ? 1234567890 : 9876543210; // [email protected] uint foo = longCondition1 || longCondition2 ? 1234567890 : 9876543210;
Dependencies
- This package was bundled with webpack 5.105.4 by @dependabot[bot] in #1438
- Support @nomicfoundation/slang 1.3.4 and supporting up to solidity 0.8.34 by @Janther in #1421
- Updating semver to 7.7.4 by @dependabot[bot] in #1403
Behaviour changes
- Prettier can format multiple files in parallel and this plugin is now multi-thread safe by @Janther in #1393
Internal changes
- Keeping with continuously improving code speed, size and simplicity. There has been a lot of progress in reducing the size and repetition of steps while keeping or improving the execution time.
- A few bugs if some rare format cases were addressed.
Development changes
- Improved the code coverage to include all possible edge cases of Slang's AST. by @Janther in #1425
- Improved the types, to be more descriptive and accurate to each scenario.
Full Changelog: v2.2.1...v2.3.0
v2.0.0-beta.6
New features
Format changes
// Original
import * as SomeSymbol from "AnotherFile.sol";
// [email protected]
// { parser: 'solidity-parse' }
import "AnotherFile.sol" as SomeSymbol;
// [email protected]
// { parser: 'solidity-parse' }
import * as SomeSymbol from "AnotherFile.sol";Breaking changes
Full Changelog: v1.4.1...v1.4.2
v2.0.0-beta.1
This year we have been working hard on adopting Nomic Foundation's Slang as our new parser.
This allowed us to update our architecture, address issues that the ANTLR parser was blocking, have more control in the rendering of comments, and officially move our codebase to typescript.
While in beta, we will still serve the solidity-parse parser, but the plugin will now log a deprecation warning recommending using the slang-solidity parser.
To start using the new parser just replace solidity-parse with slang-solidity in the .prettierrc file.
{
"plugins": ["prettier-plugin-solidity"],
"overrides": [
{
"files": "*.sol",
"options": {
"parser": "slang-solidity",
"printWidth": 80,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false,
"compiler": "0.8.26",
}
}
]
}If a compiler version is specified, this will be used to parse all the contracts in your project. By default the compiler version will be the latest Solidity version supported by @nomicfoundation/slang. The final 2.0.0 release will infer the Solidity version from the pragma statements in each contract.
A wasm build of the @nomicfoundation/slang package is not included in this beta release. This means the beta release can currently be used in node projects and build pipelines where Rust is supported.
We are working with Nomic Foundation to include a wasm build in the final 2.0.0 release to support browser based IDEs like Remix.
import prettier from 'prettier';
import solidityPlugin from 'prettier-plugin-solidity';
async function format(code) {
return await prettier.format(code, {
parser: 'slang-solidity',
compiler: '0.8.26',
plugins: [solidityPlugin],
});
}
const originalCode = 'contract Foo {}';
const formattedCode = format(originalCode);We invite everyone to try this new version out and welcome reports of new issues.
v2.2.1
What's Changed
Release with @nomicfoundation/slang version 1.3.1 which adds support for solidity 0.8.31.
Full Changelog: v2.2.0...v2.2.1
v2.2.0
What's Changed
Format fixes
- Avoid printing an extra new line after the contract specifiers by @Janther in #1212
- Avoid removing intended new line after
try-catchstatement by @Janther in #1295, reported by @niklasnatter
Behaviour changes
- Parse with latest compatible solidity version by @fvictorio in #1225
- Support @nomicfoundation/slang 1.3.0 by @Janther in #1288
Internal changes
There has been a lot of work put into simplifying the printing flow avoiding extra steps and cleaning up the patterns in the printing functions across the codebase. There has been a noticeable improvement in the execution speed and cleaner codebase.
Development changes
- Add knip by @fvictorio in #1305
Full Changelog: v2.1.0...v2.2.0
v2.1.0
What's Changed
API Changes
- Added support for experimentalOperatorPosition. by @Janther in #1162
- Using Slang's language inference tool to decide what solidity version will be assumed in case no
compileroption is provided. by @Janther in #1158 and #1175
Format Changes
// Original
import { Item } from "../../../contracts/very/long/path/to/File1.sol";
import { Item1, Item2 } from "../../../contracts/very/long/path/to/File2.sol";
// version 2.0.0
import {
Item
} from "../../../contracts/very/long/path/to/File.sol";
import {
Item1,
Item2
} from "../../../contracts/very/long/path/to/File2.sol";
// version 2.1.0
import { Item } from "../../../contracts/very/long/path/to/File.sol";
import {
Item1,
Item2
} from "../../../contracts/very/long/path/to/File2.sol";- New rules added to the grouping in a single line when possible and indentation when the line breaks on binary operations to improve readability and make operations precedence more visible. by @Janther in #1133
// Original
x = veryLongNameA * veryLongNameB + veryLongNameC;
x = veryLongNameA + veryLongNameB * veryLongNameC;
x = veryVeryLongNameA * veryVeryLongNameB + veryVeryLongNameC;
x = veryVeryLongNameA + veryVeryLongNameB * veryVeryLongNameC;
// version 2.0.0
x =
veryLongNameA *
veryLongNameB +
veryLongNameC;
x =
veryLongNameA +
veryLongNameB *
veryLongNameC;
x =
veryVeryLongNameA *
veryVeryLongNameB +
veryVeryLongNameC;
x =
veryVeryLongNameA +
veryVeryLongNameB *
veryVeryLongNameC;
// version 2.1.0
x =
veryLongNameA * veryLongNameB +
veryLongNameC;
x =
veryLongNameA +
veryLongNameB * veryLongNameC;
x =
veryVeryLongNameA *
veryVeryLongNameB +
veryVeryLongNameC;
x =
veryVeryLongNameA +
veryVeryLongNameB *
veryVeryLongNameC;- Fixed a format issue where a small operand would be left in a new line if the right operand breaks in an assignment. by @Janther in #1161
// Original
a = veryVeryVeryVeryVeryLongFunctionCalledA(veryVeryVeryVeryVeryLongArgumentCalledB) ** c;
// version 2.0.0
a =
veryVeryVeryVeryVeryLongFunctionCalledA(
veryVeryVeryVeryVeryLongVariableCalledB
) **
c;
// version 2.1.0
a =
veryVeryVeryVeryVeryLongFunctionCalledA(
veryVeryVeryVeryVeryLongVariableCalledB
) ** c;- Added parentheses on consecutive equality operators to improve readability in operation precedence. by @Janther in #1132
// Original
a == b == c;
a != b == c;
// version 2.0.0
a == b == c;
a != b == c;
// version 2.1.0
(a == b) == c;
(a != b) == c;// Original
struct A {
uint a;
uint b;
// uint c; // commented because I decided to test something
}
// version 2.0.0
struct A {
uint a;
uint b;
}
// uint c; // commented because I decided to test something
// version 2.1.0
struct A {
uint a;
uint b;
// uint c; // commented because I decided to test something
}Breaking Changes
New Contributors
- @Radovenchyk made their first contribution in #1144
Full Changelog: v2.0.0...v2.1.0
v2.0.0
This is a new major version of Prettier Plugin Solidity.
The changes from v1 are minimal, but there are a couple of breaking changes.
The plugin now uses Slang as the parser by default. Slang is a more powerful and correct parser that improves formatting in many edge cases—especially when comments are involved.
If you had the parser explicitly set in your .prettierrc (e.g., "parser": "solidity-parse"), you'll need to update it to:
"parser": "slang"
If you don't have the parser option set in your config, no action is needed.
The old ANTLR-based parser is still supported in v2, but it's deprecated and will be removed in the next major version.
v1.4.3
v2.0.0-beta.8
What's Changed
- Adding support for Slang
1.0.0by @Janther in #1106 - Reintroducing tests for
antlrby @Janther in #1107
Full Changelog: v2.0.0-beta.7...v2.0.0-beta.8