noDanglingUnderscore (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.3 - Diagnostic Category:
lint/nursery/noDanglingUnderscore - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Inspired from
no-underscore-dangle
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noDanglingUnderscore": "error" } } }}Description
Section titled “Description”Disallow names that start or end with an underscore.
An underscore at the start or end of a name, as in _count or count_,
is often used to say that something is private and shouldn’t be used
outside of its own code. The underscore doesn’t change how the code
works: a property named _id can still be read and changed from
anywhere. Readers may wrongly assume the underscore has some meaning
to the language.
This rule reports:
- variable names, such as
const _count = 0; - names of function declarations, such as
function _init() {}; - property names written after a dot, such as
user._idorthis._count.
These names are allowed:
_on its own, which is often the name of a utility library;__proto__when written after a dot;- variables created by destructuring, such as
const { _id } = user; - function parameters and names of function expressions;
- names written where a class member or object key is declared, such as
class A { _reset() {} }; - private class members, whose names start with
#, such asthis.#_count.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”let _count = 0;code-block.js:1:5 lint/nursery/noDanglingUnderscore ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The name _count starts with an underscore.
> 1 │ let _count = 0;
│ ^^^^^^
2 │
ℹ An underscore at the start or end of a name is often used to mark something as private, but it doesn't change how the code works, so it can mislead readers.
ℹ Remove the underscore from the name. For a class member that must stay private, start its name with # instead.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
function init_() {}code-block.js:1:10 lint/nursery/noDanglingUnderscore ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The name init_ ends with an underscore.
> 1 │ function init_() {}
│ ^^^^^
2 │
ℹ An underscore at the start or end of a name is often used to mark something as private, but it doesn't change how the code works, so it can mislead readers.
ℹ Remove the underscore from the name. For a class member that must stay private, start its name with # instead.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
user._id;code-block.js:1:6 lint/nursery/noDanglingUnderscore ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The name _id starts with an underscore.
> 1 │ user._id;
│ ^^^
2 │
ℹ An underscore at the start or end of a name is often used to mark something as private, but it doesn't change how the code works, so it can mislead readers.
ℹ Remove the underscore from the name. For a class member that must stay private, start its name with # instead.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
this._count = 0;code-block.js:1:6 lint/nursery/noDanglingUnderscore ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The name _count starts with an underscore.
> 1 │ this._count = 0;
│ ^^^^^^
2 │
ℹ An underscore at the start or end of a name is often used to mark something as private, but it doesn't change how the code works, so it can mislead readers.
ℹ Remove the underscore from the name. For a class member that must stay private, start its name with # instead.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
let count = 0;const _ = require("underscore");const { _id } = user;function init(_options) {}const handler = function _handler() {};obj.__proto__;
class Counter { #count = 0; _reset() {}}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.