PaulRBerg / foundry-template

Foundry-based template for developing Solidity smart contracts
MIT License
561 stars 110 forks source link

linter fails because prettier uses 2 spaces, fmt uses 4 spaces #10

Closed vmaark closed 1 year ago

vmaark commented 1 year ago

tab size is configured differently for sol in the 2 tools, causing the linter to fail, if prettier was used for formatting. editorconfig also sets indent size to 2.

PaulRBerg commented 1 year ago

This is not an issue with the template itself. You can refer to the Formatter section of the "Integrating with Foundry" guide of the Foundry Book for how to configure VSCode to not run Prettier on Solidity files. In short, you have to add this to your VSCode settings:

"[solidity]": {
  "editor.defaultFormatter": "JuanBlanco.vscode-solidity" 
},
vmaark commented 1 year ago

That may be true, but it would still be better not to use different values for tabwidth.

PaulRBerg commented 1 year ago

This is a good point! Let me think about it - really the only reason for keeping 2 spaces for tab width is formatting for JSON files. I might just add an override for *.json and set the default to 4.

PaulRBerg commented 1 year ago

I ended up doing something else - I have kept the default tabWidth to 2 but I have also added an override for Solidity to use 4, like this:

overrides:
  - files: ["*.sol"]
    options:
      tabWidth: 4

Otherwise, I would have had to add quite a few overrides:

- files: ["*.json", "*.md", "*.yml"]

Even if Prettier is not run over Solidity files, this should make the template more robust for end users, since it will prevent accidental re-formatting when the VSCode settings are not configured on a per-language basis.

Thanks for opening this issue, @vmaark.