Skip to content

Releases: prettier-solidity/prettier-plugin-solidity

v2.3.1

12 Mar 14:05
fe32e08

Choose a tag to compare

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

10 Mar 20:28
5c05465

Choose a tag to compare

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.

    // prettier-plugin-solidity@2.2.1
    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)");
    }
    
    // prettier-plugin-solidity@2.3.0
    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

    // prettier-plugin-solidity@2.2.1
    contract Foo {
        string public constant str =
            "DeadBeef00"
            "DeadBeef01"
            "DeadBeef02";
        function bar() public {
            string str = "DeadBeef03"
            "DeadBeef04"
            "DeadBeef05";
            str = "DeadBeef0a"
            "DeadBeef0b"
            "DeadBeef0c";
        }
    }
    
    // prettier-plugin-solidity@2.3.0
    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

    // prettier-plugin-solidity@2.2.1
    uint foo =
        longCondition1 ||
            longCondition2
            ? 1234567890 
            : 9876543210;
    
    // prettier-plugin-solidity@2.3.0
    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

06 Jan 23:04

Choose a tag to compare

v2.0.0-beta.6 Pre-release
Pre-release

New features

  • Add support for transient keyword in the solidity-parse parser by @Janther in #1079

Format changes

  • Don't re-write import * as ... from ... in the solidity-parse parser by @Janther in #1083
// Original
import * as SomeSymbol from "AnotherFile.sol";

// prettier-plugin-solidity@2.0.0-beta.5
// { parser: 'solidity-parse' }
import "AnotherFile.sol" as SomeSymbol;

// prettier-plugin-solidity@2.0.0-beta.6
// { parser: 'solidity-parse' }
import * as SomeSymbol from "AnotherFile.sol";

Breaking changes

Full Changelog: v1.4.1...v1.4.2

v2.0.0-beta.1

18 Sep 10:11

Choose a tag to compare

v2.0.0-beta.1 Pre-release
Pre-release

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

18 Dec 19:49
f667822

Choose a tag to compare

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

10 Nov 20:48
212ffcf

Choose a tag to compare

What's Changed

Format fixes

Behaviour changes

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

Full Changelog: v2.1.0...v2.2.0

v2.1.0

09 Jul 20:23
29f41b4

Choose a tag to compare

What's Changed

API Changes

Format Changes

  • Only break import deconstruction if the list of items is longer than 1. by @Janther in #1178
// 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;
  • Fixed bug in the last comment in a struct definition. by @Janther in #1181
// 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

Full Changelog: v2.0.0...v2.1.0

v2.0.0

30 Apr 08:10
4fc697c

Choose a tag to compare

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

25 Apr 16:28
ef2ec66

Choose a tag to compare

What's Changed

Full Changelog: v1.4.2...v1.4.3

v2.0.0-beta.8

25 Mar 10:38
bd5ece9

Choose a tag to compare

v2.0.0-beta.8 Pre-release
Pre-release

What's Changed

Full Changelog: v2.0.0-beta.7...v2.0.0-beta.8