@arrirpc/eslint-plugin 0.76.4 → 0.77.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/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Arri-RPC Eslint Plugin and Configs
2
2
 
3
- This library provides some useful lint rules when building Arri RPC schemas.
3
+ This library provides some useful lint rules when building schemas for Arri-RPC.
4
+
5
+ If you are using Arri Schema standalone and are not using any of the codegen features the only lint rule you will probably need is `arri/prefer-modular-imports`.
4
6
 
5
7
  ## Installation
6
8
 
@@ -14,26 +16,33 @@ pnpm i --save-dev @arrirpc/eslint-plugin
14
16
 
15
17
  ## Usage
16
18
 
17
- ### Ecosystem Note
18
-
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
-
21
19
  ### Flat File Config
22
20
 
23
- #### Using the default recommended configuration
21
+ #### Use one of the premade configurations
24
22
 
25
- This turns all of the `@arrirpc/eslint` rules on.
23
+ - **recommended**: turns on all of the lint rules related to schema building and codegen
24
+ - **all**: the same as recommended but also includes the `prefer-modular-imports` rule
26
25
 
27
26
  ```js
28
27
  // eslint.config.js
29
28
  import arri from '@arrirpc/eslint-plugin/configs';
30
29
 
30
+ // turn on lint rules related to schema building and codegen
31
31
  export default [
32
32
  arri.recommended,
33
33
  {
34
- files: ['src/**/*.ts'], // you will still need to tell eslint which files to lint like so
34
+ files: ['src/**/*.ts'],
35
35
  },
36
36
  ];
37
+
38
+
39
+ // turn on all arri lint rules
40
+ export default [
41
+ arri.all,
42
+ {
43
+ files: ['src/**/*.ts']
44
+ }
45
+ ]
37
46
  ```
38
47
 
39
48
  #### Manual setup
@@ -58,6 +67,8 @@ export default [
58
67
  'arri/no-anonymous-discriminator': 2,
59
68
  // check to see if an ID has been assigned to a.recursive() schemas
60
69
  'arri/no-anonymous-recursive': 2,
70
+ // enforce using arri's tree-shakable imports instead of the non tree-shakable imports to keep bundle sizes lower
71
+ 'arri/prefer-modular-imports': 2,
61
72
  },
62
73
  },
63
74
  ];
@@ -67,13 +78,18 @@ export default [
67
78
 
68
79
  #### Using the default recommended configuration
69
80
 
70
- This turns all of the `@arrirpc/eslint` rules on
71
-
72
81
  ```jsonc
82
+ // Arri-RPC recommended
73
83
  {
74
84
  "extends": ["plugin:@arrirpc/legacy-config-recommended"],
75
85
  "files": ["**/*.ts"],
76
86
  }
87
+
88
+ // all rules
89
+ {
90
+ "extends": ["plugin:@arrirpc/legacy-config-all"],
91
+ "files": ["**/*.ts"]
92
+ }
77
93
  ```
78
94
 
79
95
  #### Manual Setup
@@ -90,6 +106,8 @@ This turns all of the `@arrirpc/eslint` rules on
90
106
  "@arrirpc/no-anonymous-discriminator": 2,
91
107
  // check to see if an ID has been assigned to a.recursive() schemas
92
108
  "@arrirpc/no-anonymous-recursive": 2,
109
+ // enforce usage of modular imports to reduce bundle size
110
+ "@arrirpc/prefer-modular-imports": 2,
93
111
  },
94
112
  }
95
113
  ```
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.KTsOJsei.cjs');
5
+ const plugin = require('./shared/eslint-plugin.OTGuyyTf.cjs');
6
6
 
7
7
  const flatConfigs = {
8
8
  recommended: {
@@ -13,7 +13,20 @@ const flatConfigs = {
13
13
  "no-anonymous-object": 2,
14
14
  "no-anonymous-enumerator": 2,
15
15
  "no-anonymous-discriminator": 2,
16
- "no-anonymous-recursive": 2
16
+ "no-anonymous-recursive": 2,
17
+ "prefer-modular-imports": 0
18
+ })
19
+ },
20
+ all: {
21
+ plugins: {
22
+ arri: plugin.plugin
23
+ },
24
+ rules: plugin.prefixedRuleMap("arri", {
25
+ "no-anonymous-discriminator": 2,
26
+ "no-anonymous-enumerator": 2,
27
+ "no-anonymous-object": 2,
28
+ "no-anonymous-recursive": 2,
29
+ "prefer-modular-imports": 2
17
30
  })
18
31
  }
19
32
  };
@@ -9,18 +9,39 @@ declare const flatConfigs: {
9
9
  name?: string | undefined;
10
10
  version?: string | undefined;
11
11
  };
12
- configs: Record<string, Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
12
+ configs: Record<string, Linter.Config<Linter.RulesRecord> | Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
13
13
  rules: {
14
14
  readonly 'no-anonymous-discriminator': eslint.Rule.RuleModule;
15
15
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
16
16
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
17
17
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
18
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
18
19
  };
19
20
  };
20
21
  };
21
- rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive", Linter.RuleEntry<any[]>>;
22
+ rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive" | "arri/prefer-modular-imports", Linter.RuleEntry<any[]>>;
23
+ };
24
+ readonly all: {
25
+ plugins: {
26
+ arri: {
27
+ meta: {
28
+ name?: string | undefined;
29
+ version?: string | undefined;
30
+ };
31
+ configs: Record<string, Linter.Config<Linter.RulesRecord> | Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
32
+ rules: {
33
+ readonly 'no-anonymous-discriminator': eslint.Rule.RuleModule;
34
+ readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
35
+ readonly 'no-anonymous-object': eslint.Rule.RuleModule;
36
+ readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
37
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
38
+ };
39
+ };
40
+ };
41
+ rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive" | "arri/prefer-modular-imports", Linter.RuleEntry<any[]>>;
22
42
  };
23
43
  };
24
44
 
45
+ // @ts-ignore
25
46
  export = flatConfigs;
26
47
  export { flatConfigs };
@@ -9,16 +9,36 @@ declare const flatConfigs: {
9
9
  name?: string | undefined;
10
10
  version?: string | undefined;
11
11
  };
12
- configs: Record<string, Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
12
+ configs: Record<string, Linter.Config<Linter.RulesRecord> | Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
13
13
  rules: {
14
14
  readonly 'no-anonymous-discriminator': eslint.Rule.RuleModule;
15
15
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
16
16
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
17
17
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
18
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
18
19
  };
19
20
  };
20
21
  };
21
- rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive", Linter.RuleEntry<any[]>>;
22
+ rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive" | "arri/prefer-modular-imports", Linter.RuleEntry<any[]>>;
23
+ };
24
+ readonly all: {
25
+ plugins: {
26
+ arri: {
27
+ meta: {
28
+ name?: string | undefined;
29
+ version?: string | undefined;
30
+ };
31
+ configs: Record<string, Linter.Config<Linter.RulesRecord> | Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
32
+ rules: {
33
+ readonly 'no-anonymous-discriminator': eslint.Rule.RuleModule;
34
+ readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
35
+ readonly 'no-anonymous-object': eslint.Rule.RuleModule;
36
+ readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
37
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
38
+ };
39
+ };
40
+ };
41
+ rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive" | "arri/prefer-modular-imports", Linter.RuleEntry<any[]>>;
22
42
  };
23
43
  };
24
44
 
package/dist/configs.d.ts CHANGED
@@ -9,18 +9,39 @@ declare const flatConfigs: {
9
9
  name?: string | undefined;
10
10
  version?: string | undefined;
11
11
  };
12
- configs: Record<string, Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
12
+ configs: Record<string, Linter.Config<Linter.RulesRecord> | Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
13
13
  rules: {
14
14
  readonly 'no-anonymous-discriminator': eslint.Rule.RuleModule;
15
15
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
16
16
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
17
17
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
18
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
18
19
  };
19
20
  };
20
21
  };
21
- rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive", Linter.RuleEntry<any[]>>;
22
+ rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive" | "arri/prefer-modular-imports", Linter.RuleEntry<any[]>>;
23
+ };
24
+ readonly all: {
25
+ plugins: {
26
+ arri: {
27
+ meta: {
28
+ name?: string | undefined;
29
+ version?: string | undefined;
30
+ };
31
+ configs: Record<string, Linter.Config<Linter.RulesRecord> | Linter.LegacyConfig<Linter.RulesRecord, Linter.RulesRecord> | Linter.Config<Linter.RulesRecord>[]>;
32
+ rules: {
33
+ readonly 'no-anonymous-discriminator': eslint.Rule.RuleModule;
34
+ readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
35
+ readonly 'no-anonymous-object': eslint.Rule.RuleModule;
36
+ readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
37
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
38
+ };
39
+ };
40
+ };
41
+ rules: Record<"arri/no-anonymous-discriminator" | "arri/no-anonymous-enumerator" | "arri/no-anonymous-object" | "arri/no-anonymous-recursive" | "arri/prefer-modular-imports", Linter.RuleEntry<any[]>>;
22
42
  };
23
43
  };
24
44
 
45
+ // @ts-ignore
25
46
  export = flatConfigs;
26
47
  export { flatConfigs };
package/dist/configs.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { p as prefixedRuleMap, a as plugin } from './shared/eslint-plugin.B2xKduqu.mjs';
1
+ import { p as prefixedRuleMap, a as plugin } from './shared/eslint-plugin.TPk3R2S0.mjs';
2
2
 
3
3
  const flatConfigs = {
4
4
  recommended: {
@@ -9,7 +9,20 @@ const flatConfigs = {
9
9
  "no-anonymous-object": 2,
10
10
  "no-anonymous-enumerator": 2,
11
11
  "no-anonymous-discriminator": 2,
12
- "no-anonymous-recursive": 2
12
+ "no-anonymous-recursive": 2,
13
+ "prefer-modular-imports": 0
14
+ })
15
+ },
16
+ all: {
17
+ plugins: {
18
+ arri: plugin
19
+ },
20
+ rules: prefixedRuleMap("arri", {
21
+ "no-anonymous-discriminator": 2,
22
+ "no-anonymous-enumerator": 2,
23
+ "no-anonymous-object": 2,
24
+ "no-anonymous-recursive": 2,
25
+ "prefer-modular-imports": 2
13
26
  })
14
27
  }
15
28
  };
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.KTsOJsei.cjs');
5
+ const plugin = require('./shared/eslint-plugin.OTGuyyTf.cjs');
6
6
 
7
7
 
8
8
 
package/dist/plugin.d.cts CHANGED
@@ -8,6 +8,7 @@ declare const rules: {
8
8
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
9
9
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
10
10
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
11
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
11
12
  };
12
13
  declare const _default: {
13
14
  meta: {
@@ -20,8 +21,10 @@ declare const _default: {
20
21
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
21
22
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
22
23
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
24
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
23
25
  };
24
26
  };
25
27
 
28
+ // @ts-ignore
26
29
  export = _default;
27
30
  export { configs, meta, rules };
package/dist/plugin.d.mts CHANGED
@@ -8,6 +8,7 @@ declare const rules: {
8
8
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
9
9
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
10
10
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
11
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
11
12
  };
12
13
  declare const _default: {
13
14
  meta: {
@@ -20,6 +21,7 @@ declare const _default: {
20
21
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
21
22
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
22
23
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
24
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
23
25
  };
24
26
  };
25
27
 
package/dist/plugin.d.ts CHANGED
@@ -8,6 +8,7 @@ declare const rules: {
8
8
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
9
9
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
10
10
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
11
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
11
12
  };
12
13
  declare const _default: {
13
14
  meta: {
@@ -20,8 +21,10 @@ declare const _default: {
20
21
  readonly 'no-anonymous-enumerator': eslint.Rule.RuleModule;
21
22
  readonly 'no-anonymous-object': eslint.Rule.RuleModule;
22
23
  readonly 'no-anonymous-recursive': eslint.Rule.RuleModule;
24
+ readonly 'prefer-modular-imports': eslint.Rule.RuleModule;
23
25
  };
24
26
  };
25
27
 
28
+ // @ts-ignore
26
29
  export = _default;
27
30
  export { configs, meta, rules };
package/dist/plugin.mjs CHANGED
@@ -1 +1 @@
1
- export { c as configs, a as default, m as meta, r as rules } from './shared/eslint-plugin.B2xKduqu.mjs';
1
+ export { c as configs, a as default, m as meta, r as rules } from './shared/eslint-plugin.TPk3R2S0.mjs';
@@ -287,11 +287,108 @@ const noAnonymousRecursive = {
287
287
  }
288
288
  };
289
289
 
290
+ const preferModularImports = {
291
+ meta: {
292
+ type: "suggestion",
293
+ fixable: "code",
294
+ messages: {
295
+ arriModularImportError: "use Arri's modular import syntax instead"
296
+ }
297
+ },
298
+ create(context) {
299
+ return {
300
+ ImportDeclaration(node) {
301
+ if (node.source.value !== "@arrirpc/schema") return;
302
+ let targetNode;
303
+ let numIdentifiers = 0;
304
+ for (let i = 0; i < node.specifiers.length; i++) {
305
+ const specifier = node.specifiers[i];
306
+ if (specifier.type !== "ImportSpecifier") continue;
307
+ if (specifier.imported.type !== "Identifier") continue;
308
+ numIdentifiers++;
309
+ if (specifier.imported.name !== "a") continue;
310
+ targetNode = specifier;
311
+ }
312
+ if (!targetNode) return;
313
+ const fix = (fixer) => {
314
+ if (numIdentifiers === 1) {
315
+ return fixer.replaceText(
316
+ node,
317
+ "import * as a from '@arrirpc/schema';"
318
+ );
319
+ }
320
+ const parent = node.parent;
321
+ if (parent.type !== "Program")
322
+ return fixer.insertTextAfter(node, "");
323
+ const newStringParts = [];
324
+ let skipNext = false;
325
+ let importPart = "";
326
+ let shouldExitNext = false;
327
+ const loc = node.loc;
328
+ console.log("LOC", loc);
329
+ for (let i = 0; i < parent.tokens.length; i++) {
330
+ const token = parent.tokens[i];
331
+ if (shouldExitNext) {
332
+ if (token.value === ";") {
333
+ newStringParts.push(token.value);
334
+ }
335
+ break;
336
+ }
337
+ console.log("TOKEN", token.loc);
338
+ if (token.loc.start.line > (loc?.start.line ?? 0))
339
+ break;
340
+ if (token.loc.start.line !== loc?.start.line) continue;
341
+ if (skipNext && token.type == "Punctuator" && token.value === ",") {
342
+ skipNext = false;
343
+ continue;
344
+ }
345
+ skipNext = false;
346
+ if (token.type == "Identifier" && token.value === "a") {
347
+ skipNext = true;
348
+ continue;
349
+ }
350
+ switch (token.value) {
351
+ case "import":
352
+ case "from":
353
+ case "{":
354
+ case ",":
355
+ newStringParts.push(token.value + " ");
356
+ break;
357
+ case "}":
358
+ newStringParts.push(" " + token.value + " ");
359
+ break;
360
+ case "'@arrirpc/schema'":
361
+ case '"@arrirpc/schema"':
362
+ importPart = token.value;
363
+ newStringParts.push(token.value);
364
+ shouldExitNext = true;
365
+ break;
366
+ default:
367
+ newStringParts.push(token.value);
368
+ }
369
+ }
370
+ return fixer.replaceText(
371
+ node,
372
+ `import * as a from ${importPart};
373
+ ${newStringParts.join("")}`
374
+ );
375
+ };
376
+ context.report({
377
+ node: targetNode,
378
+ messageId: "arriModularImportError",
379
+ fix
380
+ });
381
+ }
382
+ };
383
+ }
384
+ };
385
+
290
386
  const rules$1 = {
291
387
  "no-anonymous-discriminator": noAnonymousDiscriminator,
292
388
  "no-anonymous-enumerator": noAnonymousEnumerator,
293
389
  "no-anonymous-object": noAnonymousObject,
294
- "no-anonymous-recursive": noAnonymousRecursive
390
+ "no-anonymous-recursive": noAnonymousRecursive,
391
+ "prefer-modular-imports": preferModularImports
295
392
  };
296
393
  function prefixedRuleMap(prefix, rules2) {
297
394
  const result = {};
@@ -311,7 +408,18 @@ const configs = {
311
408
  "no-anonymous-object": 2,
312
409
  "no-anonymous-recursive": 2,
313
410
  "no-anonymous-discriminator": 2,
314
- "no-anonymous-enumerator": 2
411
+ "no-anonymous-enumerator": 2,
412
+ "prefer-modular-imports": 0
413
+ })
414
+ },
415
+ "legacy-config-all": {
416
+ plugins: ["@arrirpc"],
417
+ rules: prefixedRuleMap("@arrirpc", {
418
+ "no-anonymous-object": 2,
419
+ "no-anonymous-recursive": 2,
420
+ "no-anonymous-discriminator": 2,
421
+ "no-anonymous-enumerator": 2,
422
+ "prefer-modular-imports": 2
315
423
  })
316
424
  }
317
425
  };
@@ -285,11 +285,108 @@ const noAnonymousRecursive = {
285
285
  }
286
286
  };
287
287
 
288
+ const preferModularImports = {
289
+ meta: {
290
+ type: "suggestion",
291
+ fixable: "code",
292
+ messages: {
293
+ arriModularImportError: "use Arri's modular import syntax instead"
294
+ }
295
+ },
296
+ create(context) {
297
+ return {
298
+ ImportDeclaration(node) {
299
+ if (node.source.value !== "@arrirpc/schema") return;
300
+ let targetNode;
301
+ let numIdentifiers = 0;
302
+ for (let i = 0; i < node.specifiers.length; i++) {
303
+ const specifier = node.specifiers[i];
304
+ if (specifier.type !== "ImportSpecifier") continue;
305
+ if (specifier.imported.type !== "Identifier") continue;
306
+ numIdentifiers++;
307
+ if (specifier.imported.name !== "a") continue;
308
+ targetNode = specifier;
309
+ }
310
+ if (!targetNode) return;
311
+ const fix = (fixer) => {
312
+ if (numIdentifiers === 1) {
313
+ return fixer.replaceText(
314
+ node,
315
+ "import * as a from '@arrirpc/schema';"
316
+ );
317
+ }
318
+ const parent = node.parent;
319
+ if (parent.type !== "Program")
320
+ return fixer.insertTextAfter(node, "");
321
+ const newStringParts = [];
322
+ let skipNext = false;
323
+ let importPart = "";
324
+ let shouldExitNext = false;
325
+ const loc = node.loc;
326
+ console.log("LOC", loc);
327
+ for (let i = 0; i < parent.tokens.length; i++) {
328
+ const token = parent.tokens[i];
329
+ if (shouldExitNext) {
330
+ if (token.value === ";") {
331
+ newStringParts.push(token.value);
332
+ }
333
+ break;
334
+ }
335
+ console.log("TOKEN", token.loc);
336
+ if (token.loc.start.line > (loc?.start.line ?? 0))
337
+ break;
338
+ if (token.loc.start.line !== loc?.start.line) continue;
339
+ if (skipNext && token.type == "Punctuator" && token.value === ",") {
340
+ skipNext = false;
341
+ continue;
342
+ }
343
+ skipNext = false;
344
+ if (token.type == "Identifier" && token.value === "a") {
345
+ skipNext = true;
346
+ continue;
347
+ }
348
+ switch (token.value) {
349
+ case "import":
350
+ case "from":
351
+ case "{":
352
+ case ",":
353
+ newStringParts.push(token.value + " ");
354
+ break;
355
+ case "}":
356
+ newStringParts.push(" " + token.value + " ");
357
+ break;
358
+ case "'@arrirpc/schema'":
359
+ case '"@arrirpc/schema"':
360
+ importPart = token.value;
361
+ newStringParts.push(token.value);
362
+ shouldExitNext = true;
363
+ break;
364
+ default:
365
+ newStringParts.push(token.value);
366
+ }
367
+ }
368
+ return fixer.replaceText(
369
+ node,
370
+ `import * as a from ${importPart};
371
+ ${newStringParts.join("")}`
372
+ );
373
+ };
374
+ context.report({
375
+ node: targetNode,
376
+ messageId: "arriModularImportError",
377
+ fix
378
+ });
379
+ }
380
+ };
381
+ }
382
+ };
383
+
288
384
  const rules$1 = {
289
385
  "no-anonymous-discriminator": noAnonymousDiscriminator,
290
386
  "no-anonymous-enumerator": noAnonymousEnumerator,
291
387
  "no-anonymous-object": noAnonymousObject,
292
- "no-anonymous-recursive": noAnonymousRecursive
388
+ "no-anonymous-recursive": noAnonymousRecursive,
389
+ "prefer-modular-imports": preferModularImports
293
390
  };
294
391
  function prefixedRuleMap(prefix, rules2) {
295
392
  const result = {};
@@ -309,7 +406,18 @@ const configs = {
309
406
  "no-anonymous-object": 2,
310
407
  "no-anonymous-recursive": 2,
311
408
  "no-anonymous-discriminator": 2,
312
- "no-anonymous-enumerator": 2
409
+ "no-anonymous-enumerator": 2,
410
+ "prefer-modular-imports": 0
411
+ })
412
+ },
413
+ "legacy-config-all": {
414
+ plugins: ["@arrirpc"],
415
+ rules: prefixedRuleMap("@arrirpc", {
416
+ "no-anonymous-object": 2,
417
+ "no-anonymous-recursive": 2,
418
+ "no-anonymous-discriminator": 2,
419
+ "no-anonymous-enumerator": 2,
420
+ "prefer-modular-imports": 2
313
421
  })
314
422
  }
315
423
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/eslint-plugin",
3
- "version": "0.76.4",
3
+ "version": "0.77.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {