All Downloads are FREE. Search and download functionalities are using the official Maven repository.

rules.jshint.W090.html Maven / Gradle / Ivy

Go to download

Consume reports generated by jshint for code quality. Also consume reports for code duplication (either simian or cpd). Consumes the unit/integration tests reports (generated by Jasmin) coverage report (lcov generated by Istanbul). The information generated by reports are added in Sonar

There is a newer version: 2.1.0
Show newest version

    

History

This warning has existed in three forms across the three main linters. It was introduced in the original version of JSLint and has remained (in a way) in all three tools ever since.

  • In JSLint the warning given is "'{a}' is not a label"

  • In JSHint the warning given has always been "'{a}' is not a statement label"

  • In ESLint the Esprima parser fails to parse the code so the message given matches the V8 engine error "Undefined label '{a}'"

The situations that produce the warning have not changed despite changes to the text of the warning itself.

When do I get this error?

The "'{a}' is not a label" error, and the alternatives "'{a}' is not a statement label" and "Undefined label '{a}'", is thrown when JSLint, JSHint or ESLint encounters a break or continue statement referencing a label that does not exist. In the following example we try to break out of a for loop to the non-existent example label:

x
 
1
function demo() {
2
    "use strict";
3
    var i;
4
    for (i = 0; i < 10; i += 1) {
5
        if (i === 5) {
6
            break example;
7
        }
8
    }
9
}
10
JSLint found 2 errorsVersion 2015-09-23
Line 3:Unexpected 'for'.
Line 5:'example' is not a label.

Why do I get this error?

This error is raised to highlight a fatal JavaScript syntax error. It is not valid to reference an identifier that does not appear in the label set of the enclosing statement. This is stated in the ECMAScript 5 specification (section §12.7 and section §12.8):

A program is considered syntactically incorrect if...

  • ...
  • The program contains a break statement with the optional Identifier, where Identifier does not appear in the label set of an enclosing [statement]

In the snippet above, the for statement has not been explicitly labelled, and therefore there is no label in its label set with the identifier example. When the interpreter reaches the break statement a syntax error will be thrown. This can be avoided by removing the identifier from the break statement:

10
 
1
function demo() {
2
    "use strict";
3
    var i;
4
    for (i = 0; i < 10; i += 1) {
5
        if (i === 5) {
6
            break;
7
        }
8
    }
9
}
10
JSLint found 1 errorVersion 2015-09-23
Line 3:Unexpected 'for'.

Or alternatively by adding a label with the correct identifer to the label set of the for statement (although since November 2013 this will cause JSLint to raise a different warning, because it is now of the opinion that label statements should not be used at all):

11
 
1
function demo() {
2
    "use strict";
3
    var i;
4
example:
5
    for (i = 0; i < 10; i += 1) {
6
        if (i === 5) {
7
            break example;
8
        }
9
    }
10
}
11
JSLint found 1 errorVersion 2015-09-23
Line 4:Unexpected 'for'.

In JSHint 1.0.0 and above you have the ability to ignore any warning with a special option syntax. The identifier of this warning is W090. This means you can tell JSHint to not issue this warning with the /*jshint -W090 */ directive.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy