Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

solidity - Weird behaviour with prettier in VS Code

So Prettier is behaving quite weirdly for me. I have this simplified interface in a language called solidity:

interface Token {
  function getTotalSupply(address _market, TokenType _tokenType) external view returns (uint256);
  function mint(address _to, uint256 _amount, TokenType _tokenType) external;
}

After formatting it gets formatted to this:

interface Token {
  function getTotalSupply(address _market, TokenType _tokenType) external view returns (uint256);

  function mint(
    address _to,
    uint256 _amount,
    TokenType _tokenType
  ) external;
}

I want both functions to stay on one line. The printWidth option does not seem to be the issue here, as the first function is actually longer than the second one and does not line break. The difference seems to be that the second function has more arguments and that every function with more than 2 arguments gets split up. Here is my .prettierrc

{
  "overrides": [
    {
      "files": "*.sol",
      "options": {
        "printWidth": 160,
        "tabWidth": 4,
        "useTabs": false,
        "singleQuote": false,
        "bracketSpacing": false,
        "explicitTypes": "always"
      }
    }
  ]
}

How can I fix this?

question from:https://stackoverflow.com/questions/65876455/weird-behaviour-with-prettier-in-vs-code

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This looks fine to me. Do you have your .Prettierrc file in the root, and did you reload/restart after setting it up?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...