react/jsx-curly-spacing "never" + Prettier - Incorrect removal of parentheses around multiline JSX
See original GitHub issueUPDATE - Issue resolved
IMO this is not clear in the docs at all, but a second prettier extends was needed:
extends: [
'airbnb',
'plugin:fetch/recommended',
'plugin:prettier/recommended',
'prettier/react', // THIS OVERRIDES SPECIFIC REACT RULES THAT CONFLICT WITH PRETTIER
],
Issue
The error I’m encountering only manifests when the following react rule is enabled:
'react/jsx-curly-spacing': ['error', 'never', { allowMultiline: true }],
The playground below shows Prettier by itself formatting correctly. When the above react rule is added, the error presents itself.
Prettier 1.16.4 Playground link
--jsx-bracket-same-line
--parser babel
➡️ Input:
function App() {
return (
<div
className="flex"
activator={ (
<div>
my really long divvvvvvvvvvvvvvvvvvvv
<span>some child</span>
</div>
) }>
My app
</div>
);
}
❌ Output (with react/jsx-curly-spacing
“never”): Opening paren remains, causing compile error
function App() {
return (
<div
className="flex"
activator={(
<div>
my really long divvvvvvvvvvvvvvvvvvvv
<span>some child</span>
</div>
}
>
My app
</div>
);
}
✅ Output (with react/jsx-curly-spacing
“always”):
function App() {
return (
<div
className="flex"
activator={
<div>
my really long divvvvvvvvvvvvvvvvvvvv
<span>some child</span>
</div>
}>
My app
</div>
);
}
Expected behavior:
With the react/jsx-curly-spacing
“never” setting, the parentheses should be removed correctly, as seen in the 2nd ✅ output example.
Here is a GIF to show this as well:
ESLint Config
module.exports = {
env: {
browser: true,
es6: true,
},
extends: [
'plugin:react/recommended',
'plugin:prettier/recommended'
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly'
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
},
plugins: [
'react',
'prettier'
],
rules: {
'react/jsx-curly-spacing': ['error', 'never', { allowMultiline: true }], // ERROR
'react/jsx-curly-spacing': ['error', 'always', { allowMultiline: true }], // OK
'prettier/prettier': 'error'
},
};
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Delete `(` eslint (prettier/prettier) - Stack Overflow
I have a conflict of rules. When I include parentheses around multiline JSX, the prettier reports a error Delete ...
Read more >Options - Prettier
Print trailing commas wherever possible in multi-line comma-separated syntactic structures. (A single-line array, for example, never gets trailing commas.).
Read more >Configuring Prettier and Eslint Plugins for React From Scratch
Today we are going to configure the prettier and eslint plugins for a React ... react/jsx-wrap-multilines, Prevent missing parentheses around multilines JSX ......
Read more >ESLint | John Vincent
This ESLint discussion is an addition to Visual Studio Code. ESLint. ESLint · ESLint Rules · ESLint User Guide. Prettier. Prettier.
Read more >@thibaudcolas/eslint-plugin-cookbook - Package Manager
Changelog. All notable changes to this project will be documented in this file. The format is based on Keep a Changelog and this...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
UPDATE: IMO this is not clear in the docs at all, but a second prettier extends was needed:
I think someone should raise a PR to clarify this (docs page has an edit button).