M
M
meinhard2019-06-24 20:46:28
React
meinhard, 2019-06-24 20:46:28

Prettier - how to set each jsx attribute to be on a new line?

Actually, I set up a bunch of eslint + prettier for myself, everything works with one exception, in JSX all attributes of a tag are written on one line, but I would like each one on a new line:
How prettier formats now:

<li className={classNames} onMouseLeave={() => setMouseLeave(true)} onMouseEnter={() => setMouseLeave(false)}>

How should:
<li className={classNames} 
     onMouseLeave={() => setMouseLeave(true)} 
     onMouseEnter={() => setMouseLeave(false)}>

How to achieve this?
.prettierrc
{
    "singleQuote": true,
    "printWidth": 120,
    "tabWidth": 4,
    "semi": true,
    "trailingComma": "none",
    "jsxBracketSameLine": true,
    "arrowParens": "always",
    "bracketSpacing": true
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Proskurin, 2019-06-24
@Vlad_IT

There is a jsx-max-props-per-line rule in eslint with eslint-plugin-react . Set it up and use eslint's own autofix, or integrate eslint with prettier https://github.com/prettier/eslint-plugin-prettier https://github.com/prettier/prettier-eslint

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question