@arrirpc/eslint-plugin 0.45.4 → 0.45.6

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -18,46 +18,15 @@ pnpm i --save-dev @arrirpc/eslint-plugin
18
18
 
19
19
  This library supports both [flat file config format](https://eslint.org/docs/latest/use/configure/configuration-files) and the [legacy config format](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated). Right now, the legacy format is the default. When more of the ecosystem has moved to supporting the new format this library will swap defaults, and potentially drop support for the old format. When such a change happens, it will be marked as a breaking change.
20
20
 
21
- ### Legacy Eslint Config
22
-
23
- #### Using the default recommended configuration
24
-
25
- This turns all of the `@arrirpc/eslint` rules on
26
-
27
- ```jsonc
28
- {
29
- "extends": ["plugin:@arrirpc/legacy-config-recommended"],
30
- "files": ["**/*.ts"],
31
- }
32
- ```
33
-
34
- #### Manual Setup
35
-
36
- ```jsonc
37
- {
38
- "plugins": ["@arrirpc"],
39
- "rules": {
40
- // check to see if an ID has been assigned to root a.object() schemas
41
- "@arrirpc/no-anonymous-object": 2,
42
- // check to see if an ID has been assigned to a.enumerator() or a.stringEnum() schemas
43
- "@arrirpc/no-anonymous-enumerator": 2,
44
- // check to see if an ID has been assigned to a.discriminator() schemas
45
- "@arrirpc/no-anonymous-discriminator": 2,
46
- // check to see if an ID has been assigned to a.recursive() schemas
47
- "@arrirpc/no-anonymous-recursive": 2,
48
- },
49
- }
50
- ```
51
-
52
21
  ### Flat File Config
53
22
 
54
23
  #### Using the default recommended configuration
55
24
 
56
- This turns all of the `@arrirpc/eslint` rules on. Please note that the file extension is required to get it work properly.
25
+ This turns all of the `@arrirpc/eslint` rules on.
57
26
 
58
27
  ```js
59
28
  // eslint.config.js
60
- import arri from "@arrirpc/eslint-plugin/dist/configs.mjs";
29
+ import arri from "@arrirpc/eslint-plugin/configs";
61
30
 
62
31
  export default [
63
32
  arri.recommended,
@@ -67,19 +36,9 @@ export default [
67
36
  ];
68
37
  ```
69
38
 
70
- If you need commonjs support you can change the `.mjs` extension to `.cjs`
71
-
72
- ```ts
73
- import arri from "@arrirpc/eslint-plugin/dist/configs.cjs";
74
- ```
75
-
76
- ##### Note
77
-
78
- When the flat file config format becomes the default these long imports with explicit `.mjs`/`.cjs` suffixes will not longer be required. This method is just a hacky way for us keep the old and new style configs in one package.
79
-
80
39
  #### Manual setup
81
40
 
82
- The plugin can be enabled in flat file configs like so. Fortunately this doesn't require the long ugly imports.
41
+ The plugin can be enabled in flat file configs like so.
83
42
 
84
43
  ```js
85
44
  // eslint.config.js
@@ -103,3 +62,34 @@ export default [
103
62
  },
104
63
  ];
105
64
  ```
65
+
66
+ ### Legacy Eslint Config
67
+
68
+ #### Using the default recommended configuration
69
+
70
+ This turns all of the `@arrirpc/eslint` rules on
71
+
72
+ ```jsonc
73
+ {
74
+ "extends": ["plugin:@arrirpc/legacy-config-recommended"],
75
+ "files": ["**/*.ts"],
76
+ }
77
+ ```
78
+
79
+ #### Manual Setup
80
+
81
+ ```jsonc
82
+ {
83
+ "plugins": ["@arrirpc"],
84
+ "rules": {
85
+ // check to see if an ID has been assigned to root a.object() schemas
86
+ "@arrirpc/no-anonymous-object": 2,
87
+ // check to see if an ID has been assigned to a.enumerator() or a.stringEnum() schemas
88
+ "@arrirpc/no-anonymous-enumerator": 2,
89
+ // check to see if an ID has been assigned to a.discriminator() schemas
90
+ "@arrirpc/no-anonymous-discriminator": 2,
91
+ // check to see if an ID has been assigned to a.recursive() schemas
92
+ "@arrirpc/no-anonymous-recursive": 2,
93
+ },
94
+ }
95
+ ```
package/dist/configs.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const plugin = require('./shared/eslint-plugin.5adc55bc.cjs');
5
+ const plugin = require('./shared/eslint-plugin.acba1ce7.cjs');
6
6
 
7
7
  const flatConfigs = {
8
8
  recommended: {
package/dist/configs.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { p as plugin, a as prefixedRuleMap } from './shared/eslint-plugin.aced4931.mjs';
1
+ import { p as plugin, a as prefixedRuleMap } from './shared/eslint-plugin.558090f3.mjs';
2
2
 
3
3
  const flatConfigs = {
4
4
  recommended: {
package/dist/plugin.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- const plugin = require('./shared/eslint-plugin.5adc55bc.cjs');
5
+ const plugin = require('./shared/eslint-plugin.acba1ce7.cjs');
6
6
 
7
7
 
8
8
 
package/dist/plugin.mjs CHANGED
@@ -1 +1 @@
1
- export { c as configs, p as default, m as meta, r as rules } from './shared/eslint-plugin.aced4931.mjs';
1
+ export { c as configs, p as default, m as meta, r as rules } from './shared/eslint-plugin.558090f3.mjs';
@@ -13,19 +13,24 @@ function argHasIdKey(arg) {
13
13
  }
14
14
  return false;
15
15
  }
16
- function isNestedInSchema(schemaTypes, context, log = false) {
17
- const ancestors = context.getAncestors();
16
+ function isNestedInSchema(node, schemaTypes, context, log = false) {
17
+ const sourceCode = "sourceCode" in context ? context.sourceCode : (
18
+ // legacy method
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ context.getSourceCode()
21
+ );
22
+ const ancestors = sourceCode.getAncestors(node);
18
23
  if (log) {
19
24
  console.log(ancestors);
20
25
  }
21
- for (const node of ancestors) {
22
- if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression" || node.callee.object.type !== "Identifier" || node.callee.object.name !== "a") {
26
+ for (const node2 of ancestors) {
27
+ if (node2.type !== "CallExpression" || node2.callee.type !== "MemberExpression" || node2.callee.object.type !== "Identifier" || node2.callee.object.name !== "a") {
23
28
  continue;
24
29
  }
25
- if (node.callee.property.type !== "Identifier") {
30
+ if (node2.callee.property.type !== "Identifier") {
26
31
  continue;
27
32
  }
28
- const nodeName = node.callee.property.name;
33
+ const nodeName = node2.callee.property.name;
29
34
  if (schemaTypes.includes(nodeName)) {
30
35
  return true;
31
36
  }
@@ -47,7 +52,7 @@ const noAnonymousDiscriminator = {
47
52
  if (propName !== "discriminator") {
48
53
  return;
49
54
  }
50
- if (isNestedInSchema(["recursive"], context)) {
55
+ if (isNestedInSchema(node, ["recursive"], context)) {
51
56
  return;
52
57
  }
53
58
  if (node.arguments.length < 3) {
@@ -89,9 +94,16 @@ const noAnonymousEnumerator = {
89
94
  if (propName !== "enumerator" && propName !== "stringEnum") {
90
95
  return;
91
96
  }
97
+ if (isNestedInSchema(
98
+ node,
99
+ ["object", "discriminator", "recursive"],
100
+ context
101
+ )) {
102
+ return;
103
+ }
92
104
  if (node.arguments.length < 2) {
93
105
  context.report({
94
- message: "enum schemas must specify an id",
106
+ message: "root enum schemas must specify an id",
95
107
  node
96
108
  });
97
109
  return;
@@ -105,7 +117,7 @@ const noAnonymousEnumerator = {
105
117
  return;
106
118
  }
107
119
  context.report({
108
- message: "enum schemas must specify an id",
120
+ message: "root enum schemas must specify an id",
109
121
  node
110
122
  });
111
123
  }
@@ -147,7 +159,7 @@ const noAnonymousObject = {
147
159
  }
148
160
  };
149
161
  function handleObject(node, context) {
150
- if (!isRootObjectSchema(context)) {
162
+ if (!isRootObjectSchema(node, context)) {
151
163
  return;
152
164
  }
153
165
  if (node.arguments.length < 2) {
@@ -171,7 +183,7 @@ function handleObject(node, context) {
171
183
  });
172
184
  }
173
185
  function handlePartial(node, context) {
174
- if (!isRootObjectSchema(context)) {
186
+ if (!isRootObjectSchema(node, context)) {
175
187
  return;
176
188
  }
177
189
  if (node.arguments.length < 2) {
@@ -190,7 +202,7 @@ function handlePartial(node, context) {
190
202
  });
191
203
  }
192
204
  function handlePick(node, context) {
193
- if (!isRootObjectSchema(context)) {
205
+ if (!isRootObjectSchema(node, context)) {
194
206
  return;
195
207
  }
196
208
  if (node.arguments.length < 3) {
@@ -208,27 +220,28 @@ function handlePick(node, context) {
208
220
  node
209
221
  });
210
222
  }
211
- function handleExtend(node, context) {
212
- if (!isRootObjectSchema(context)) {
223
+ function handleExtend(expression, context) {
224
+ if (!isRootObjectSchema(expression, context)) {
213
225
  return;
214
226
  }
215
- if (node.arguments.length < 3) {
227
+ if (expression.arguments.length < 3) {
216
228
  context.report({
217
229
  message: defaultMessage,
218
- node
230
+ node: expression
219
231
  });
220
232
  return;
221
233
  }
222
- if (argHasIdKey(node.arguments[2])) {
234
+ if (argHasIdKey(expression.arguments[2])) {
223
235
  return;
224
236
  }
225
237
  context.report({
226
238
  message: defaultMessage,
227
- node
239
+ node: expression
228
240
  });
229
241
  }
230
- function isRootObjectSchema(context, log = false) {
242
+ function isRootObjectSchema(node, context, log = false) {
231
243
  return !isNestedInSchema(
244
+ node,
232
245
  [...guardedSchemaTypes, "discriminator", "recursive"],
233
246
  context,
234
247
  log
@@ -15,19 +15,24 @@ function argHasIdKey(arg) {
15
15
  }
16
16
  return false;
17
17
  }
18
- function isNestedInSchema(schemaTypes, context, log = false) {
19
- const ancestors = context.getAncestors();
18
+ function isNestedInSchema(node, schemaTypes, context, log = false) {
19
+ const sourceCode = "sourceCode" in context ? context.sourceCode : (
20
+ // legacy method
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ context.getSourceCode()
23
+ );
24
+ const ancestors = sourceCode.getAncestors(node);
20
25
  if (log) {
21
26
  console.log(ancestors);
22
27
  }
23
- for (const node of ancestors) {
24
- if (node.type !== "CallExpression" || node.callee.type !== "MemberExpression" || node.callee.object.type !== "Identifier" || node.callee.object.name !== "a") {
28
+ for (const node2 of ancestors) {
29
+ if (node2.type !== "CallExpression" || node2.callee.type !== "MemberExpression" || node2.callee.object.type !== "Identifier" || node2.callee.object.name !== "a") {
25
30
  continue;
26
31
  }
27
- if (node.callee.property.type !== "Identifier") {
32
+ if (node2.callee.property.type !== "Identifier") {
28
33
  continue;
29
34
  }
30
- const nodeName = node.callee.property.name;
35
+ const nodeName = node2.callee.property.name;
31
36
  if (schemaTypes.includes(nodeName)) {
32
37
  return true;
33
38
  }
@@ -49,7 +54,7 @@ const noAnonymousDiscriminator = {
49
54
  if (propName !== "discriminator") {
50
55
  return;
51
56
  }
52
- if (isNestedInSchema(["recursive"], context)) {
57
+ if (isNestedInSchema(node, ["recursive"], context)) {
53
58
  return;
54
59
  }
55
60
  if (node.arguments.length < 3) {
@@ -91,9 +96,16 @@ const noAnonymousEnumerator = {
91
96
  if (propName !== "enumerator" && propName !== "stringEnum") {
92
97
  return;
93
98
  }
99
+ if (isNestedInSchema(
100
+ node,
101
+ ["object", "discriminator", "recursive"],
102
+ context
103
+ )) {
104
+ return;
105
+ }
94
106
  if (node.arguments.length < 2) {
95
107
  context.report({
96
- message: "enum schemas must specify an id",
108
+ message: "root enum schemas must specify an id",
97
109
  node
98
110
  });
99
111
  return;
@@ -107,7 +119,7 @@ const noAnonymousEnumerator = {
107
119
  return;
108
120
  }
109
121
  context.report({
110
- message: "enum schemas must specify an id",
122
+ message: "root enum schemas must specify an id",
111
123
  node
112
124
  });
113
125
  }
@@ -149,7 +161,7 @@ const noAnonymousObject = {
149
161
  }
150
162
  };
151
163
  function handleObject(node, context) {
152
- if (!isRootObjectSchema(context)) {
164
+ if (!isRootObjectSchema(node, context)) {
153
165
  return;
154
166
  }
155
167
  if (node.arguments.length < 2) {
@@ -173,7 +185,7 @@ function handleObject(node, context) {
173
185
  });
174
186
  }
175
187
  function handlePartial(node, context) {
176
- if (!isRootObjectSchema(context)) {
188
+ if (!isRootObjectSchema(node, context)) {
177
189
  return;
178
190
  }
179
191
  if (node.arguments.length < 2) {
@@ -192,7 +204,7 @@ function handlePartial(node, context) {
192
204
  });
193
205
  }
194
206
  function handlePick(node, context) {
195
- if (!isRootObjectSchema(context)) {
207
+ if (!isRootObjectSchema(node, context)) {
196
208
  return;
197
209
  }
198
210
  if (node.arguments.length < 3) {
@@ -210,27 +222,28 @@ function handlePick(node, context) {
210
222
  node
211
223
  });
212
224
  }
213
- function handleExtend(node, context) {
214
- if (!isRootObjectSchema(context)) {
225
+ function handleExtend(expression, context) {
226
+ if (!isRootObjectSchema(expression, context)) {
215
227
  return;
216
228
  }
217
- if (node.arguments.length < 3) {
229
+ if (expression.arguments.length < 3) {
218
230
  context.report({
219
231
  message: defaultMessage,
220
- node
232
+ node: expression
221
233
  });
222
234
  return;
223
235
  }
224
- if (argHasIdKey(node.arguments[2])) {
236
+ if (argHasIdKey(expression.arguments[2])) {
225
237
  return;
226
238
  }
227
239
  context.report({
228
240
  message: defaultMessage,
229
- node
241
+ node: expression
230
242
  });
231
243
  }
232
- function isRootObjectSchema(context, log = false) {
244
+ function isRootObjectSchema(node, context, log = false) {
233
245
  return !isNestedInSchema(
246
+ node,
234
247
  [...guardedSchemaTypes, "discriminator", "recursive"],
235
248
  context,
236
249
  log
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/eslint-plugin",
3
- "version": "0.45.4",
3
+ "version": "0.45.6",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "joshmossas",
@@ -16,6 +16,16 @@
16
16
  },
17
17
  "main": "./dist/plugin.cjs",
18
18
  "module": "./dist/plugin.mjs",
19
+ "exports": {
20
+ ".": {
21
+ "import": "./dist/plugin.mjs",
22
+ "require": "./dist/plugin.cjs"
23
+ },
24
+ "./configs": {
25
+ "import": "./dist/configs.mjs",
26
+ "require": "./dist/configs.cjs"
27
+ }
28
+ },
19
29
  "files": [
20
30
  "dist"
21
31
  ],