What is prettier-plugin-solidity?
The prettier-plugin-solidity is a plugin for Prettier that formats Solidity code. It helps maintain a consistent style across Solidity codebases, making the code more readable and easier to maintain.
What are prettier-plugin-solidity's main functionalities?
Code Formatting
The plugin automatically formats Solidity code according to a set of predefined rules. For example, it can adjust spacing, indentation, and line breaks to ensure the code is clean and consistent.
contract MyContract { function myFunction() public { uint x = 1; } }
Consistent Style
By using the plugin, developers can ensure that their Solidity code adheres to a consistent style guide, which is particularly useful in collaborative projects. The plugin enforces rules such as consistent indentation and spacing.
contract MyContract {
function myFunction() public {
uint x = 1;
}
}
Integration with Prettier
The plugin integrates seamlessly with Prettier, allowing developers to format their Solidity code using the same tool they use for other languages. This integration simplifies the development workflow by providing a unified formatting solution.
{ "plugins": ["prettier-plugin-solidity"] }
Other packages similar to prettier-plugin-solidity
solhint
Solhint is a linter for Solidity code that helps developers enforce coding standards and best practices. While it focuses on linting rather than formatting, it complements prettier-plugin-solidity by providing additional checks for code quality and security.
solium
Solium, also known as Ethlint, is another linter for Solidity that enforces style and security rules. Like Solhint, it focuses on linting rather than formatting, but it can be used alongside prettier-plugin-solidity to ensure both style consistency and code quality.
prettier-plugin-solidity

This is a work in progress Prettier Plugin for Solidity.
Installation and usage
Install both prettier
and prettier-plugin-solidity
:
npm install --save-dev prettier prettier-plugin-solidity
You can add a script for running prettier on all your contracts:
"prettier": "prettier --write **/*.sol"
Or you can use it as part of your linting to check that all your code is prettified:
"lint": "prettier --list-different **/*.sol"
Contributing
- Fork it
- Create your feature branch (
git checkout -b feature/fooBar
)
- Commit your changes (
git commit -am 'Add some fooBar'
)
- Push to the branch (
git push origin feature/fooBar
)
- Create a new Pull Request
License
Distributed under the MIT license. See LICENSE for more information.