Package Exports
- prettier-plugin-solidity-refactor
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (prettier-plugin-solidity-refactor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Solidity Upgrade
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
calldata
storage keyword infront ofexternal
function complex parameters andmemory
infront of other function's complex parameters that don't already have a defined parameter storage location. - Rename constructor function from
function ContractName
toconstructor
. - Add default function visibility of
public
to those normal functions which don't have function visibility explicitly defined. - Add function visibility of
external
to fallback functions and all functions of inteface. - Convert
constant
function visibility toview
. - Prettify your code using prettier.
Installation
Install both prettier
and prettier-plugin-solidity-refactor
:
npm install --save-dev prettier prettier-plugin-solidity-refactor
OR
yarn add --dev prettier prettier-plugin-solidity-refactor
Usage
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
payable
to addresses as it can not detect which addresses require to be payable. If you are usingaddressA.send
oraddressA.transfer
, please manually declare them asaddress payable addressA
rather thanaddress addressA
. - This tool is still under early testing. Please always manually verify all your contracts after using this tool. It might have unexpected side-effects.
Known bugs
- It does not work when the function body has only one comment and no statements.
TODO
- Add test cases.