question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mdjermanoviccommented, Jan 9, 2020

I think this is a good use case for rules such as no-restricted-globals and no-restricted-properties:

rules: {
    "no-restricted-globals": ["error", {
        name: "setInterval",
        message: "Avoid using timers.",
    }, {
        name: "setTimeout",
        message: "Avoid using timers.",
    }],
    "no-restricted-properties": ["error", {
        object: 'window',
        property: "setInterval",
        message: "Avoid using timers.",
    }, {
        object: "window",
        property: "setTimeout",
        message: "Avoid using timers.",
    }],
},
1reaction
kaicataldocommented, Jan 9, 2020

Closing since it looks like we’re all in agreement that this should be covered by no-restricted-properties and no-restricted-globals.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable Timers - Workshop - Steam Community
1,586 ratings. Disable Timers ... Disables the vanilla game mission timer in most non-story missions. ... This mod does not disable achievements.
Read more >
Enabling and Disabling Timers - Interactive Technologies
Timers can trigger actions such as Cues, Macros, Presets or any other CueScript command(s) ... Using this method does not prevent the timer...
Read more >
Disable Timers at XCOM2 Nexus - Mods and Community
About this mod. Disables the mission timer in most non-story missions. Notable exceptions are UFO and terror missions.
Read more >
Timers REST API Reference | Alexa Skills Kit
Valid value: Up to 256 characters. String. No. creationBehavior. Defines the behavior at timer creation. Object.
Read more >
Programmable Block + Timers (help) : r/spaceengineers - Reddit
Is there a bug with timers? IMyTimerBlock timerRun = GridTerminalSystem.GetBlockWithName("Timer Block Launch Sequance 1") as IMyTimerBlock;.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found