Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforce jsx to start on new line if jsx is multiline

What eslint rule would prefer the former over the second when the jsx spans multiple lines? Currently prettier is changing preferred to notPreferred

const preferred = (
    <tag
        prop={hi}
        another={test}
    \>
);

const notPreferred = (<tag
        prop={hi}
        Another={test}
    \>
);
like image 405
user3916570 Avatar asked Jun 21 '19 14:06

user3916570


1 Answers

I was looking for the same, it seems that react/jsx-wrap-multilines rule covers that.

This means adding:

"react/jsx-wrap-multilines": ["error", {
   "declaration": "parens-new-line",
    "assignment": "parens-new-line",
    "return": "parens-new-line",
    "arrow": "parens-new-line",
    "condition": "parens-new-line",
    "logical": "parens-new-line",
    "prop": "parens-new-line"
  }
]

This does the job, and you can customize it in multiple ways, take a look at the documentation 👍

like image 169
mloureiro Avatar answered Nov 10 '22 05:11

mloureiro