Skip to content

Update dependency prettier-plugin-solidity to v2 #5654

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Apr 30, 2025

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
prettier-plugin-solidity ^1.1.0 -> ^2.0.0 age adoption passing confidence

Release Notes

prettier-solidity/prettier-plugin-solidity (prettier-plugin-solidity)

v2.0.0

Compare Source

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

Compare Source

What's Changed

Full Changelog: prettier-solidity/prettier-plugin-solidity@v1.4.2...v1.4.3

v1.4.2

Compare Source

New features

Format changes

// Original
import * as SomeSymbol from "AnotherFile.sol";

// [email protected]
import "AnotherFile.sol" as SomeSymbol;

// [email protected]
import * as SomeSymbol from "AnotherFile.sol";

Breaking changes

Full Changelog: prettier-solidity/prettier-plugin-solidity@v1.4.1...v1.4.2

v1.4.1

Compare Source

@​pcaversaccio let us know that one of our formatting decisions was formatting an expected result so this was quickly reverted to the previous standard.

// Input
contract Comments {
    function ifElse() public {
        if (condition) {
            // ...
        } // Reason for else case
        else {
            // ...
        }
    }
}

// v1.4.0
contract Comments {
    function ifElse() public {
        if (condition) {
            // ...
        } else {
            // Reason for else case
            // ...
        }
    }
}

// v1.4.1
contract Comments {
    function ifElse() public {
        if (condition) {
            // ...
        } // Reason for else case
        else {
            // ...
        }
    }
}

v1.4.0

Compare Source

As we are preparing for a version 2.0.0 of this plugin there were a few tweaks in the formatting that we needed to address before proceeding forward.

Empty assembly blocks

// Input
contract Assembly {
    function assemblyEmptyBlocks() public {
        assembly {}
        assembly {
            for {} lt(x, y) {} {}
        }
    }
}

// v1.3.1
contract Assembly {
    function assemblyEmptyBlocks() public {
        assembly {

        }
        assembly {
            for {

            } lt(x, y) {

            } {

            }
        }
    }
}

// v1.4.0
contract Assembly {
    function assemblyEmptyBlocks() public {
        assembly {}
        assembly {
            for {} lt(x, y) {} {}
        }
    }
}

Assembly stack assignments

In versions of Solidity prior to v0.5.0 there was a syntax called stack assignment where the last value of the stack would be allocated to a variable. This statement is independent of what happens before it but in some cases the developer could write it in the same line as the last statement.
So far we have been formatting this in the same line as the previous statement but since in v2.0.0 we will have access to an AST much closer to the actual grammar of solidity, it makes more sense to keep it in a separate statement.

// Input
contract Assembly {
    function stackAssignment() public {
        assembly {
            4 =: y
        }
    }
}

// v1.3.1
contract Assembly {
    function assemblyEmptyBlocks() public {
        assembly {
            4 =: y
        }
    }
}

// v1.4.0
contract Assembly {
    function assemblyEmptyBlocks() public {
        assembly {
            4
            =: y
        }
    }
}

HexLiterals in multiple lines

Solidity allows to declare long HexLiterals as a list of HexLiterals separated by white space. The only reason for using this feature is to display said HexLiteral in multiple lines.

// Input
contract HexLiteral {
    bytes8 hex1 = hex'Dead' hex'Beef';
}

// v1.3.1
contract Assembly {
    bytes8 hex1 = hex'Dead' hex'Beef';
}

// v1.4.0
contract Assembly {
    bytes8 hex1 =
        hex'Dead'
        hex'Beef';
}

Modifier Definitions and Function TypeNames

These 2 cases should format in the same way a function definition does but they remained with separate behaviours.

// Input
contract ModifierDefinitions {
   modifier long() override(Foo , Bar, Baz, Very, VeryVery, VeryLong, OverrideList) { _; }
   modifier threeParams(uint a, uint b, uint c) {}
}

// v1.3.1
contract ModifierDefinitions {
   modifier long()
       override(
           Foo,
           Bar,
           Baz,
           Very,
           VeryVery,
           VeryLong,
           OverrideList
       ) {
       _;
   }
   modifier threeParams(
       uint a,
       uint b,
       uint c
   ) {}
}

// v1.4.0
contract ModifierDefinitions {
   modifier long()
       override(
           Foo,
           Bar,
           Baz,
           Very,
           VeryVery,
           VeryLong,
           OverrideList
       )
   {
       _;
   }
   modifier threeParams(uint a, uint b, uint c) {}
}
// Input
contract FunctionTypeNames {
   struct StructWithFunctionTypes {
       function(bytes32, bytes32, bytes32, bytes32, bytes32, bytes32) internal view[] d;
   }
}

// v1.3.1
contract FunctionTypeNames {
   struct StructWithFunctionTypes {
       function(bytes32, bytes32, bytes32, bytes32, bytes32, bytes32)
           internal
           view[] d;
   }
}

// v1.4.0
contract FunctionTypeNames {
   struct StructWithFunctionTypes {
       function(
           bytes32,
           bytes32,
           bytes32,
           bytes32,
           bytes32,
           bytes32
       ) internal view[] d;
   }
}

There are no comments for the else keyword

As we moved into v2.0.0 we got to review many of the formatting prettier inspired us that were in the backlog.
This particular decision had already been changed prettier and we base our work on old code released by prettier. @​pcaversaccio very diligently let us notice that this could not be reproduced in prettier, therefore it was quickly reverted in v1.4.1

// Input
contract Comments {
    function ifElse() public {
        if (condition) {
            // ...
        } // Reason for else case
        else {
            // ...
        }
    }
}

// v1.3.1
contract Comments {
    function ifElse() public {
        if (condition) {
            // ...
        } // Reason for else case
        else {
            // ...
        }
    }
}

// v1.4.0
contract Comments {
    function ifElse() public {
        if (condition) {
            // ...
        } else {
            // Reason for else case
            // ...
        }
    }
}

v1.3.1

Compare Source

Needed to put a specific experimentalTernaries behaviour behind a feature flag. (thanks @​pcaversaccio)

v1.3.0

Compare Source

This version ships with 2 substantial changes.

  1. The parser had a great improvement in size package making our bundled size go from 773.5 KB to 417 KB and 90 KB gzipped, making our support for browser more impactful. (#​967)
  2. We embraced prettier's ternaries formatting improvements and support the new option externalTernaries, so we invite people to start experimenting with it and give us some feedback. (#​953)

v1.2.0

Compare Source

A few improvements on this release:

  • Dropped support for node 14 (#​887)
  • Migrated the whole codebase to ESM (#​894)
    • The bundled version now has the .cjs extension
  • Improved the bundled file to better support projects targeting browsers (#​943 thanks to @​folego and electric_gary on Telegram)
    • Projects can easily import from prettier-plugin-solidity/standalone
  • Added support for negative e notation 1000e-2 (solidity-parser/parser#95)
  • Full support of file level event definitions, introduced with solidity 0.8.22 (solidity-parser/parser#97)

A few tweaks in the code and refactor for simplicity and efficiency.


Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

Copy link

changeset-bot bot commented Apr 30, 2025

⚠️ No Changeset found

Latest commit: 3523a56

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

socket-security bot commented Apr 30, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​prettier-plugin-solidity@​1.4.3 ⏵ 2.0.010010010095100

View full report

@renovate renovate bot force-pushed the renovate/prettier-plugin-solidity-2.x branch from 2b8c41f to 3523a56 Compare May 2, 2025 19:19
@Janther
Copy link
Contributor

Janther commented May 20, 2025

The solidity compiler prior version 0.7.4 would not parse an import statetment split into more than 1 line.

Since prettier-plugin-solidity@^1.0.0 could not recognise which version of solidity the contract was using, it defaulted to having long import statements in a single line for safety.

However [email protected] derives the version of the solidity compiler from the source and therefore is able to split these long imports safely.

there are 2 contracts in the tests folder that need to be linted for this test to pass and the change will look like this:

// openzeppelin-contracts/test/account/utils/draft-ERC7579Utils.t.sol
// Original
import {ERC7579Utils, Mode, CallType, ExecType, ModeSelector, ModePayload, Execution} from "@openzeppelin/contracts/account/utils/draft-ERC7579Utils.sol";

// Formatted
import {
    ERC7579Utils,
    Mode,
    CallType,
    ExecType,
    ModeSelector,
    ModePayload,
    Execution
} from "@openzeppelin/contracts/account/utils/draft-ERC7579Utils.sol";

Hope this explanation helps solve the decision to move into the new version of prettier-plugin-solidity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant