
rules.jshint.W105.html Maven / Gradle / Ivy
Show all versions of sonar-web-frontend-js Show documentation
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 */
2var _x = 10,
3 y = {
4 z_: 20
5 };
6
7function _test() {
8 "use strict";
9 return true;
10}
11
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 */
2var _x = 10,
3 y = {
4 z_: 20
5 };
6
7function _test() {
8 "use strict";
9 return true;
10}
11
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 */
2var x = 10,
3 y = {
4 z: 20
5 };
6
7function test_with_underscores() {
8 "use strict";
9 return true;
10}
11
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.