Welcome to OGeek Q&A 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 Reply

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...