New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no-invalid-this: add switch for function name based heuristic #12271
no-invalid-this: add switch for function name based heuristic #12271
Comments
Seems reasonable to me, a project can have a different convention for capitalized functions and not have 'ES5' constructor functions at all. |
I'm willing to champion this, but it still needs one more 👍 from the team. The name of the option could be |
I removed my vote to avoid confusion, as the issue needs 3 👍 from other members to be accepted. To illustrate the idea, the following would be an error in strict mode (e.g., in a module): /* eslint no-invalid-this: ["error", { "capIsConstructor": false }] */
function Hello() {
const { foo } = this.state; // Error: Unexpected 'this'
} Setting the option to |
It's okay even if you don't remove your vote. Because 👍 on GitHub issues includes votes from the community, it's hard to count votes from the team on issues. Instead, we can check champion and supporters from the team in https://github.com/mysticatea/eslint-evaluating-issues#readme. |
I'm working on this. |
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 text was updated successfully, but these errors were encountered: