NomicFoundation / hardhat-vscode

Solidity and Hardhat support for Visual Studio Code
https://hardhat.org
MIT License
174 stars 43 forks source link

explicitTypes parameter does not work when format solidity file #367

Closed gzliudan closed 1 year ago

gzliudan commented 1 year ago

When I use hardhat-vscode to format solidity contract codes, the uint type can not become uint256 automatically.


file .prettierrc.js:

module.exports = {
  bracketSpacing: true,
  semi: true,
  singleQuote: true,
  trailingComma: 'es5',
  overrides: [
    {
      files: '*.sol',
      options: {
        bracketSpacing: true,
        explicitTypes: 'always',
        printWidth: 120,
        singleQuote: false,
        tabWidth: 4,
        useTabs: false,
      },
    },
  ],
};

file .vscode/settings.json

{
  "editor.codeActionsOnSave": {
    "source.fixAll": true
  },
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "editor.renderControlCharacters": true,
  "editor.renderWhitespace": "all",
  "editor.tabSize": 4,
  "files.autoSave": "afterDelay",
  "files.autoSaveDelay": 5000,
  "[solidity]": {
    "editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
  }
}

fvictorio commented 1 year ago

Hey @gzliudan, the explicitTypes option was removed from Prettier Solidity in v1.0.0, that's why this is not working for you.

I think solhint will eventually have a rule (with auto-fix) for this, which should be enough to fill this use case. But that's outside of the scope of the hardhat-vscode plugin.

gzliudan commented 1 year ago

According to #456, this issue seems can be solved by:

VSCode settings

{
  "[solidity]": {
    "editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
  },
  "solidity.formatter": "forge"
}

and foundry.toml

[fmt]
  int_types = "long"