Skip to content

allowAfterThisConstructor for no-underscore-dangle #11488

Closed
@sripberger

Description

@sripberger

Like many, I've been using the no-underscore-dangle method to enforce the style of prefixing "private" members with underscores. It's nice in that it flags anytime such properties are accessed, and the allowAfterThis and allowAfterSuper rules make possible to work with these properties inside a class.

I have found an additional case that would be nice to allow: when an instance method or constructor wants to invoke a "private" static method. To make this possible without having to disable the rule on a case-by-case basis, I'd like to add an option to allow underscore dangles when referencing properties on this.constructor.

What rule do you want to change?

no-underscore-dangle

Does this change cause the rule to produce more or fewer warnings?

Fewer, optionally.

How will the change be implemented? (New option, new default behavior, etc.)?

New option.

Please provide some example code that this change will affect:

var a = this.constructor.foo_;
this.constructor._bar();

What does the rule currently do for this code?

Produces the following warnings/errors:
Unexpected dangling '_' in 'foo_' Unexpected dangling '_' in '_bar'

What will the rule do after it's changed?
Allows suppression in this case, if new allowAfterThisConstructor option is set to true.

Are you willing to submit a pull request to implement this change?

Yes, will be creating it shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    archived due to ageThis issue has been archived; please open a new issue for any further discussionauto closedThe bot closed this issueenhancementThis change enhances an existing feature of ESLintevaluatingThe team will evaluate this issue to decide whether it meets the criteria for inclusionruleRelates to ESLint's core rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions