eslint-plugin-new-with-error 1.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG +17 -0
- package/index.js +10 -0
- package/lib/rules/new-with-error.js +18 -31
- package/package.json +39 -3
- package/.npmignore +0 -27
- package/docs/rules/new-with-error.md +0 -36
- package/tests/lib/rules/new-with-error.js +0 -40
package/CHANGELOG
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# [3.0.0](https://github.com/Trott/eslint-plugin-new-with-error/compare/v2.0.0...v3.0.0) (2021-11-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### chore
|
|
5
|
+
|
|
6
|
+
* test all versions of ESLint that we support ([#24](https://github.com/Trott/eslint-plugin-new-with-error/issues/24)) ([221a5fc](https://github.com/Trott/eslint-plugin-new-with-error/commit/221a5fc3ff799b54c7fb5ff3c6d87856e190605d))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* drop support for Node.js < 12.x.
|
|
12
|
+
|
|
13
|
+
# Changelog
|
|
14
|
+
|
|
15
|
+
## 2.0.0
|
|
16
|
+
|
|
17
|
+
Now requires ESLint 2 or higher.
|
package/index.js
ADDED
|
@@ -1,43 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Require `throw new Error()` rather than `throw Error()`
|
|
3
3
|
* @author Rich Trott
|
|
4
|
-
* @copyright
|
|
4
|
+
* @copyright Rich Trott. All rights reserved.
|
|
5
5
|
* See LICENSE file in root directory for full license.
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
'use strict'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// ------------------------------------------------------------------------------
|
|
10
10
|
// Rule Definition
|
|
11
|
-
|
|
11
|
+
// ------------------------------------------------------------------------------
|
|
12
12
|
|
|
13
|
-
module.exports = function(context) {
|
|
13
|
+
module.exports = function (context) {
|
|
14
|
+
const defaultErrorsList = ['Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError']
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
const errorList = context.options.length !== 0 ? context.options : defaultErrorsList
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
// --------------------------------------------------------------------------
|
|
19
|
+
// Public
|
|
20
|
+
// --------------------------------------------------------------------------
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
return {
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
module.exports.schema = {
|
|
33
|
-
'type': 'array',
|
|
34
|
-
'items': [
|
|
35
|
-
{
|
|
36
|
-
'enum': [0, 1, 2]
|
|
37
|
-
}
|
|
38
|
-
],
|
|
39
|
-
'additionalItems': {
|
|
40
|
-
'type': 'string'
|
|
41
|
-
},
|
|
42
|
-
'uniqueItems': true
|
|
43
|
-
};
|
|
24
|
+
ThrowStatement: function (node) {
|
|
25
|
+
if (node.argument.type === 'CallExpression' && errorList.indexOf(node.argument.callee.name) !== -1) {
|
|
26
|
+
context.report(node, 'Use new keyword when throwing.')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-new-with-error",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Require `throw new Error()` and not `throw Error()`",
|
|
5
5
|
"repository": "https://github.com/Trott/eslint-plugin-new-with-error",
|
|
6
6
|
"directories": {
|
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
"test": "tests"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"
|
|
11
|
+
"pretest": "standard",
|
|
12
|
+
"test": "for eslintVersion in 2.13.1 3 4 5 6 7 8; do npm install --no-save eslint@${eslintVersion} && c8 --check-coverage --branches 100 --functions 100 --lines 100 node tests/lib/rules/new-with-error.js || exit 1; done",
|
|
13
|
+
"posttest": "npm ci"
|
|
12
14
|
},
|
|
13
15
|
"keywords": [
|
|
14
16
|
"eslint",
|
|
@@ -17,6 +19,40 @@
|
|
|
17
19
|
"author": "Rich Trott <rtrott@gmail.com>",
|
|
18
20
|
"license": "MIT",
|
|
19
21
|
"peerDependencies": {
|
|
20
|
-
"eslint": ">=
|
|
22
|
+
"eslint": ">=2.13.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@semantic-release/changelog": "^6.0.1",
|
|
26
|
+
"@semantic-release/git": "^10.0.1",
|
|
27
|
+
"c8": "^7.10.0",
|
|
28
|
+
"eslint": "^8.2.0",
|
|
29
|
+
"semantic-release": "^18.0.0",
|
|
30
|
+
"standard": "^16.0.4"
|
|
31
|
+
},
|
|
32
|
+
"release": {
|
|
33
|
+
"branches": [
|
|
34
|
+
"main"
|
|
35
|
+
],
|
|
36
|
+
"plugins": [
|
|
37
|
+
"@semantic-release/commit-analyzer",
|
|
38
|
+
"@semantic-release/release-notes-generator",
|
|
39
|
+
[
|
|
40
|
+
"@semantic-release/changelog",
|
|
41
|
+
{
|
|
42
|
+
"changelogFile": "CHANGELOG"
|
|
43
|
+
}
|
|
44
|
+
],
|
|
45
|
+
"@semantic-release/npm",
|
|
46
|
+
[
|
|
47
|
+
"@semantic-release/git",
|
|
48
|
+
{
|
|
49
|
+
"assets": [
|
|
50
|
+
"CHANGELOG",
|
|
51
|
+
"package.json"
|
|
52
|
+
],
|
|
53
|
+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
]
|
|
21
57
|
}
|
|
22
58
|
}
|
package/.npmignore
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# Logs
|
|
2
|
-
logs
|
|
3
|
-
*.log
|
|
4
|
-
|
|
5
|
-
# Runtime data
|
|
6
|
-
pids
|
|
7
|
-
*.pid
|
|
8
|
-
*.seed
|
|
9
|
-
|
|
10
|
-
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
11
|
-
lib-cov
|
|
12
|
-
|
|
13
|
-
# Coverage directory used by tools like istanbul
|
|
14
|
-
coverage
|
|
15
|
-
|
|
16
|
-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
|
17
|
-
.grunt
|
|
18
|
-
|
|
19
|
-
# node-waf configuration
|
|
20
|
-
.lock-wscript
|
|
21
|
-
|
|
22
|
-
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
|
23
|
-
build/Release
|
|
24
|
-
|
|
25
|
-
# Dependency directory
|
|
26
|
-
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
|
|
27
|
-
node_modules
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Require `throw new Error()` rather than `throw Error()` (new-with-error)
|
|
2
|
-
|
|
3
|
-
This is a style requirement of Node.js core code. Perhaps you will find it useful too.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
## Rule Details
|
|
7
|
-
|
|
8
|
-
This rule aims to make sure that there is consistency with how Errors are thrown.
|
|
9
|
-
|
|
10
|
-
The following patterns are considered warnings:
|
|
11
|
-
|
|
12
|
-
```js
|
|
13
|
-
|
|
14
|
-
throw Error('foo');
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
The following patterns are not warnings:
|
|
19
|
-
|
|
20
|
-
```js
|
|
21
|
-
|
|
22
|
-
throw new Error('foo');
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### Options
|
|
27
|
-
|
|
28
|
-
You can include an array of Error types you want checked (SyntaxError, ReferenceError, etc.). Or don't provide it and you'll just get checks on Error.
|
|
29
|
-
|
|
30
|
-
## When Not To Use It
|
|
31
|
-
|
|
32
|
-
If you don't care if there's a mix of `throw Error()` and `throw new Error()` in your code, then this is not the rule for you.
|
|
33
|
-
|
|
34
|
-
## Further Reading
|
|
35
|
-
|
|
36
|
-
* https://github.com/nodejs/node/pull/3714
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Require `throw new Error()` rather than `throw Error()`
|
|
3
|
-
* @author Rich Trott
|
|
4
|
-
* @copyright 2015 Rich Trott. All rights reserved.
|
|
5
|
-
* See LICENSE file in root directory for full license.
|
|
6
|
-
*/
|
|
7
|
-
"use strict";
|
|
8
|
-
|
|
9
|
-
//------------------------------------------------------------------------------
|
|
10
|
-
// Requirements
|
|
11
|
-
//------------------------------------------------------------------------------
|
|
12
|
-
|
|
13
|
-
var rule = require("../../../lib/rules/new-with-error"),
|
|
14
|
-
|
|
15
|
-
RuleTester = require("eslint").RuleTester;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//------------------------------------------------------------------------------
|
|
19
|
-
// Tests
|
|
20
|
-
//------------------------------------------------------------------------------
|
|
21
|
-
|
|
22
|
-
var ruleTester = new RuleTester();
|
|
23
|
-
ruleTester.run("new-with-error", rule, {
|
|
24
|
-
|
|
25
|
-
valid: [
|
|
26
|
-
{
|
|
27
|
-
code: "throw new Error();"
|
|
28
|
-
}
|
|
29
|
-
],
|
|
30
|
-
|
|
31
|
-
invalid: [
|
|
32
|
-
{
|
|
33
|
-
code: "throw Error();",
|
|
34
|
-
errors: [{
|
|
35
|
-
message: "Use new keyword when throwing.",
|
|
36
|
-
type: "ThrowStatement"
|
|
37
|
-
}]
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
});
|