| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 09f35a4 commit dec5900
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -124,6 +124,7 @@ rules: | |||
| 124 | 124 | assert-fail-single-argument: 2 | |
| 125 | 125 | assert-throws-arguments: [2, { requireTwo: false }] | |
| 126 | 126 | new-with-error: [2, Error, RangeError, TypeError, SyntaxError, ReferenceError] | |
| 127 | + timer-arguments: 2 | ||
| 127 | 128 | ||
| 128 | 129 | # Global scoped method and vars | |
| 129 | 130 | globals: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + /** | ||
| 2 | + * @fileoverview Require at least two arguments when calling setTimeout() or | ||
| 3 | + * setInterval(). | ||
| 4 | + * @author Rich Trott | ||
| 5 | + */ | ||
| 6 | + 'use strict'; | ||
| 7 | + | ||
| 8 | + //------------------------------------------------------------------------------ | ||
| 9 | + // Rule Definition | ||
| 10 | + //------------------------------------------------------------------------------ | ||
| 11 | + | ||
| 12 | + function isTimer(name) { | ||
| 13 | + return ['setTimeout', 'setInterval'].includes(name); | ||
| 14 | + } | ||
| 15 | + | ||
| 16 | + module.exports = function(context) { | ||
| 17 | + return { | ||
| 18 | + 'CallExpression': function(node) { | ||
| 19 | + const name = node.callee.name; | ||
| 20 | + if (isTimer(name) && node.arguments.length < 2) { | ||
| 21 | + context.report(node, `${name} must have at least 2 arguments`); | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | + }; | ||
| 25 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments