eslint-plugin-new-with-error 3.0.0 → 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 CHANGED
@@ -1,3 +1,10 @@
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
+
1
8
  # [3.0.0](https://github.com/Trott/eslint-plugin-new-with-error/compare/v2.0.0...v3.0.0) (2021-11-18)
2
9
 
3
10
 
@@ -10,8 +17,7 @@
10
17
 
11
18
  * drop support for Node.js < 12.x.
12
19
 
13
- # Changelog
14
20
 
15
- ## 2.0.0
21
+ # 2.0.0
16
22
 
17
23
  Now requires ESLint 2 or higher.
@@ -10,20 +10,34 @@
10
10
  // Rule Definition
11
11
  // ------------------------------------------------------------------------------
12
12
 
13
- module.exports = function (context) {
14
- const defaultErrorsList = ['Error', 'EvalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError']
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']
15
22
 
16
- const errorList = context.options.length !== 0 ? context.options : defaultErrorsList
23
+ const errorList = context.options.length !== 0 ? context.options : defaultErrorsList
17
24
 
18
- // --------------------------------------------------------------------------
19
- // Public
20
- // --------------------------------------------------------------------------
25
+ // --------------------------------------------------------------------------
26
+ // Public
27
+ // --------------------------------------------------------------------------
21
28
 
22
- return {
29
+ return {
23
30
 
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.')
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 ')
38
+ }
39
+ })
40
+ }
27
41
  }
28
42
  }
29
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-new-with-error",
3
- "version": "3.0.0",
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": {