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

unexpected indent behaviour in multiline boolean expression in 4.x #8914

Closed
pavelkucera opened this issue Jul 10, 2017 · 2 comments
Closed
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly indent Relates to the `indent` rule rule Relates to ESLint's core rules

Comments

@pavelkucera
Copy link

Tell us about your environment

  • ESLint Version: 4.2.0
  • Node Version: 8.1.3
  • npm Version: 5.0.3

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

Please show your full configuration:

Configuration
{
    "parser": "babel-eslint",
    "env": {
        "es6": true,
        "node": true
    },
    "rules": {
        "indent": [
            "error",
            4,
            {
                "SwitchCase": 1,
                "MemberExpression": 1
            }
        ]
    }
}

What did you do? Please include the actual source code causing the issue.

const skip = (request, response) => {
    return first
        || (
            second
            && third
        );
};

What did you expect to happen?
I expected the code to pass the indent rule with given configuration.

What actually happened? Please include the actual, raw output from ESLint.

/…/src/index.js
  5:1  error  Expected indentation of 8 spaces but found 12  indent
  7:1  error  Expected indentation of 4 spaces but found 8   indent

However, the proposed fix looks rather odd

const skip = (request, response) => {
    return first
        || (
        second // no indentation here?
            && third // inconsistent indentation of the first and second part of the condition
    ); // inconsistent indentation of the opening and closing brace
};

Is this intended behaviour? Thank you.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jul 10, 2017
@not-an-aardvark
Copy link
Member

not-an-aardvark commented Jul 10, 2017

Thanks for reporting, this seems like a bug to me. It was probably introduced in #8719, which means it has been present since 4.1.0.

As a workaround, the rule won't complain if you do this:

const skip = (request, response) => {
    return first
    || (
        second
        && third
    );
};

or this:

const skip = (request, response) => {
    return first ||
        (
            second
            && third
        );
};

@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly indent Relates to the `indent` rule rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jul 10, 2017
@not-an-aardvark not-an-aardvark self-assigned this Jul 11, 2017
not-an-aardvark added a commit that referenced this issue Jul 12, 2017
This fixes an issue where the indentation of the right-hand side of a `BinaryExpression` did not depend on the indentation of the operator. This could result in a situation where the rule would verify the absolute indentation of a node within the BinaryExpression, rather than the relative indentation from the operator.
@pavelkucera
Copy link
Author

Thank you a lot for a quick fix!

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly indent Relates to the `indent` rule rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

3 participants