Skip to content

no-invalid-this: add switch for function name based heuristic  #12271

@andidevi

Description

@andidevi
  • ESLint Version: 6.4.0
  • Node Version: 8.16.1
  • npm Version: 6.4.1

What parser (default, Babel-ESLint, etc.) are you using?
babel-eslint

What did you expect to happen?
Detect invalid this in functions with names with leading uppercase

What actually happened? Please include the actual, raw output from ESLint.
The rule no-invalid-this counts functions with leading uppercase in name as constructor.
There is no option to turn this heuristic of.

Reason
When writing React Components as a pure function one likes to keep the leading uppercase in the name. This will lead no-invalid-this to ignore uses of this in the pure function, which is a common error when refactoring call components to pure functions.

This is a request to add a switch to turn off the (documented) heuristic decision, that function is a constructor if

  • the name of the function starts with uppercase, or
  • the function is assigned to a variable which starts with an uppercase letter.

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionenhancementThis change enhances an existing feature of ESLintruleRelates 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