
rules.jshint.W032.html Maven / Gradle / Ivy
Show all versions of sonar-web-frontend-js Show documentation
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 1function example(a) {
2 "use strict";
3 if (a) {
4 return true;
5 };
6};
7
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 1function example(a) {
2 "use strict";
3 if (a) {
4 return true;
5 }
6}
7
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
.