3

Hello everyone! Sorry for such a trivial question but after spending all day solving a pointless task I decided to ask smarter people 😅

The problem is simple.

I have a solidity extension by Juan Blanco in vscode for writing smart contracts. Writing smart contracts I noticed that it has some printWidth limits and if the line has more than 80-100 symbols it wraps into the next line. From the beginning, it looked OK but after a while, I realised that it's quite annoying because more than half of a file is just empty. enter image description here enter image description here

My settings in vscode for formatting.

enter image description here enter image description here enter image description here enter image description here

I even have .prettierignore file to ignore small printwidth just in case. enter image description here

But it still doesn't work.

The only variant when I can get normal formatting is to use format document(forced) in vscode enter image description here

And the result will be enter image description here

But after pressing ctrl+s it resets all formatting.

I hope I gave enough screens and info and I would be really grateful if you know how to solve such a simple problem because I gave up 😢

2
  • Did you ever get answer to this?
    – GGizmos
    Commented Oct 30, 2022 at 0:44
  • Nop, still waiting :D @GGzmos
    – AGJoYy
    Commented Oct 31, 2022 at 8:48

4 Answers 4

1

I had a lot of trouble getting Format on Save to work but eventually got it working using the following steps.

Install the following two extensions:-

Solidity By Juan Blanco

enter image description here

Prettier Code Formatter enter image description here

( I couldn't get the format on save to work with Solidity by the Nomic Foundation)

Then in settings (CTRL ,) type in

Format on Save

(Make sure you have this enabled if it isn't already)

enter image description here

Then still in settings type in

Solidity Formatter

Set it to Prettier Code Formatter (esbenp.prettier-vscode)

enter image description here

The final setting is changing Solidity Formatter to Prettier (default is none)

enter image description here

I had settings in .prettier and .settings and I just removed them and solidity files formatted when I hit save.

1

For me the problem was solved by using Forge formatter. You probably need to install Foundry and integrate it with your vscode IDE.

My vscode settings:

"editor.formatOnSave": true,
"[solidity]": {
    "editor.defaultFormatter": "JuanBlanco.solidity"
},
"solidity.formatter": "forge",

It does not break my long lines.

0

Here are my vscode settings that worked for the Hardhat Solidity Extension (also requires prettier):

{
  "editor.formatOnSave": true,
  "[solidity]": {
    "editor.defaultFormatter": "NomicFoundation.hardhat-solidity"
  },
  "solidity.formatter": "prettier"
}
0

I ran into the same problem. I tried the online solution, which was configuring ".setting.json", but it didn't work. But I happened to come across a way that works:

step 1: Install solidity and prettier plugins.

step 2: Configer the default formatter: prettier enter image description here

step 3: Create ".prettierrc" file in the project root, the content:

{
 "printWidth": 1000
}

Hope this helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.