eslint-plugin-new-with-error 1.0.1 → 3.1.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 ADDED
@@ -0,0 +1,23 @@
1
+ # [3.1.0](https://github.com/Trott/eslint-plugin-new-with-error/compare/v3.0.0...v3.1.0) (2021-11-19)
2
+
3
+
4
+ ### Features
5
+
6
+ * make rule fixable ([#25](https://github.com/Trott/eslint-plugin-new-with-error/issues/25)) ([72666f4](https://github.com/Trott/eslint-plugin-new-with-error/commit/72666f4822e2df25f685c8039e282d9739dce8d6))
7
+
8
+ # [3.0.0](https://github.com/Trott/eslint-plugin-new-with-error/compare/v2.0.0...v3.0.0) (2021-11-18)
9
+
10
+
11
+ ### chore
12
+
13
+ * 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))
14
+
15
+
16
+ ### BREAKING CHANGES
17
+
18
+ * drop support for Node.js < 12.x.
19
+
20
+
21
+ # 2.0.0
22
+
23
+ Now requires ESLint 2 or higher.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ 'use strict'
2
2
 
3
3
  module.exports = {
4
4
  rules: {
@@ -7,4 +7,4 @@ module.exports = {
7
7
  rulesConfig: {
8
8
  'new-with-error': 1
9
9
  }
10
- };
10
+ }
@@ -1,43 +1,44 @@
1
1
  /**
2
2
  * @fileoverview Require `throw new Error()` rather than `throw Error()`
3
3
  * @author Rich Trott
4
- * @copyright 2015 Rich Trott. All rights reserved.
4
+ * @copyright Rich Trott. All rights reserved.
5
5
  * See LICENSE file in root directory for full license.
6
6
  */
7
- "use strict";
7
+ 'use strict'
8
8
 
9
- //------------------------------------------------------------------------------
9
+ // ------------------------------------------------------------------------------
10
10
  // Rule Definition
11
- //------------------------------------------------------------------------------
11
+ // ------------------------------------------------------------------------------
12
12
 
13
- module.exports = function(context) {
13
+ /**
14
+ * @type {import('eslint').Rule.RuleModule}
15
+ */
16
+ module.exports = {
17
+ meta: {
18
+ fixable: 'code'
19
+ },
20
+ create: function (context) {
21
+ const defaultErrorsList = ['Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError']
14
22
 
15
- var errorList = context.options.length !== 0 ? context.options : ['Error'];
23
+ const errorList = context.options.length !== 0 ? context.options : defaultErrorsList
16
24
 
17
- //--------------------------------------------------------------------------
25
+ // --------------------------------------------------------------------------
18
26
  // Public
19
- //--------------------------------------------------------------------------
27
+ // --------------------------------------------------------------------------
20
28
 
21
29
  return {
22
30
 
23
- 'ThrowStatement': function(node) {
24
- if (node.argument.type === 'CallExpression' && errorList.indexOf(node.argument.callee.name) !== -1) {
25
- context.report(node, 'Use new keyword when throwing.');
31
+ ThrowStatement: function (node) {
32
+ if (node.argument.type === 'CallExpression' && errorList.indexOf(node.argument.callee.name) !== -1) {
33
+ context.report({
34
+ message: 'Use new keyword when throwing.',
35
+ node: node,
36
+ fix: function (fixer) {
37
+ return fixer.insertTextBefore(node.argument, 'new ')
26
38
  }
39
+ })
27
40
  }
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
- };
41
+ }
42
+ }
43
+ }
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-new-with-error",
3
- "version": "1.0.1",
3
+ "version": "3.1.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
- "test": "node tests/lib/rules/new-with-error.js"
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": ">=0.8.0"
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
- });