@darksheep/eslint 5.3.0 → 5.3.2

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/package.json +7 -7
  3. package/src/configs/eslint-base.js +103 -103
  4. package/src/configs/eslint-complexity.js +24 -24
  5. package/src/configs/eslint-ignores.js +32 -32
  6. package/src/configs/eslint-recommended.js +4 -4
  7. package/src/configs/eslint-style.js +12 -12
  8. package/src/custom/index.js +5 -5
  9. package/src/custom/instance-of-array.js +44 -44
  10. package/src/custom/loose-types.js +128 -128
  11. package/src/custom/no-useless-expression.js +19 -19
  12. package/src/custom/sequence-expression.js +15 -15
  13. package/src/index.js +38 -38
  14. package/src/plugins/eslint-comments.js +19 -19
  15. package/src/plugins/jsdoc.js +57 -57
  16. package/src/plugins/json.js +43 -43
  17. package/src/plugins/node.js +108 -108
  18. package/src/plugins/package-json.js +25 -25
  19. package/src/plugins/perfectionist.js +200 -200
  20. package/src/plugins/promise.js +9 -9
  21. package/src/plugins/react.js +111 -111
  22. package/src/plugins/regexp.js +6 -6
  23. package/src/plugins/sca.js +32 -32
  24. package/src/plugins/security.js +14 -14
  25. package/src/plugins/sonarjs.js +11 -11
  26. package/src/plugins/style.js +236 -236
  27. package/src/plugins/typescript.js +65 -65
  28. package/src/plugins/unicorn.js +40 -40
  29. package/src/plugins/unused-imports.js +25 -25
  30. package/src/plugins/yml.js +32 -32
  31. package/src/types.d.ts +80 -80
  32. package/src/utilities/editorconfig.js +150 -150
  33. package/src/utilities/eslint-files.js +20 -20
  34. package/src/utilities/expand-glob.js +33 -33
  35. package/src/utilities/filesystem.js +30 -30
  36. package/src/utilities/make-compat.js +6 -6
  37. package/src/utilities/package.js +29 -29
@@ -5,158 +5,158 @@
5
5
  * @returns {(node: import('eslint').Rule.Node) => void}
6
6
  */
7
7
  function createReporter(optionName, context, message) {
8
- const [ options ] = context.options;
9
-
10
- /**
11
- * @param {(
12
- * import('eslint').Rule.Node |
13
- * import('estree').Identifier |
14
- * import('estree').MemberExpression |
15
- * import('estree').ChainExpression |
16
- * import('estree').CallExpression |
17
- * import('estree').LogicalExpression |
18
- * import('estree').UnaryExpression
19
- * )} node The AST function node
20
- *
21
- * @returns {void}
22
- */
23
- function validateNode(node) {
24
- if (options?.[optionName] !== true) {
25
- context.report({ node, message });
26
- }
8
+ const [ options ] = context.options;
9
+
10
+ /**
11
+ * @param {(
12
+ * import('eslint').Rule.Node |
13
+ * import('estree').Identifier |
14
+ * import('estree').MemberExpression |
15
+ * import('estree').ChainExpression |
16
+ * import('estree').CallExpression |
17
+ * import('estree').LogicalExpression |
18
+ * import('estree').UnaryExpression
19
+ * )} node The AST function node
20
+ *
21
+ * @returns {void}
22
+ */
23
+ function validateNode(node) {
24
+ if (options?.[optionName] !== true) {
25
+ context.report({ node, message });
27
26
  }
27
+ }
28
28
 
29
- return validateNode;
29
+ return validateNode;
30
30
  }
31
31
 
32
32
  /** @type {import('eslint').Rule.RuleModule} */
33
33
  const rule = {
34
- meta: {
35
- type: 'problem',
36
- docs: {
37
- description: 'Prevent accidental implicit coercion in Expressions',
38
- recommended: true,
39
- },
40
- schema: [
41
- {
42
- type: 'object',
43
- properties: {
44
- allowConditionalExpressionCallExpression: { type: 'boolean' },
45
- allowConditionalExpressionIdentifier: { type: 'boolean' },
46
- allowConditionalExpressionMemberExpression: { type: 'boolean' },
47
- allowConditionalExpressionChainExpression: { type: 'boolean' },
48
-
49
- allowLogicalExpressionCallExpression: { type: 'boolean' },
50
- allowLogicalExpressionIdentifier: { type: 'boolean' },
51
- allowLogicalExpressionMemberExpression: { type: 'boolean' },
52
- allowLogicalExpressionChainExpression: { type: 'boolean' },
53
-
54
- allowNegatedUnaryExpression: { type: 'boolean' },
55
- },
56
- additionalProperties: false,
57
- },
58
- ],
34
+ meta: {
35
+ type: 'problem',
36
+ docs: {
37
+ description: 'Prevent accidental implicit coercion in Expressions',
38
+ recommended: true,
59
39
  },
60
-
61
- create: function (context) {
62
- return {
63
- /*
40
+ schema: [
41
+ {
42
+ type: 'object',
43
+ properties: {
44
+ allowConditionalExpressionCallExpression: { type: 'boolean' },
45
+ allowConditionalExpressionIdentifier: { type: 'boolean' },
46
+ allowConditionalExpressionMemberExpression: { type: 'boolean' },
47
+ allowConditionalExpressionChainExpression: { type: 'boolean' },
48
+
49
+ allowLogicalExpressionCallExpression: { type: 'boolean' },
50
+ allowLogicalExpressionIdentifier: { type: 'boolean' },
51
+ allowLogicalExpressionMemberExpression: { type: 'boolean' },
52
+ allowLogicalExpressionChainExpression: { type: 'boolean' },
53
+
54
+ allowNegatedUnaryExpression: { type: 'boolean' },
55
+ },
56
+ additionalProperties: false,
57
+ },
58
+ ],
59
+ },
60
+
61
+ create: function (context) {
62
+ return {
63
+ /*
64
64
  * var b = a ? 'hello' : 'there';
65
65
  * if (a) return 'hello';
66
66
  */
67
- 'Identifier.test': createReporter(
68
- 'allowConditionalExpressionIdentifier',
69
- context,
70
- 'Unexpected Identifier as Conditional',
71
- ),
67
+ 'Identifier.test': createReporter(
68
+ 'allowConditionalExpressionIdentifier',
69
+ context,
70
+ 'Unexpected Identifier as Conditional',
71
+ ),
72
72
 
73
- /*
73
+ /*
74
74
  * var b = object.key ? 'hello' : 'there';
75
75
  * if (object.key) return 'hello';
76
76
  */
77
- 'MemberExpression.test': createReporter(
78
- 'allowConditionalExpressionMemberExpression',
79
- context,
80
- 'Unexpected MemberExpression as Conditional',
81
- ),
77
+ 'MemberExpression.test': createReporter(
78
+ 'allowConditionalExpressionMemberExpression',
79
+ context,
80
+ 'Unexpected MemberExpression as Conditional',
81
+ ),
82
82
 
83
- /*
83
+ /*
84
84
  * var b = object?.key ? 'hello' : 'there';
85
85
  * if (object?.key) return 'hello';
86
86
  */
87
- 'ChainExpression.test': createReporter(
88
- 'allowConditionalExpressionChainExpression',
89
- context,
90
- 'Unexpected ChainExpression as Conditional',
91
- ),
87
+ 'ChainExpression.test': createReporter(
88
+ 'allowConditionalExpressionChainExpression',
89
+ context,
90
+ 'Unexpected ChainExpression as Conditional',
91
+ ),
92
92
 
93
- /*
93
+ /*
94
94
  * var b = a() ? 'hello' : 'there';
95
95
  * if (a()) return 'hello';
96
96
  *
97
97
  * var b = object.key() ? 'hello' : 'there';
98
98
  * if (object.key()) return 'hello';
99
99
  */
100
- 'CallExpression.test': createReporter(
101
- 'allowConditionalExpressionCallExpression',
102
- context,
103
- 'Unexpected CallExpression as Conditional',
104
- ),
100
+ 'CallExpression.test': createReporter(
101
+ 'allowConditionalExpressionCallExpression',
102
+ context,
103
+ 'Unexpected CallExpression as Conditional',
104
+ ),
105
105
 
106
- /*
106
+ /*
107
107
  * one === 1 && two
108
108
  * one === 1 || two
109
109
  */
110
- 'LogicalExpression[operator="&&"] > Identifier.right, LogicalExpression[operator="||"] > Identifier.right': createReporter(
111
- 'allowLogicalExpressionIdentifier',
112
- context,
113
- 'Unexpected Identifier as right hand of LogicalExpression',
114
- ),
110
+ 'LogicalExpression[operator="&&"] > Identifier.right, LogicalExpression[operator="||"] > Identifier.right': createReporter(
111
+ 'allowLogicalExpressionIdentifier',
112
+ context,
113
+ 'Unexpected Identifier as right hand of LogicalExpression',
114
+ ),
115
115
 
116
- /*
116
+ /*
117
117
  * one === 1 && two()
118
118
  * one === 1 || two()
119
119
  *
120
120
  * one === 1 && object.two()
121
121
  * one === 1 || object.two()
122
122
  */
123
- 'LogicalExpression[operator="&&"] > CallExpression.right, LogicalExpression[operator="||"] > CallExpression.right': createReporter(
124
- 'allowLogicalExpressionCallExpression',
125
- context,
126
- 'Unexpected CallExpression as right hand of LogicalExpression',
127
- ),
123
+ 'LogicalExpression[operator="&&"] > CallExpression.right, LogicalExpression[operator="||"] > CallExpression.right': createReporter(
124
+ 'allowLogicalExpressionCallExpression',
125
+ context,
126
+ 'Unexpected CallExpression as right hand of LogicalExpression',
127
+ ),
128
128
 
129
- /*
129
+ /*
130
130
  * one === 1 && object.two
131
131
  * one === 1 || object.two
132
132
  */
133
- 'LogicalExpression[operator="&&"] > MemberExpression.right, LogicalExpression[operator="||"] > MemberExpression.right': createReporter(
134
- 'allowLogicalExpressionMemberExpression',
135
- context,
136
- 'Unexpected MemberExpression as right hand of LogicalExpression',
137
- ),
133
+ 'LogicalExpression[operator="&&"] > MemberExpression.right, LogicalExpression[operator="||"] > MemberExpression.right': createReporter(
134
+ 'allowLogicalExpressionMemberExpression',
135
+ context,
136
+ 'Unexpected MemberExpression as right hand of LogicalExpression',
137
+ ),
138
138
 
139
- /*
139
+ /*
140
140
  * one === 1 && object?.two
141
141
  * one === 1 || object?.two
142
142
  */
143
- 'LogicalExpression[operator="&&"] > ChainExpression.right, LogicalExpression[operator="||"] > ChainExpression.right': createReporter(
144
- 'allowLogicalExpressionChainExpression',
145
- context,
146
- 'Unexpected ChainExpression as right hand of LogicalExpression',
147
- ),
143
+ 'LogicalExpression[operator="&&"] > ChainExpression.right, LogicalExpression[operator="||"] > ChainExpression.right': createReporter(
144
+ 'allowLogicalExpressionChainExpression',
145
+ context,
146
+ 'Unexpected ChainExpression as right hand of LogicalExpression',
147
+ ),
148
148
 
149
- /*
149
+ /*
150
150
  * one && two === 2
151
151
  * one || two === 2
152
152
  */
153
- 'LogicalExpression[operator="&&"] > Identifier.left, LogicalExpression[operator="||"] > Identifier.left': createReporter(
154
- 'allowLogicalExpressionIdentifier',
155
- context,
156
- 'Unexpected Identifier as left hand of LogicalExpression',
157
- ),
153
+ 'LogicalExpression[operator="&&"] > Identifier.left, LogicalExpression[operator="||"] > Identifier.left': createReporter(
154
+ 'allowLogicalExpressionIdentifier',
155
+ context,
156
+ 'Unexpected Identifier as left hand of LogicalExpression',
157
+ ),
158
158
 
159
- /*
159
+ /*
160
160
  * one() && two === 2
161
161
  * one() || two === 2
162
162
  *
@@ -166,39 +166,39 @@ const rule = {
166
166
  * object?.one() && two === 2
167
167
  * object?.one() || two === 2
168
168
  */
169
- 'LogicalExpression[operator="&&"] > CallExpression.left, LogicalExpression[operator="||"] > CallExpression.left': createReporter(
170
- 'allowLogicalExpressionCallExpression',
171
- context,
172
- 'Unexpected CallExpression as left hand of LogicalExpression',
173
- ),
169
+ 'LogicalExpression[operator="&&"] > CallExpression.left, LogicalExpression[operator="||"] > CallExpression.left': createReporter(
170
+ 'allowLogicalExpressionCallExpression',
171
+ context,
172
+ 'Unexpected CallExpression as left hand of LogicalExpression',
173
+ ),
174
174
 
175
- /*
175
+ /*
176
176
  * object.one && two === 2
177
177
  * object.one || two === 2
178
178
  */
179
- 'LogicalExpression[operator="&&"] > MemberExpression.left, LogicalExpression[operator="||"] > MemberExpression.left': createReporter(
180
- 'allowLogicalExpressionMemberExpression',
181
- context,
182
- 'Unexpected MemberExpression as left hand of LogicalExpression',
183
- ),
179
+ 'LogicalExpression[operator="&&"] > MemberExpression.left, LogicalExpression[operator="||"] > MemberExpression.left': createReporter(
180
+ 'allowLogicalExpressionMemberExpression',
181
+ context,
182
+ 'Unexpected MemberExpression as left hand of LogicalExpression',
183
+ ),
184
184
 
185
- /*
185
+ /*
186
186
  * object?.one && two === 2
187
187
  * object?.one || two === 2
188
188
  */
189
- 'LogicalExpression[operator="&&"] > ChainExpression.left, LogicalExpression[operator="||"] > ChainExpression.left': createReporter(
190
- 'allowLogicalExpressionChainExpression',
191
- context,
192
- 'Unexpected ChainExpression as left hand of LogicalExpression',
193
- ),
194
-
195
- 'UnaryExpression[operator="!"]': createReporter(
196
- 'allowNegatedUnaryExpression',
197
- context,
198
- 'Unexpected "!" UnaryExpression',
199
- ),
200
- };
201
- },
189
+ 'LogicalExpression[operator="&&"] > ChainExpression.left, LogicalExpression[operator="||"] > ChainExpression.left': createReporter(
190
+ 'allowLogicalExpressionChainExpression',
191
+ context,
192
+ 'Unexpected ChainExpression as left hand of LogicalExpression',
193
+ ),
194
+
195
+ 'UnaryExpression[operator="!"]': createReporter(
196
+ 'allowNegatedUnaryExpression',
197
+ context,
198
+ 'Unexpected "!" UnaryExpression',
199
+ ),
200
+ };
201
+ },
202
202
  };
203
203
 
204
204
  export default rule;
@@ -1,28 +1,28 @@
1
1
  const selector = [
2
- // test || false, false || test
3
- 'LogicalExpression[operator="||"] > [type=/Literal$/]',
4
- // true && test, test && true
5
- 'LogicalExpression[operator="&&"] > [type=/Literal$/]',
2
+ // test || false, false || test
3
+ 'LogicalExpression[operator="||"] > [type=/Literal$/]',
4
+ // true && test, test && true
5
+ 'LogicalExpression[operator="&&"] > [type=/Literal$/]',
6
6
  ].join(', ');
7
7
 
8
8
  /** @type {import('eslint').Rule.RuleModule} */
9
9
  const rule = {
10
- meta: { type: 'suggestion' },
10
+ meta: { type: 'suggestion' },
11
11
 
12
- create: function (context) {
13
- return {
14
- /**
15
- * @param {import('estree').Literal} node The AST function node
16
- * @returns {void}
17
- */
18
- [selector]: (node) => {
19
- context.report({
20
- node: node,
21
- message: 'Unexpected Literal in LogicalExpression',
22
- });
23
- },
24
- };
25
- },
12
+ create: function (context) {
13
+ return {
14
+ /**
15
+ * @param {import('estree').Literal} node The AST function node
16
+ * @returns {void}
17
+ */
18
+ [selector]: (node) => {
19
+ context.report({
20
+ node: node,
21
+ message: 'Unexpected Literal in LogicalExpression',
22
+ });
23
+ },
24
+ };
25
+ },
26
26
  };
27
27
 
28
28
  export default rule;
@@ -1,21 +1,21 @@
1
1
  /** @type {import('eslint').Rule.RuleModule} */
2
2
  const rule = {
3
- meta: { type: 'suggestion' },
3
+ meta: { type: 'suggestion' },
4
4
 
5
- create: function (context) {
6
- return {
7
- /**
8
- * @param {import('estree').SequenceExpression} node The AST function node
9
- * @returns {void}
10
- */
11
- SequenceExpression: (node) => {
12
- context.report({
13
- node: node,
14
- message: 'Unexpected use of a SequenceExpression',
15
- });
16
- },
17
- };
18
- },
5
+ create: function (context) {
6
+ return {
7
+ /**
8
+ * @param {import('estree').SequenceExpression} node The AST function node
9
+ * @returns {void}
10
+ */
11
+ SequenceExpression: (node) => {
12
+ context.report({
13
+ node: node,
14
+ message: 'Unexpected use of a SequenceExpression',
15
+ });
16
+ },
17
+ };
18
+ },
19
19
  };
20
20
 
21
21
  export default rule;
package/src/index.js CHANGED
@@ -24,28 +24,28 @@ import { createEslintUnusedImportsConfig } from './plugins/unused-imports.js';
24
24
  import { createEslintYmlConfig } from './plugins/yml.js';
25
25
 
26
26
  const configBuilders = [
27
- createEslintIgnoresConfig,
28
- createEslintRecommendsConfig,
29
- createEslintBaseConfig,
30
- createEslintComplexityConfig,
31
- createStyleConfig,
32
- createEslintCommentsConfig,
33
- createEslintNodeConfig,
34
- createEslintPerfectionistConfig,
35
- createEslintPackageJsonConfig,
36
- createEslintJsonConfig,
37
- createEslintYmlConfig,
38
- createEslintPromiseConfig,
39
- createEslintTypescriptConfig,
40
- createEslintReactConfig,
41
- createEslintSecurityConfig,
42
- createEslintUnicornConfig,
43
- createEslintRegexpConfig,
44
- createEslintSCAConfig,
45
- createEslintSonarJSConfig,
46
- createEslintStyleConfig,
47
- createEslintUnusedImportsConfig,
48
- createEslintJSDocConfig,
27
+ createEslintIgnoresConfig,
28
+ createEslintRecommendsConfig,
29
+ createEslintBaseConfig,
30
+ createEslintComplexityConfig,
31
+ createStyleConfig,
32
+ createEslintCommentsConfig,
33
+ createEslintNodeConfig,
34
+ createEslintPerfectionistConfig,
35
+ createEslintPackageJsonConfig,
36
+ createEslintJsonConfig,
37
+ createEslintYmlConfig,
38
+ createEslintPromiseConfig,
39
+ createEslintTypescriptConfig,
40
+ createEslintReactConfig,
41
+ createEslintSecurityConfig,
42
+ createEslintUnicornConfig,
43
+ createEslintRegexpConfig,
44
+ createEslintSCAConfig,
45
+ createEslintSonarJSConfig,
46
+ createEslintStyleConfig,
47
+ createEslintUnusedImportsConfig,
48
+ createEslintJSDocConfig,
49
49
  ];
50
50
 
51
51
  /**
@@ -53,11 +53,11 @@ const configBuilders = [
53
53
  * @returns {Promise<import('eslint').Linter.FlatConfig[]>}
54
54
  */
55
55
  async function createConfigUrl(root) {
56
- const configs = await Promise.all(
57
- configBuilders.map((builder) => builder(root)),
58
- );
56
+ const configs = await Promise.all(
57
+ configBuilders.map((builder) => builder(root)),
58
+ );
59
59
 
60
- return configs.flat();
60
+ return configs.flat();
61
61
  }
62
62
 
63
63
  /**
@@ -65,21 +65,21 @@ async function createConfigUrl(root) {
65
65
  * @returns {Promise<import('eslint').Linter.FlatConfig[]>}
66
66
  */
67
67
  export async function createConfig(root) {
68
- if (root instanceof URL) {
69
- return createConfigUrl(root);
70
- }
68
+ if (root instanceof URL) {
69
+ return createConfigUrl(root);
70
+ }
71
71
 
72
- if (typeof root !== 'string') {
73
- throw new TypeError('Invalid file root');
74
- }
72
+ if (typeof root !== 'string') {
73
+ throw new TypeError('Invalid file root');
74
+ }
75
75
 
76
- root = root
77
- // This is to remove: file:/ or file:///
78
- .replace(/^file:\/*/, '/')
79
- // This is prevent ?time=<stamp>
80
- .replace(/\?.*$/, '');
76
+ root = root
77
+ // This is to remove: file:/ or file:///
78
+ .replace(/^file:\/*/, '/')
79
+ // This is prevent ?time=<stamp>
80
+ .replace(/\?.*$/, '');
81
81
 
82
- return createConfigUrl(pathToFileURL(root));
82
+ return createConfigUrl(pathToFileURL(root));
83
83
  }
84
84
 
85
85
  export * from 'eslint';
@@ -5,24 +5,24 @@ import eslintComments from '@eslint-community/eslint-plugin-eslint-comments';
5
5
  * @returns {import('eslint').Linter.FlatConfig[]}
6
6
  */
7
7
  export function createEslintCommentsConfig() {
8
- return [
9
- {
10
- name: 'eslint-comments/custom',
11
- plugins: {
12
- 'eslint-comments': eslintComments,
13
- },
14
- rules: {
15
- 'eslint-comments/disable-enable-pair': [ 'error', { allowWholeFile: true } ],
16
- 'eslint-comments/no-aggregating-enable': 'error',
17
- 'eslint-comments/no-duplicate-disable': 'error',
18
- 'eslint-comments/no-unlimited-disable': 'error',
19
- 'eslint-comments/no-unused-disable': 'error',
20
- 'eslint-comments/no-unused-enable': 'error',
8
+ return [
9
+ {
10
+ name: 'eslint-comments/custom',
11
+ plugins: {
12
+ 'eslint-comments': eslintComments,
13
+ },
14
+ rules: {
15
+ 'eslint-comments/disable-enable-pair': [ 'error', { allowWholeFile: true } ],
16
+ 'eslint-comments/no-aggregating-enable': 'error',
17
+ 'eslint-comments/no-duplicate-disable': 'error',
18
+ 'eslint-comments/no-unlimited-disable': 'error',
19
+ 'eslint-comments/no-unused-disable': 'error',
20
+ 'eslint-comments/no-unused-enable': 'error',
21
21
 
22
- // 'line-comment-position': 'off',
23
- // 'multiline-comment-style': 'off',
24
- 'no-inline-comments': 'off',
25
- },
26
- },
27
- ];
22
+ // 'line-comment-position': 'off',
23
+ // 'multiline-comment-style': 'off',
24
+ 'no-inline-comments': 'off',
25
+ },
26
+ },
27
+ ];
28
28
  }