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

rules.jshint.W032.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

    

When do I get this error?

The "Unnecessary semicolon" error is thrown when JSHint or ESLint encounters a semicolon following a block statement or function declaration. In the following example we mistakenly include a semicolon after an if statement body (which is a block statement), and another after a function declaration:

x
 
1
function example(a) {
2
    "use strict";
3
    if (a) {
4
        return true;
5
    };
6
};
7
JSHint found 2 errorsVersion 2.9.0
Line 5:Unnecessary semicolon.
Line 6:Unnecessary semicolon.

Why do I get this error?

This error is raised to highlight a pointless piece of code. Semicolons are not required after block statements or function declarations. The specification makes it clear where semicolons are necessary. For example, here's the grammar for variable declarations (ES5 §12.2):

VariableStatement :
    var VariableDeclarationList ;

The semicolon is clearly required by this production. Now compare that to the grammar for a block statement (ES5 §12.1):

Block :
    { StatementListopt }

This time there is no semicolon which means its safe to remove the extra semicolons from the previous example. This will resolve the issue:

7
 
1
function example(a) {
2
    "use strict";
3
    if (a) {
4
        return true;
5
    }
6
}
7
JSHint found no errorsVersion 2.9.0

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 W032. This means you can tell JSHint to not issue this warning with the /*jshint -W032 */ directive.

In ESLint the rule that generates this warning is named no-extra-semi. You can disable it by setting it to 0, or enable it by setting it to 1.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy