Skip to content

2.0.0-beta.1

Pre-release
Pre-release
Compare
Choose a tag to compare
@Janther Janther released this 18 Sep 10:11
· 3 commits to v2 since this 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.