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

rules.jshint.W105.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 "Unexpected dangling '_' in '{a}'" error is thrown when JSLint, JSHint or ESLint encounters an identifier that begins or ends with the underscore character. JSHint will only raise this warning when the nomen option is set to true. ESLint only raises this warning for variable and function identifiers and not for object property identifiers. In the following example we use several such identifiers:

x
 
1
/*jshint nomen: true */
2
var _x = 10,
3
    y = {
4
        z_: 20
5
    };
6
7
function _test() {
8
    "use strict";
9
    return true;
10
}
11
JSLint found 1 errorVersion 2015-09-23
Line 3:Bad property name 'z_'.

Why do I get this error?

This error is raised to highlight a lack of convention. Your code will run without error if you do not change it, but could be confusing to other developers, and could also indicate a lack of understanding of the language.

Identifiers prefixed with the underscore character are often used to indicate a private variable. Since JavaScript doesn't have a real notion of "private", this can be misleading.

If you're using JSLint, you can fix the error by setting the nomen (short for nomenclature) option to true. Conversely, if you're using JSHint, you can simply remove the same option:

11
 
1
/*jslint nomen: true */
2
var _x = 10,
3
    y = {
4
        z_: 20
5
    };
6
7
function _test() {
8
    "use strict";
9
    return true;
10
}
11
JSLint found 2 errorsVersion 2015-09-23
Line 0:Bad option 'nomen'.
Line 3:Bad property name 'z_'.

Alternatively, you can simply remove the underscore character from the start or end of your identifiers (note that use of this character elsewhere in identifiers is accepted):

11
 
1
/*jshint nomen: true */
2
var x = 10,
3
    y = {
4
        z: 20
5
    };
6
7
function test_with_underscores() {
8
    "use strict";
9
    return true;
10
}
11
JSLint found no errorsVersion 2015-09-23

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy