Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive react/jsx-indent when working with DoExpression #2199

Closed
Kenneth-KT opened this issue Mar 13, 2019 · 1 comment · Fixed by #2200
Closed

False positive react/jsx-indent when working with DoExpression #2199

Kenneth-KT opened this issue Mar 13, 2019 · 1 comment · Fixed by #2200

Comments

@Kenneth-KT
Copy link
Contributor

Kenneth-KT commented Mar 13, 2019

Description

Given eslint-plugin-react is used with babel's do-expressions proposal, it produces a false-positive react/jsx-indent error suggesting the user to indent one level more than needed if a JsxElement is the last statement in the DoExpression block. The JsxElement in the last statement is intended to be the return value of the DoExpression.

Environment

indentation 2 spaces
babel plugin '@babel/plugin-proposal-do-expressions'
eslint parser 'babel-eslint'
eslint plugin 'eslint-plugin-babel'
eslint rule no-unused-expressions: 0
eslint rule babel/no-unused-expressions: 2

Input code

import React from 'react';

const TestDoExpression = () => (
  <div>
    <div>1</div>
    {do {
      const num = 1 + 1;
      <div>{num}</div>;
    }}
    <div>3</div>
  </div>
);

export default TestDoExpression;

Expected outcome

No errors

Actual outcome

Error with message below:

/TestDoExpression.jsx
8:7  error  Expected indentation of 8 space characters but found 6  react/jsx-indent
Kenneth-KT added a commit to Kenneth-KT/eslint-plugin-react that referenced this issue Mar 13, 2019
Kenneth-KT added a commit to Kenneth-KT/eslint-plugin-react that referenced this issue Mar 13, 2019
Kenneth-KT added a commit to Kenneth-KT/eslint-plugin-react that referenced this issue Mar 13, 2019
@ljharb
Copy link
Member

ljharb commented Mar 17, 2019

Wrap it in parens?

Kenneth-KT added a commit to Kenneth-KT/eslint-plugin-react that referenced this issue Sep 29, 2019
… statement within a do expression (with tests)

Fixes jsx-eslint#2199.
Kenneth-KT added a commit to Kenneth-KT/eslint-plugin-react that referenced this issue Sep 29, 2019
… statement within a do expression (with tests)

Fixes jsx-eslint#2199.
Kenneth-KT added a commit to Kenneth-KT/eslint-plugin-react that referenced this issue Sep 30, 2019
… statement within a do expression (with tests)

Fixes jsx-eslint#2199.
@ljharb ljharb closed this as completed in 32e27b7 Oct 1, 2019
stefan-wullems pushed a commit to stefan-wullems/eslint-plugin-react that referenced this issue Nov 30, 2019
… statement within a do expression (with tests)

Fixes jsx-eslint#2199.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants