@arrirpc/eslint-plugin 0.45.3 → 0.45.5

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.034df0f0.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.3757fb90.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.034df0f0.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.3757fb90.mjs';
@@ -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) {
@@ -149,7 +154,7 @@ const noAnonymousObject = {
149
154
  }
150
155
  };
151
156
  function handleObject(node, context) {
152
- if (!isRootObjectSchema(context)) {
157
+ if (!isRootObjectSchema(node, context)) {
153
158
  return;
154
159
  }
155
160
  if (node.arguments.length < 2) {
@@ -173,7 +178,7 @@ function handleObject(node, context) {
173
178
  });
174
179
  }
175
180
  function handlePartial(node, context) {
176
- if (!isRootObjectSchema(context)) {
181
+ if (!isRootObjectSchema(node, context)) {
177
182
  return;
178
183
  }
179
184
  if (node.arguments.length < 2) {
@@ -192,7 +197,7 @@ function handlePartial(node, context) {
192
197
  });
193
198
  }
194
199
  function handlePick(node, context) {
195
- if (!isRootObjectSchema(context)) {
200
+ if (!isRootObjectSchema(node, context)) {
196
201
  return;
197
202
  }
198
203
  if (node.arguments.length < 3) {
@@ -210,27 +215,28 @@ function handlePick(node, context) {
210
215
  node
211
216
  });
212
217
  }
213
- function handleExtend(node, context) {
214
- if (!isRootObjectSchema(context)) {
218
+ function handleExtend(expression, context) {
219
+ if (!isRootObjectSchema(expression, context)) {
215
220
  return;
216
221
  }
217
- if (node.arguments.length < 3) {
222
+ if (expression.arguments.length < 3) {
218
223
  context.report({
219
224
  message: defaultMessage,
220
- node
225
+ node: expression
221
226
  });
222
227
  return;
223
228
  }
224
- if (argHasIdKey(node.arguments[2])) {
229
+ if (argHasIdKey(expression.arguments[2])) {
225
230
  return;
226
231
  }
227
232
  context.report({
228
233
  message: defaultMessage,
229
- node
234
+ node: expression
230
235
  });
231
236
  }
232
- function isRootObjectSchema(context, log = false) {
237
+ function isRootObjectSchema(node, context, log = false) {
233
238
  return !isNestedInSchema(
239
+ node,
234
240
  [...guardedSchemaTypes, "discriminator", "recursive"],
235
241
  context,
236
242
  log
@@ -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) {
@@ -147,7 +152,7 @@ const noAnonymousObject = {
147
152
  }
148
153
  };
149
154
  function handleObject(node, context) {
150
- if (!isRootObjectSchema(context)) {
155
+ if (!isRootObjectSchema(node, context)) {
151
156
  return;
152
157
  }
153
158
  if (node.arguments.length < 2) {
@@ -171,7 +176,7 @@ function handleObject(node, context) {
171
176
  });
172
177
  }
173
178
  function handlePartial(node, context) {
174
- if (!isRootObjectSchema(context)) {
179
+ if (!isRootObjectSchema(node, context)) {
175
180
  return;
176
181
  }
177
182
  if (node.arguments.length < 2) {
@@ -190,7 +195,7 @@ function handlePartial(node, context) {
190
195
  });
191
196
  }
192
197
  function handlePick(node, context) {
193
- if (!isRootObjectSchema(context)) {
198
+ if (!isRootObjectSchema(node, context)) {
194
199
  return;
195
200
  }
196
201
  if (node.arguments.length < 3) {
@@ -208,27 +213,28 @@ function handlePick(node, context) {
208
213
  node
209
214
  });
210
215
  }
211
- function handleExtend(node, context) {
212
- if (!isRootObjectSchema(context)) {
216
+ function handleExtend(expression, context) {
217
+ if (!isRootObjectSchema(expression, context)) {
213
218
  return;
214
219
  }
215
- if (node.arguments.length < 3) {
220
+ if (expression.arguments.length < 3) {
216
221
  context.report({
217
222
  message: defaultMessage,
218
- node
223
+ node: expression
219
224
  });
220
225
  return;
221
226
  }
222
- if (argHasIdKey(node.arguments[2])) {
227
+ if (argHasIdKey(expression.arguments[2])) {
223
228
  return;
224
229
  }
225
230
  context.report({
226
231
  message: defaultMessage,
227
- node
232
+ node: expression
228
233
  });
229
234
  }
230
- function isRootObjectSchema(context, log = false) {
235
+ function isRootObjectSchema(node, context, log = false) {
231
236
  return !isNestedInSchema(
237
+ node,
232
238
  [...guardedSchemaTypes, "discriminator", "recursive"],
233
239
  context,
234
240
  log
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/eslint-plugin",
3
- "version": "0.45.3",
3
+ "version": "0.45.5",
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
  ],