question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react/jsx-curly-spacing "never" + Prettier - Incorrect removal of parentheses around multiline JSX

See original GitHub issue

UPDATE - 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-error

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:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jamesopticommented, Dec 11, 2019

UPDATE: 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
  ],
1reaction
brodybitscommented, Dec 11, 2019

I think someone should raise a PR to clarify this (docs page has an edit button).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found