Undocumented Inconsistency of Warning Suppression #915

Closed
jonni83 opened this Issue Mar 12, 2013 · 1 comment

Projects

None yet

2 participants

@jonni83
jonni83 commented Mar 12, 2013

There seems to be an undocumented inconsistency with the way warnings are dealt with, when omitting them through an in-file directive. The documentation states "This syntax will disable all warnings with this code. Some warnings are more generic than others so be cautious." What it doesn't explicitly warn about is that the syntax is not scoped to the function, and it will affect all code after the comment, but not always the before.

To exemplify this, I've tried to suppress the "expected indentation" warning, W015, for a switch/case statement.

function blah() {
    /*jshint -W015*/
    var something;
    switch(something) {
        case 'thing1':
            break;
        case 'thing2':
            break;
    }
}
function blah2() {
    var something2;
    switch(something2) {
        case 'thing3':
            break;
        case 'thing4':
            break;
    }
}

In this example, with the comment within the first function, no warnings are omitted. However, if the comment is moved to the second function, the warnings do appear for the first function.

I have also tested this same behavior to be consistent with the "trailing whitespace" warning, W102. However, when testing with the "unused variable" warning, W098, the scope seemed to be global regardless to position in the code.

Is this a bug? Is this undocumented intentional functionality?

@valueof
Member
valueof commented Mar 12, 2013

Yes, this looks like a bug.

@valueof valueof added a commit that closed this issue May 1, 2013
@valueof valueof Make -WNNN pragma function scoped.
There's no reason for -WNNN pragma to behave differently from normal
option pragma.

Closes GH-915.
421cf94
@valueof valueof closed this in 421cf94 May 1, 2013
@jugglinmike jugglinmike added a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014
@valueof valueof Make -WNNN pragma function scoped.
There's no reason for -WNNN pragma to behave differently from normal
option pragma.

Closes GH-915.
0733873
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment