javascript - VSCode is auto-formatting multiline to one line code - Stack Overflow

I like auto-formatting code idea very much. You can use eslint rules to configure code style you like.

I like auto-formatting code idea very much. You can use eslint rules to configure code style you like. But some hidden rule makes what I don't like: inlines document destruction props or jsx template element attributes.

Example (this is how I want it to be).

const {
  foo: 1,
  bar: 2,
  baz: 3,
} = require('qux')

And here is how it is reformatted by VSCode or some its plugin (not sure)

const { foo: 1, bar: 2, baz: 3 } = require('qux')

It is absolutely OK in case it is reformatted back to multiline when the line lenth exceeds some specified limit.

JSX examples (tried with a new project generated with use of react-create-app).

  1. OK, it would be too long line, thus VSCode re-formats it to multiline

    <a
      className="App-link"
      href=""
      target="_blank"
      rel="noopener noreferrer"
    >
    
  2. Line length wouldn't be longer than allowed, but I still love this style

    <a
      className="App-link"
      href=""
    >
    
  3. But VSCode/plugin has a different preference and reformats it to

    <a className="App-link" href="">
    

I tried to find a specific eslint rule which would be responsible for this behavior, but with no luck (not found). I tried to change default vscode formatter from prettier to null - no luck.

One more strange thing for me: VSCode doesn't highlights such code snippets which it is going to reformat.

So how can it be fixed?

UPDATE

The only thing I want VSCode to do within such code parts, is just breaking one line to multiline in case the line exceeds eslint max-len value.

I like auto-formatting code idea very much. You can use eslint rules to configure code style you like. But some hidden rule makes what I don't like: inlines document destruction props or jsx template element attributes.

Example (this is how I want it to be).

const {
  foo: 1,
  bar: 2,
  baz: 3,
} = require('qux')

And here is how it is reformatted by VSCode or some its plugin (not sure)

const { foo: 1, bar: 2, baz: 3 } = require('qux')

It is absolutely OK in case it is reformatted back to multiline when the line lenth exceeds some specified limit.

JSX examples (tried with a new project generated with use of react-create-app).

  1. OK, it would be too long line, thus VSCode re-formats it to multiline

    <a
      className="App-link"
      href="https://reactjs"
      target="_blank"
      rel="noopener noreferrer"
    >
    
  2. Line length wouldn't be longer than allowed, but I still love this style

    <a
      className="App-link"
      href="https://reactjs"
    >
    
  3. But VSCode/plugin has a different preference and reformats it to

    <a className="App-link" href="https://reactjs">
    

I tried to find a specific eslint rule which would be responsible for this behavior, but with no luck (not found). I tried to change default vscode formatter from prettier to null - no luck.

One more strange thing for me: VSCode doesn't highlights such code snippets which it is going to reformat.

So how can it be fixed?

UPDATE

The only thing I want VSCode to do within such code parts, is just breaking one line to multiline in case the line exceeds eslint max-len value.

Share Improve this question edited Mar 28, 2020 at 21:43 user13142267 asked Mar 27, 2020 at 14:27 humkinshumkins 10.8k12 gold badges64 silver badges79 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

If you have prettier configured. Did you try the prettier.printWidth property here

{
  "prettier.printWidth": 80
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744776538a4593078.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信