prettier-plugin-solidity-refactor
v1.0.0-alpha.14
Published
prettier plugin for solidity that refactors solidity 0.4.x code to solidity 0.5.x code
Maintainers
Readme
Solidity Refactor
This is a work in progress Prettier Plugin for Refactoring Solidity 0.4.X code to 0.5.X code. This tool does the following tasks currently to refactor your soldiity 0.4.X code to work with solidity 0.5.X:
- Change pragma version to
^0.5.0. - Add
calldatastorage keyword infront ofexternalfunction complex parameters andmemoryinfront of other function's complex parameters that don't already have a defined parameter storage location. - Rename constructor function from
function ContractNametoconstructor. - Add default function visibility of
publicto those normal 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.
Installation
Install both prettier and prettier-plugin-solidity-refactor:
npm install --save-dev prettier prettier-plugin-solidity-refactorOR
yarn add --dev prettier prettier-plugin-solidity-refactorUsage
This plugin allows you to configure prettier to your needs. Command with my personal config is
./node_modules/.bin/prettier --write --tab-width 4 --print-width 140 '**/*.sol'OR command with default config that will just print changed contracts to stdout instead of actually making chnages:
./node_modules/.bin/prettier '**/*.sol'You may add the command script to your package.json file and then use npm run scriptName to execute the command.
Known limitations
- It does not add
payableto addresses as it can not detect which addresses require to be payable. If you are usingaddressA.sendoraddressA.transfer, please manually declare them asaddress payable addressArather thanaddress addressA. - It does not redefine expired variables. In solidity 0.4.X, variables persisted even outside their scope but in soldiity 0.5.x, you need to define them again.
- It does not fix illegal implicit conversions.
- Low level
callnow returns 2 parameters rather than 1. This plugin does not rafactor it.
Known bugs
None. Please report the bugs you may find.
TODO
- Add test cases.
Contributions of any kind are welcome.
NOTE: This tool is still under early testing. Please always manually verify all your contracts after using this tool.
