Disallow timers
See original GitHub issuePlease describe what the rule should do:
This rule would disallow usage of setTimeout()
and setInterval()
in code.
What category of rule is this? (place an “X” next to just one item)
[x] Warns about a potential error (problem) [ ] Suggests an alternate way of doing something (suggestion) [x] Enforces code style (layout) [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
var interval = window.setInterval(() => {
// Do something
} , 2000);
window.setTimeout(() => {
// Do something
} , 500);
var interval = setInterval(() => {
// Do something
} , 2000);
setTimeout(() => {
// Do something
} , 500);
Why should this rule be included in ESLint (instead of a plugin)? A lot of developers want to avoid using timers in code unless there is a really good reason. This rule seems to have a pretty common use case, and could really help to make sure people have to think long and hard if there is another way to solve the problem before using a timer in code.
Are you willing to submit a pull request to implement this rule? No
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:6 (4 by maintainers)
Top GitHub Comments
I think this is a good use case for rules such as
no-restricted-globals
andno-restricted-properties
:Closing since it looks like we’re all in agreement that this should be covered by
no-restricted-properties
andno-restricted-globals
.