Quality VPS and Dedicated Servers at Incredible Prices

Ethereum: Prettier not detecting solidity

Here is a draft article based on your description:

Ethereum: Prettier Doesn’t Recognize Solidity

As developers, we rely heavily on tools to improve the quality of our code. One such tool is Prettier, a popular JavaScript formatter that can automatically format and edit our code for better readability. However, one of the extensions that Prettier uses, “solidity”, causes formatting issues when developing Ethereum.

Problem

Ethereum: Prettier not detecting solidity

In my experience, I have had to install and reinstall the Solidity extension and Prettier itself several times. However, the problem persists. The “solidity” command from my project always outputs a different format than what the code would look like if it were formatted using Prettier.

Problem

I noticed that when I run the “solidity –format” command in the terminal of my project, I get the following output:

pragma solidity ^ 0,8,10; // pragma: // comment

contract MyContract {

uint256 public counter;

}

However, running with Prettier installed and properly configured gives a different result:

pragma solidity ^ 0,8,11;

contract MyContract {

uint256 public counter;

}

Solution

After trying various solutions, I found the following solutions to this problem:

  • Remove and reinstall Solidity extension: I have asked several times to remove and reinstall the “solidity” extension. This solution seems to work in some cases, but it is not reliable.
  • Reinstall Prettier with custom configurations: I have tried reinstalling Prettier with custom configurations for JavaScript and Solidity files. However, this also does not seem to provide a permanent solution.
  • Set Prettier as an option: One solution is to set Prettier as an option when you run the solidity command. You can do this by adding the following code to your .bashrc or .zshrc file:

export PATH="$PATH:$HOME/.config/nvm/v0.51.9/bin:$HOME/.nvm/lib/$NVM_VERSION/bin"

source $HOME/.nvm/nvm-sh/bash

npm install --global prettier

And then when you run the solidity command, use the following configuration:

solidity --format=.js solidity.js

Conclusion

In conclusion, Prettier seems to work fine with TypeScript projects, but its Solidity formatting is not working. After trying various solutions, I found that reinstalling the Solidity extension and setting Prettier as an option can provide a temporary solution.

However, this solution has its limitations and it is recommended to explore other alternatives or configure Prettier in a way that suits your specific use case.

Tips and Options

  • If you are using a different IDE or text editor, such as WebStorm or VS Code, the configuration parameters may differ. Be sure to check the documentation for your chosen tool.
  • You can also try installing thesolidity` extension separately from Prettier and configuring it manually.
  • In some cases, you may need to use a different version of the Solidity or Ethereum libraries that are not supported by Prettier.

Hope this helps! If you have any further questions or need further assistance, please feel free to ask.