Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Undocumented Inconsistency of Warning Suppression #915

Closed
jonni83 opened this Issue · 1 comment

2 participants

@jonni83

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
Owner

Yes, this looks like a bug.

@valueof valueof closed this issue from a commit
@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
@jugglinmike jugglinmike referenced this issue from a commit in jugglinmike/jshint
@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
Something went wrong with that request. Please try again.