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

eslint reports max-depth for `else if` blocks. #1835

Closed
Raynos opened this issue Feb 14, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@Raynos
Copy link

commented Feb 14, 2015

When specifying max-depth I expected it to not complain about nested else if statements.

I would expect that max-depth would only complain when it's indented 4 times.

/*global require*/
/*eslint global-strict: [2, "always"], quotes: [2, "single"]*/

/*eslint max-depth: [2, 4]*/
'use strict';

var process = require('process');

function log(m) {
    process.stdout.log(m + '\n');
}

function foo(a) {
    if (a === 1) {
        log('1');
    } else if (a === 2) {
        log('2');
    } else if (a === 3) {
        log('3');
    } else if (a === 4) {
        log('4');
    } else if (a === 5) {
        log('5');
    } else if (a === 6) {
        log('6');
    }
}

var x = 3;
foo(x);

/*
    $ eslint test.js

    test.js
      21:11  error  Blocks are nested too deeply (5)  max-depth
      23:11  error  Blocks are nested too deeply (6)  max-depth

        ✖ 2 problems (2 errors, 0 warnings)
*/

Sounds like the fix would be to decrement the max depth counter on an else if statement.

cc @malandrew @jcorbin

@nzakas

This comment has been minimized.

Copy link
Member

commented Feb 14, 2015

Definitely looks like a bug.

@nzakas

This comment has been minimized.

Copy link
Member

commented Feb 20, 2015

Looking at this now.

@nzakas nzakas closed this in ab249e5 Feb 21, 2015

nzakas added a commit that referenced this issue Feb 21, 2015

Merge pull request #1855 from eslint/issue1835
Fix: Don't count else-if in max-depth (fixes #1835)

@eslint eslint bot locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.