Solidity 0.5.X is here with a lot of features and breaking changes. Making all the changes to your solidity code manually, especially adding the explicitness requirements can be really cumbersome (and boring) for large projects. This is why I decided to make a codemod for Solidity that does most of the work for you. It’s still under testing and is buggy but it gets the job done for the most part. You may see its magic in the underworks polymath-core repo branch.
The plugin is based on the solidity prettier plugin that extends the features of prettier, a well-known code formatter. It is available as an NPM package and the source code is hosted on GitHub.
Features
The plugin has the following features:
- Change solidity pragma version to
^0.5.0. - Add
calldatastorage keyword toexternalfunction complex parameters like arrays that lack an already defined storage location. - Add
memorystorage keyword to public, private and internal complex parameters that don’t already have a defined parameter storage location. - Rename constructor function definition from
function ContractNametoconstructor. - Add default function visibility of
publicto those functions which don’t have function visibility explicitly defined. - Add function visibility of
externalto fallback functions and all functions of any interface. - Convert
constantfunction state mutability modifier toview. - Prettify your code using prettier.
Usage
Using this plugin is very straightforward and only requires two simple commands:
Firstly, you need to install the npm plugin vianpm install --save-dev prettier prettier-plugin-solidity-refactorSecondly, you need to execute the plugin using
./node_modules/.bin/prettier --write --tab-width 4 --print-width 140 '**/*.sol'
More detailed usage instructions and information is available on the GitHub repo.
Feel free to play around with the plugin and let me know if you find any bug. Refactoring your solidity code should be less boring now 🙂
Disclaimer
Remember that this plugin is still in testing and lacks a few features. Nevertheless, it should save a decent chunk of time if you are planning on refactoring your code. Read more about its limitations and known bugs on GitHub and always manually verify all your code. I won’t be liable if your cat loses one of their live or the ethereum blockchain hangs due to the use of this plugin :).