| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 38bb0d8 commit d036b35
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -87,6 +87,8 @@ rules: | |||
| 87 | 87 | ||
| 88 | 88 | # Custom rules in tools/eslint-rules | |
| 89 | 89 | require-buffer: 2 | |
| 90 | + new-with-error: [2, "Error", "RangeError", "TypeError", "SyntaxError", "ReferenceError"] | ||
| 91 | + | ||
| 90 | 92 | ||
| 91 | 93 | # Global scoped method and vars | |
| 92 | 94 | globals: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,36 @@ | |||
| 1 | + /** | ||
| 2 | + * @fileoverview Require `throw new Error()` rather than `throw Error()` | ||
| 3 | + * @author Rich Trott | ||
| 4 | + */ | ||
| 5 | + 'use strict'; | ||
| 6 | + | ||
| 7 | + //------------------------------------------------------------------------------ | ||
| 8 | + // Rule Definition | ||
| 9 | + //------------------------------------------------------------------------------ | ||
| 10 | + | ||
| 11 | + module.exports = function(context) { | ||
| 12 | + | ||
| 13 | + var errorList = context.options.length !== 0 ? context.options : ['Error']; | ||
| 14 | + | ||
| 15 | + return { | ||
| 16 | + 'ThrowStatement': function(node) { | ||
| 17 | + if (node.argument.type === 'CallExpression' && | ||
| 18 | + errorList.indexOf(node.argument.callee.name) !== -1) { | ||
| 19 | + context.report(node, 'Use new keyword when throwing.'); | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | + }; | ||
| 23 | + }; | ||
| 24 | + | ||
| 25 | + module.exports.schema = { | ||
| 26 | + 'type': 'array', | ||
| 27 | + 'items': [ | ||
| 28 | + { | ||
| 29 | + 'enum': [0, 1, 2] | ||
| 30 | + } | ||
| 31 | + ], | ||
| 32 | + 'additionalItems': { | ||
| 33 | + 'type': 'string' | ||
| 34 | + }, | ||
| 35 | + 'uniqueItems': true | ||
| 36 | + }; | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments