Comments (6)
@jrr This is a solid suggestion 👍 Initially, I went with the approach eslint-plugin-react-hooks
introduced to have everything under one rule.
It can be changed, though. I will consider splitting the rule into multiple ones with lesser individual scopes
Out of curiosity, what is your use case for enabling hooks in regular functions? 😄
from tslint-react-hooks.
Initially I'd like to set all the rules I'm already in compliance with to "error"
, and then put the rest on "warning"
until we get around to fixing them.
For this particular rule, though, there may be some places we'll never comply, and think it's Probably Okay. For example, when we need to call a hook from tests or storybook, which make heavy use of lambdas.
from tslint-react-hooks.
I gave some thought into this issue. Having multiple rules means that the parser and rule logic would have to be invoked multiple times due to the limitations of TSLint. One walker cannot report violations of multiple rules.
This can still be achieved, it's just that the performance may be worse than when having a single rule with controllable options.
How about adding options to a single react-hooks-nesting
rule? Then, you would be able to allow using hooks in any function. The configuration could be as follows:
"react-hooks-nesting": {
"severity": "error",
"options": {
"allow-using-hooks-in-all-functions": true
}
}
That would make the rule walker ignore violations connected with checking the function's name.
What do you think? Would that be sufficient?
from tslint-react-hooks.
Thanks for looking into this!
Having multiple rules means that the parser and rule logic would have to be invoked multiple times due to the limitations of TSLint. One walker cannot report violations of multiple rules.
Yikes, that's disappointing. Do you happen to know if ESLint (with the ts parser) has this limitation?
Your proposal would unblock me on this issue, but doesn't help with the general goal of granularly tightening rules, gradually over time.
I wouldn't bother unless anyone else is clamoring for it; I'll probably just keep severity set to warning, suppress in source code, and/or try my luck with ESLint.
from tslint-react-hooks.
I think I might have worded that incorrectly. I meant that the walker and rule logic would have to be invoked multiple times. The parser runs once and parses the file into an AST that is then provided to every rules' walkers.
Still, the walker (the class that explores the AST) has to once for every rule and for every CallExpression
(essentially for every function call in a file) has to check whether it is a hook call and check its ancestors to determine if it is inside a switch etc.
This is not as bad as running the parser multiple times but still adds some overhead compared to a single rule with one walker that reports violations conditionally, based on the options.
I wouldn't bother unless anyone else is clamoring for it; I'll probably just keep severity set to warning, suppress in source code, and/or try my luck with ESLint.
Sure, I will consider splitting it into multiple rules in the future, but currently, I do not have the time to implement it.
I heard create-react-app
wants to use ESLint with the TS parser when using Typescript, so trying ESLint may be a solid idea 👍 For more information on this, take a look at facebook/create-react-app#5641
from tslint-react-hooks.
Closing because the world has moved on to eslint.
from tslint-react-hooks.
Related Issues (18)
- Early return? HOT 16
- Report error in nextjs file HOT 1
- Rule reports false positive for anonymous component returned from a function HOT 6
- Not warning about custom hooks as properties HOT 2
- Provide support for .tsx files HOT 4
- Detect use of useState inside useEffect HOT 3
- Confused with rules HOT 5
- tslint-react-hooks rules not working in my atom HOT 1
- Doesn't work with React.memo or React.forwardRef (maybe others) HOT 4
- [Bug] Unable to enable "warning" mode HOT 3
- Support globbing import style HOT 5
- Supporting option to whitelist non-hook functions
- extend supported component decorators HOT 3
- Wrong message for anonymous functions HOT 2
- shows as warning regardless of rules declaration HOT 9
- Integrate this to tslint-react HOT 8
- [Feature Request] Exhaustive deps lint rule integration in tslint react hook HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tslint-react-hooks.