Skip to content

noDanglingUnderscore (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noDanglingUnderscore": "error"
}
}
}
}

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._id or this._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 as this.#_count.
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() {}
}