no-underscore-dangle
UnreleasedConfiguration
Rule Details
This rule disallows dangling underscores in identifiers — an underscore at the beginning or the end of a name, such as _foo or foo_. A name that is exactly _ is always allowed.
By default the rule checks variable declarations, function declaration names, and member access. Function parameters, destructured names, method names, and class field names are each governed by an option.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Options
This rule has an object option:
"allow"— a list of identifiers that may have dangling underscores"allowAfterThis": false(default) — disallows dangling underscores in members of thethisobject"allowAfterSuper": false(default) — disallows dangling underscores in members of thesuperobject"allowAfterThisConstructor": false(default) — disallows dangling underscores in members of thethis.constructorobject"enforceInMethodNames": false(default) — allows dangling underscores in method names"enforceInClassFields": false(default) — allows dangling underscores in class field names"allowInArrayDestructuring": true(default) — allows dangling underscores in names bound by array destructuring"allowInObjectDestructuring": true(default) — allows dangling underscores in names bound by object destructuring"allowFunctionParams": true(default) — allows dangling underscores in function parameter names
allow
Examples of additional correct code for this rule with the { "allow": ["foo_", "_bar"] } option:
allowAfterThis
Examples of correct code for this rule with the { "allowAfterThis": true } option:
allowAfterSuper
Examples of correct code for this rule with the { "allowAfterSuper": true } option:
allowAfterThisConstructor
Examples of correct code for this rule with the { "allowAfterThisConstructor": true } option:
enforceInMethodNames
Examples of incorrect code for this rule with the { "enforceInMethodNames": true } option:
enforceInClassFields
Examples of incorrect code for this rule with the { "enforceInClassFields": true } option:
allowInArrayDestructuring
Examples of incorrect code for this rule with the { "allowInArrayDestructuring": false } option:
allowInObjectDestructuring
Examples of incorrect code for this rule with the { "allowInObjectDestructuring": false } option:
Examples of correct code for this rule with the { "allowInObjectDestructuring": false } option:
allowFunctionParams
Examples of incorrect code for this rule with the { "allowFunctionParams": false } option:
TypeScript
A member that only declares a signature has no implementation to name, so it is never reported: overload signatures, declare function, and abstract class members. The implementation that follows is checked as usual.
A constructor parameter that also declares a property — one marked private, protected, public, readonly, or override — is exempt from allowFunctionParams.
When Not To Use It
If you want to allow dangling underscores in identifiers, then you can safely turn this rule off.