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

[Fix] jsx-indent-props: Reset line.isUsingOperator correctly after ternary (#3146) #3157

Merged
merged 1 commit into from Dec 22, 2021

Conversation

tobiaswaltl
Copy link

Closes #3146

When having a JSX element after a ternary and there are not only spaces before the opening bracket (e.g. due to a return keyword) line.isUsingOperator is not reset correctly and the rule enforces a higher indent.

Example:

export const LintExample2 = () => {
  const foo = true
    ? <div id="id">test</div>
    : false;

  return <div
    id="id" // linter complains: ESLint: Expected indentation of 6 space characters but found 4.(react/jsx-indent-props)
  >
    test
  </div>;
};

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking at the test cases, this doesn't seem right.

tests/lib/rules/jsx-indent-props.js Show resolved Hide resolved
tests/lib/rules/jsx-indent-props.js Show resolved Hide resolved
@@ -153,7 +153,7 @@ module.exports = {

const indent = regExp.exec(src);
const useOperator = /^([ ]|[\t])*[:]/.test(src) || /^([ ]|[\t])*[?]/.test(src);
const useBracket = /^([ ]|[\t])*[<]/.test(src);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add some test cases that use tabs, since that's what's being removed here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've added them.

@codecov-commenter
Copy link

codecov-commenter commented Dec 22, 2021

Codecov Report

Merging #3157 (3db5285) into master (d56fdb8) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3157   +/-   ##
=======================================
  Coverage   97.51%   97.51%           
=======================================
  Files         119      119           
  Lines        8130     8130           
  Branches     2895     2895           
=======================================
  Hits         7928     7928           
  Misses        202      202           
Impacted Files Coverage Δ
lib/rules/jsx-indent-props.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d56fdb8...3db5285. Read the comment docs.

@ljharb ljharb merged commit 3db5285 into jsx-eslint:master Dec 22, 2021
@tobiaswaltl tobiaswaltl deleted the pr-3146 branch December 29, 2021 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

jsx-indent-props: Enforcing incorrect indents when using a component with props in ternary before
3 participants