Search code examples
javascriptdestructuringprettier

How do I prevent code wrapping in Prettier / ESLint


I am struggling to find a setting in my Prettier / ESLint config which allows me to wrap my code like this:

var [
  first,
  second,
  third,
  etc,
] = data();

When I hit save, it always turns the code to this automatically:

var [first, second, third, etc] = data();

This may not be such a big problem with this simple demonstration, but with more complex destructuring, this one liner will get hard to read.

Thank you for your help!


Solution

  • In Eslint, you can enforce line breaks between array elements using option array-element-newline:

    Incorrect code:

    /*eslint array-element-newline: ["error", "always"]*/
    var d = [1, 2, 3];
    

    Correct code:

    /*eslint array-element-newline: ["error", "always"]*/
    var d = [1,
        2,
        3];
    

    You can also check out: