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.

indent conflicts with react/jsx-closing-bracket-location

See original GitHub issue

Tell us about your environment

  • ESLint Version: 5.16
  • Node Version: 11.4.0
  • yarn Version: 1.9.4

What parser (default, Babel-ESLint, etc.) are you using? @tylescript-eslint/parser

Please show your full configuration:

.eslintrc:

module.exports = {
  env: {
    'jest/globals': true
  },
  extends: [
    'airbnb',
    'plugin:@typescript-eslint/recommended',
  ],
  globals: {
    'document': true,
    'window': true,
  },
  parser: '@typescript-eslint/parser',
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    project: './tsconfig.json',
  },
  plugins: ['@typescript-eslint', 'jest'],
  rules: {
    'indent': 'off',
    '@typescript-eslint/indent': [
      'error',
      2,
      {
        'ignoredNodes': ['JSXElement *'],
        'SwitchCase': 1,
      },
    ],
  },
  settings: {
    'import/extensions': [
      '.js',
      '.jsx'
    ],
    'import/resolver': {
      webpack: {
        config: 'webpack.common.js',
      }
    }
  },
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

  1. Clone this repo.
  2. run yarn
  3. run yarn build:dev

What did you expect to happen?

No errors. Aligning the closing bracket should not cause an indent error. I am stating that the indent rule should be ignored for JSX Elements. Note that indenting the closing bracket will conflict with the react/jsx-closing-bracket-location rule.

sampleComponent.jsx:

import React from 'react';

const SampleComponent = () => (
  <h
    custom-attr-one="1"
    custom-attr-two="2"
    custom-attr-three="3"
  > // <- causes failure
    custom header
  </h>
);

export default SampleComponent;

error:

ERROR in ./src/sampleComponent.jsx
Module build failed (from ./node_modules/eslint-loader/index.js):
Module failed because of a eslint error.

/Users/jemery/dev/typescript-eslint-debug/src/sampleComponent.jsx
  8:1  error  Expected indentation of 4 spaces but found 2  @typescript-eslint/indent

✖ 1 problem (1 error, 0 warnings)
  1 error and 0 warnings potentially fixable with the `--fix` option.

 @ ./src/index.jsx 4:0-48 5:27-42
 @ multi babel-polyfill ./src/index.jsx
error Command failed with exit code 2.

ESLint Demo

Are you willing to submit a pull request to fix this bug? Yes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Jul 10, 2019

What happens if you configure your ignored nodes to include JSXElement as well (not just JSXElement *)?

0reactions
andrewjrhillcommented, Oct 7, 2019

As suggested by OliverSieweke, the following "indent" configuration is working for me:

"rules": {
    "indent": ["error", 4, {"ignoredNodes": ["JSXElement", "JSXElement *"]}],
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "react/jsx-closing-bracket-location" in WebStorm
The closing bracket must be aligned with the opening tag (expected column 13) react/jsx-closing-bracket-location.
Read more >
eslint-plugin-react/README.md - UNPKG
The CDN for eslint-plugin-react. ... /jsx-closing-bracket-location.md) | Validate closing bracket location in JSX | ... Validate props indentation in JSX |.
Read more >
Airbnb React/JSX Style Guide
A mostly reasonable approach to React and JSX ... Follow these alignment styles for JSX syntax. eslint: react/jsx-closing-bracket-location ...
Read more >
eslint-plugin-react - npm
Start using eslint-plugin-react in your project by running `npm i ... jsx-closing-bracket-location, Enforce closing bracket location in JSX ...
Read more >
eslint/eslint - Gitter
... "react/jsx-closing-bracket-location": 0, "react/jsx-curly-spacing": 1, "react/jsx-indent-props": 0, "react/jsx-key": 1, "react/jsx-max-props-per-line": ...
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