@eslinted/core 26.0.0 → 26.1.0-rc.1

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 (54) hide show
  1. package/dist/factory.d.ts +7 -38
  2. package/dist/factory.d.ts.map +1 -1
  3. package/dist/factory.js +106 -95
  4. package/dist/factory.js.map +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -4
  8. package/dist/index.js.map +1 -1
  9. package/dist/interface/configuration/defaults/index.d.ts +5 -5
  10. package/dist/interface/configuration/defaults/index.d.ts.map +1 -1
  11. package/dist/interface/configuration/extensions/index.d.ts +1 -1
  12. package/dist/interface/configuration/extensions/index.d.ts.map +1 -1
  13. package/dist/interface/configuration/index.d.ts +1 -1
  14. package/dist/interface/configuration/index.d.ts.map +1 -1
  15. package/dist/interface/imports.d.ts +3 -3
  16. package/dist/interface/imports.d.ts.map +1 -1
  17. package/dist/interface/index.d.ts +3 -3
  18. package/dist/interface/index.d.ts.map +1 -1
  19. package/dist/scope/dependencies/index.d.ts +2 -2
  20. package/dist/scope/dependencies/index.d.ts.map +1 -1
  21. package/dist/scope/dependencies/parsers.d.ts +1 -1
  22. package/dist/scope/dependencies/parsers.d.ts.map +1 -1
  23. package/dist/scope/dependencies/plugins.d.ts +1 -1
  24. package/dist/scope/dependencies/plugins.d.ts.map +1 -1
  25. package/dist/scope/index.d.ts +2 -2
  26. package/dist/scope/index.d.ts.map +1 -1
  27. package/dist/scope/index.js +1 -1
  28. package/dist/scope/{tree/index.d.ts → tree.d.ts} +1 -1
  29. package/dist/scope/tree.d.ts.map +1 -0
  30. package/dist/scope/{tree/index.js → tree.js} +1 -1
  31. package/dist/scope/tree.js.map +1 -0
  32. package/dist/scope/tree.spec.d.ts +2 -0
  33. package/dist/scope/tree.spec.d.ts.map +1 -0
  34. package/dist/scope/{tree/index.spec.js → tree.spec.js} +2 -2
  35. package/dist/scope/tree.spec.js.map +1 -0
  36. package/package.json +1 -1
  37. package/src/factory.ts +229 -198
  38. package/src/index.ts +8 -19
  39. package/src/interface/configuration/defaults/index.ts +15 -13
  40. package/src/interface/configuration/extensions/index.ts +2 -2
  41. package/src/interface/configuration/index.ts +5 -3
  42. package/src/interface/imports.ts +4 -4
  43. package/src/interface/index.ts +5 -5
  44. package/src/scope/dependencies/index.ts +2 -2
  45. package/src/scope/dependencies/parsers.ts +1 -1
  46. package/src/scope/dependencies/plugins.ts +1 -1
  47. package/src/scope/index.ts +2 -2
  48. package/src/scope/{tree/index.spec.ts → tree.spec.ts} +1 -1
  49. package/dist/scope/tree/index.d.ts.map +0 -1
  50. package/dist/scope/tree/index.js.map +0 -1
  51. package/dist/scope/tree/index.spec.d.ts +0 -2
  52. package/dist/scope/tree/index.spec.d.ts.map +0 -1
  53. package/dist/scope/tree/index.spec.js.map +0 -1
  54. /package/src/scope/{tree/index.ts → tree.ts} +0 -0
package/src/factory.ts CHANGED
@@ -1,89 +1,58 @@
1
1
  import type { Input } from "./interface";
2
2
 
3
- export class Factory<
3
+ export default function factory<
4
4
  Scope extends string,
5
5
  OptionalScope extends Scope,
6
- RequiredPlugin extends string,
7
- RequiredParser extends Scope,
8
- > {
9
- public globalConfigs;
10
- public scopes;
11
- public parsers;
12
- private readonly settings;
13
-
14
- constructor(
15
- tree: Array<
16
- readonly [
17
- Scope,
18
- readonly Scope[],
19
- ]
20
- >,
21
- optionalScopes: readonly Scope[],
22
- {
23
- plugins,
24
- parsers,
25
- }: Input<
26
- Scope,
27
- OptionalScope,
28
- RequiredPlugin,
29
- RequiredParser
30
- >["imports"],
31
- defaults: Input<
32
- Scope,
33
- OptionalScope,
34
- RequiredPlugin,
35
- RequiredParser
36
- >["configuration"]["defaults"],
37
- extensions: Input<
6
+ BundledPlugin extends string,
7
+ BundledParser extends Scope,
8
+ // Tree,
9
+ >(
10
+ scopes: readonly Scope[],
11
+ optionalScopes: readonly OptionalScope[],
12
+ tree: Array<
13
+ readonly [
38
14
  Scope,
39
- OptionalScope,
40
- RequiredPlugin,
41
- RequiredParser
42
- >["configuration"]["extensions"] = {},
43
- ) {
44
- this.settings = defaults.settings;
45
-
46
- if ("svelte" in extensions && "plugin" in (extensions.svelte as object)) {
15
+ readonly Scope[],
16
+ ]
17
+ >,
18
+ {
19
+ plugins,
20
+ parsers,
21
+ }: {
22
+ plugins: Record<BundledPlugin, unknown>;
23
+ parsers: Record<BundledParser, unknown>;
24
+ },
25
+ defaults: Input<
26
+ Scope,
27
+ OptionalScope,
28
+ BundledPlugin,
29
+ BundledParser
30
+ >["configuration"]["defaults"],
31
+ extensions: Input<
32
+ Scope,
33
+ OptionalScope,
34
+ BundledPlugin,
35
+ BundledParser
36
+ >["configuration"]["extensions"] = {},
37
+ ) {
38
+ for (const scope of optionalScopes)
39
+ if (extensions[scope] !== undefined) {
47
40
  Object.assign(
48
41
  plugins,
49
42
  {
50
- svelte: (extensions.svelte as { plugin: unknown }).plugin,
43
+ [scope]: extensions[scope].plugin,
51
44
  },
52
45
  );
53
46
  Object.assign(
54
47
  parsers,
55
48
  {
56
- svelte: (extensions.svelte as { parser: unknown }).parser,
49
+ [scope]: extensions[scope].parser,
57
50
  },
58
51
  );
59
52
  }
60
53
 
61
- const ignores = extensions["*"]?.override === true
62
- ? extensions["*"].ignores ?? []
63
- : defaults.ignores["*"].concat(extensions["*"]?.ignores ?? []);
64
-
65
- this.globalConfigs = {
66
- plugins: {
67
- name: "linted/*/plugins",
68
- plugins,
69
- },
70
- ignores: {
71
- name: "linted/*/ignores",
72
- ignores,
73
- },
74
- };
75
- this.scopes = {
76
- files: defaults.files,
77
- ignores: defaults.ignores,
78
- rules: defaults.rules,
79
- };
80
- this.parsers = parsers;
81
-
82
- const extended = new Set<Scope>(Object.keys(extensions) as unknown[] as Scope[]);
83
-
84
- extended.delete("*" as unknown as Scope);
85
-
86
- for (const scope of extended) {
54
+ for (const scope of scopes)
55
+ if (extensions[scope] !== undefined) {
87
56
  const {
88
57
  [scope]: {
89
58
  files = [],
@@ -92,150 +61,212 @@ export class Factory<
92
61
  } = {},
93
62
  } = extensions;
94
63
 
95
- if (files.length !== 0) {
96
- const defaultFiles = this.scopes.files[scope],
97
- fEnd = defaultFiles.length;
98
-
99
- defaultFiles.length += files.length;
100
-
101
- for (let i = 0; i < files.length; i++)
102
- defaultFiles[fEnd + i] = files[i] as string;
103
- }
104
-
105
- if (ignores.length !== 0) {
106
- const defaultIgnores = this.scopes.ignores[scope],
107
- iEnd = defaultIgnores.length;
108
-
109
- defaultIgnores.length += ignores.length;
110
-
111
- for (let i = 0; i < ignores.length; i++)
112
- defaultIgnores[iEnd + i] = ignores[i] as string;
113
- }
64
+ if (files.length !== 0)
65
+ if (defaults.files[scope] === undefined)
66
+ Object.assign(
67
+ defaults.files,
68
+ { [scope]: files },
69
+ );
70
+ else {
71
+ const defaultFiles = defaults.files[scope],
72
+ L = defaultFiles.length;
73
+
74
+ defaultFiles.length += files.length;
75
+
76
+ for (let i = 0; i < files.length; i++)
77
+ defaultFiles[L + i] = files[i] as string;
78
+ }
79
+
80
+ if (ignores.length !== 0)
81
+ if (defaults.ignores[scope] === undefined)
82
+ Object.assign(
83
+ defaults.ignores,
84
+ { [scope]: ignores },
85
+ );
86
+ else {
87
+ const defaultIgnores = defaults.ignores[scope],
88
+ L = defaultIgnores.length;
89
+
90
+ defaultIgnores.length += ignores.length;
91
+
92
+ for (let i = 0; i < ignores.length; i++)
93
+ defaultIgnores[L + i] = ignores[i] as string;
94
+ }
114
95
 
115
96
  if (rules !== null)
116
- this.scopes.rules[scope][
117
- this.scopes.rules[scope].length
118
- ] = {
119
- id: scope.concat("/override"),
120
- rules,
121
- };
97
+ if (defaults.rules[scope] === undefined)
98
+ Object.assign(
99
+ defaults.rules,
100
+ {
101
+ [scope]: [
102
+ {
103
+ id: scope.concat("/override"),
104
+ rules,
105
+ },
106
+ ],
107
+ },
108
+ );
109
+ else
110
+ /* eslint-disable no-param-reassign */
111
+ defaults.rules[scope][
112
+ defaults.rules[scope].length
113
+ ] = {
114
+ id: scope.concat("/override"),
115
+ rules,
116
+ };
122
117
  }
123
118
 
124
- const OptionalScopes = new Set<Scope>(optionalScopes);
119
+ const OptionalScope = new Set<Scope>(optionalScopes);
125
120
 
126
- for (const [scope, parents] of tree)
127
- if (
128
- !OptionalScopes.has(scope)
129
- || scope in this.parsers
130
- ) {
131
- const files = this.scopes.files[scope],
132
- ignores = this.scopes.ignores[scope];
121
+ for (const [scope, parents] of tree)
122
+ if (
123
+ !OptionalScope.has(scope)
124
+ || scope in parsers
125
+ ) {
126
+ const files = defaults.files[scope],
127
+ ignores = defaults.ignores[scope];
133
128
 
129
+ if (files !== undefined)
134
130
  if (files.length !== 0)
135
- for (const parent of parents) {
136
- const parentFiles = this.scopes.files[parent],
137
- fEnd = parentFiles.length;
138
-
139
- parentFiles.length += files.length;
140
-
141
- for (let i = 0; i < files.length; i++)
142
- parentFiles[fEnd + i] = files[i] as string;
143
- }
144
-
131
+ for (const parent of parents)
132
+ if (defaults.files[parent] === undefined)
133
+ Object.assign(
134
+ defaults.files,
135
+ { [parent]: files },
136
+ );
137
+ else {
138
+ const parentFiles = defaults.files[parent],
139
+ L = parentFiles.length;
140
+
141
+ parentFiles.length += files.length;
142
+
143
+ for (let i = 0; i < files.length; i++)
144
+ parentFiles[L + i] = files[i]!;
145
+ }
146
+
147
+ if (ignores !== undefined)
145
148
  if (ignores.length !== 0)
146
- for (const parent of parents) {
147
- const parentIgnores = this.scopes.ignores[parent],
148
- iEnd = parentIgnores.length;
149
-
150
- parentIgnores.length += ignores.length;
151
-
152
- for (let i = 0; i < ignores.length; i++)
153
- parentIgnores[iEnd + i] = ignores[i] as string;
154
- }
155
- }
156
- }
157
-
158
- public get globals() {
159
- return [
160
- this.globalConfigs.plugins,
161
- this.globalConfigs.ignores,
162
- ];
163
- }
164
-
165
- public scope(scope: Scope) {
166
- const {
167
- files: { [scope]: files },
168
- ignores: { [scope]: ignores },
169
- rules: { [scope]: rules },
170
- } = this.scopes;
149
+ for (const parent of parents)
150
+ if (defaults.ignores[parent] === undefined)
151
+ Object.assign(
152
+ defaults.ignores,
153
+ { [parent]: ignores },
154
+ );
155
+ else {
156
+ const parentIgnores = defaults.ignores[parent],
157
+ L = parentIgnores.length;
158
+
159
+ parentIgnores.length += ignores.length;
160
+
161
+ for (let i = 0; i < ignores.length; i++)
162
+ parentIgnores[L + i] = ignores[i]!;
163
+ }
164
+ }
171
165
 
172
- if (files.length === 0 || rules.length === 0)
173
- return [];
174
- else {
166
+ const configs: unknown[] = [
167
+ {
168
+ name: "linted/*/plugins",
169
+ plugins,
170
+ },
171
+ {
172
+ name: "linted/*/ignores",
173
+ ignores: extensions["*"]?.override === true
174
+ ? extensions["*"].ignores ?? []
175
+ : defaults.ignores["*"].concat(extensions["*"]?.ignores ?? []),
176
+ },
177
+ ],
178
+ scopeConfigs: unknown[] = scopes.flatMap(
179
+ scope => {
175
180
  const {
176
- languageOptions = {},
177
- parserOptions = {},
178
- processor,
179
- language,
180
- } = this.settings[scope];
181
-
182
- if ("parser" in languageOptions)
183
- if (languageOptions.parser in this.parsers)
184
- languageOptions.parser = this.parsers[languageOptions.parser as RequiredParser] as unknown as RequiredParser;
185
- else
186
- return [];
181
+ files: { [scope]: files },
182
+ ignores: { [scope]: ignores = [] },
183
+ rules: { [scope]: rules },
184
+ settings: { [scope]: settings },
185
+ } = defaults;
187
186
 
188
- if ("parser" in parserOptions)
189
- if (parserOptions.parser in this.parsers)
190
- parserOptions.parser = this.parsers[parserOptions.parser as RequiredParser] as unknown as RequiredParser;
191
- else
192
- return [];
193
-
194
- const manifest = {
195
- name: "linted/".concat(scope),
196
- files,
197
- ignores,
198
- };
199
-
200
- if (Object.keys(parserOptions).length !== 0)
201
- Object.assign(
202
- languageOptions,
203
- { parserOptions },
204
- );
187
+ if (
188
+ files === undefined
189
+ || rules === undefined
190
+ || files.length === 0
191
+ || rules.length === 0
192
+ || OptionalScope.has(scope)
193
+ && !(scope in parsers)
194
+
195
+ )
196
+ return [];
197
+ else {
198
+ const manifest = {
199
+ name: "linted/".concat(scope),
200
+ files,
201
+ ignores,
202
+ };
205
203
 
206
- if (Object.keys(languageOptions).length !== 0)
207
- Object.assign(
208
- manifest,
209
- { languageOptions },
204
+ if (settings !== undefined) {
205
+ const {
206
+ languageOptions = {},
207
+ parserOptions,
208
+ processor,
209
+ language,
210
+ } = settings;
211
+
212
+ if (languageOptions.parser !== undefined)
213
+ languageOptions.parser = parsers[languageOptions.parser as BundledParser] as unknown as BundledParser;
214
+
215
+ if (parserOptions?.parser !== undefined)
216
+ parserOptions.parser = parsers[parserOptions.parser as BundledParser] as unknown as BundledParser;
217
+
218
+ if (parserOptions !== undefined && Object.keys(parserOptions).length !== 0)
219
+ Object.assign(
220
+ languageOptions,
221
+ { parserOptions },
222
+ );
223
+
224
+ if (Object.keys(languageOptions).length !== 0)
225
+ Object.assign(
226
+ manifest,
227
+ { languageOptions },
228
+ );
229
+
230
+ if (processor !== undefined)
231
+ Object.assign(
232
+ manifest,
233
+ { processor },
234
+ );
235
+
236
+ if (language !== undefined)
237
+ Object.assign(
238
+ manifest,
239
+ { language },
240
+ );
241
+ }
242
+
243
+ return [manifest].concat(
244
+ rules.map(
245
+ (
246
+ {
247
+ id,
248
+ rules,
249
+ },
250
+ ) => ({
251
+ name: "linted/".concat(scope, "/", id),
252
+ files,
253
+ ignores,
254
+ rules,
255
+ }),
256
+ ),
210
257
  );
258
+ }
259
+ },
260
+ );
211
261
 
212
- if (processor !== undefined)
213
- Object.assign(
214
- manifest,
215
- { processor },
216
- );
262
+ if (scopeConfigs.length !== 0) {
263
+ const L = configs.length;
217
264
 
218
- if (language !== undefined)
219
- Object.assign(
220
- manifest,
221
- { language },
222
- );
265
+ configs.length += scopeConfigs.length;
223
266
 
224
- return [manifest].concat(
225
- rules.map(
226
- (
227
- {
228
- id,
229
- rules,
230
- },
231
- ) => ({
232
- name: "linted/".concat(scope, "/", id),
233
- files,
234
- ignores,
235
- rules,
236
- }),
237
- ),
238
- );
239
- }
267
+ for (let i = 0; i < scopeConfigs.length; i++)
268
+ configs[L + i] = scopeConfigs[i];
240
269
  }
270
+
271
+ return configs;
241
272
  }
package/src/index.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import type { Input } from "./interface";
2
2
  import type {
3
- RequiredPlugin,
4
- RequiredParser,
3
+ BundledPlugin,
4
+ BundledParser,
5
5
  } from "./scope";
6
6
  import {
7
7
  scopes,
8
8
  optionalScopes,
9
9
  tree,
10
10
  } from "./scope";
11
- import { Factory } from "./factory";
11
+ import factory from "./factory";
12
12
 
13
13
  export default function (
14
14
  {
@@ -20,27 +20,16 @@ export default function (
20
20
  }: Input<
21
21
  (typeof scopes[number]),
22
22
  (typeof optionalScopes[number]),
23
- RequiredPlugin,
24
- RequiredParser
23
+ BundledPlugin,
24
+ BundledParser
25
25
  >,
26
26
  ) {
27
- const factory = new Factory<
28
- (typeof scopes[number]),
29
- (typeof optionalScopes[number]),
30
- RequiredPlugin,
31
- RequiredParser
32
- >(
33
- tree,
27
+ return factory(
28
+ scopes,
34
29
  optionalScopes,
30
+ tree,
35
31
  imports,
36
32
  defaults,
37
33
  extensions,
38
34
  );
39
-
40
- return (factory.globals as unknown[])
41
- .concat(
42
- scopes.flatMap(
43
- scope => factory.scope(scope),
44
- ),
45
- );
46
35
  }
@@ -5,26 +5,28 @@ export interface Defaults<
5
5
  Scope extends string,
6
6
  Parser extends Scope,
7
7
  > {
8
- settings: Settings<
8
+ settings: Partial<Settings<
9
9
  Scope,
10
10
  Parser
11
- >;
12
- files: Record<
11
+ >>;
12
+ files: Partial<Record<
13
13
  Scope,
14
14
  string[]
15
- >;
16
- ignores: Record<
17
- (
18
- | "*"
19
- | Scope
20
- ),
21
- string[]
22
- >;
23
- rules: Record<
15
+ >>;
16
+ ignores:
17
+ & Record<
18
+ "*",
19
+ string[]
20
+ >
21
+ & Partial<Record<
22
+ Scope,
23
+ string[]
24
+ >>;
25
+ rules: Partial<Record<
24
26
  Scope,
25
27
  {
26
28
  id: string;
27
29
  rules: Rules;
28
30
  }[]
29
- >;
31
+ >>;
30
32
  }
@@ -5,5 +5,5 @@ export type Extensions<
5
5
  Scope extends string,
6
6
  OptionalScope extends Scope,
7
7
  >
8
- = & Partial<GlobalExtension>
9
- & Partial<ScopeExtensions<Scope, OptionalScope>>;
8
+ = & GlobalExtension
9
+ & ScopeExtensions<Scope, OptionalScope>;
@@ -10,8 +10,10 @@ export interface Configuration<
10
10
  Scope,
11
11
  Parser
12
12
  >;
13
- extensions: Extensions<
14
- Scope,
15
- OptionalScope
13
+ extensions: Partial<
14
+ Extensions<
15
+ Scope,
16
+ OptionalScope
17
+ >
16
18
  >;
17
19
  }
@@ -1,13 +1,13 @@
1
1
  export interface Imports<
2
- RequiredPlugin extends string,
3
- RequiredParser extends string,
2
+ BundledPlugin extends string,
3
+ BundledParser extends string,
4
4
  > {
5
5
  plugins: Record<
6
- RequiredPlugin,
6
+ BundledPlugin,
7
7
  unknown
8
8
  >;
9
9
  parsers: Record<
10
- RequiredParser,
10
+ BundledParser,
11
11
  unknown
12
12
  >;
13
13
  }
@@ -4,18 +4,18 @@ import type { Configuration } from "./configuration";
4
4
  export interface Input<
5
5
  Scope extends string,
6
6
  OptionalScope extends Scope,
7
- RequiredPlugin extends string,
8
- RequiredParser extends Scope,
7
+ BundledPlugin extends string,
8
+ BundledParser extends Scope,
9
9
  > {
10
10
  imports: Imports<
11
- RequiredPlugin,
12
- RequiredParser
11
+ BundledPlugin,
12
+ BundledParser
13
13
  >;
14
14
  configuration: Configuration<
15
15
  Scope,
16
16
  OptionalScope,
17
17
  (
18
- | RequiredParser
18
+ | BundledParser
19
19
  | OptionalScope
20
20
  )
21
21
  >;
@@ -1,2 +1,2 @@
1
- export type { RequiredPlugin } from "./plugins";
2
- export type { RequiredParser } from "./parsers";
1
+ export type { BundledPlugin } from "./plugins";
2
+ export type { BundledParser } from "./parsers";
@@ -1,4 +1,4 @@
1
- export type RequiredParser
1
+ export type BundledParser
2
2
  = | "ts"
3
3
  | "html"
4
4
  | "yml";
@@ -1,4 +1,4 @@
1
- export type RequiredPlugin
1
+ export type BundledPlugin
2
2
  = | "@stylistic"
3
3
  | "@typescript-eslint"
4
4
  | "mocha"
@@ -13,6 +13,6 @@ export const scopes = [
13
13
  export const optionalScopes = ["svelte"] as const;
14
14
  export { tree } from "./tree";
15
15
  export type {
16
- RequiredPlugin,
17
- RequiredParser,
16
+ BundledPlugin,
17
+ BundledParser,
18
18
  } from "./dependencies";
@@ -1,5 +1,5 @@
1
1
  import "chai/register-should.js";
2
- import { tree } from ".";
2
+ import { tree } from "./tree";
3
3
 
4
4
  const nodes = tree.map(([scope]) => scope);
5
5
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/scope/tree/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,qMAqBhB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scope/tree/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB;QACE,QAAQ;QACR,CAAC,OAAO,CAAC;KACD;IACV;QACE,OAAO;QACP,CAAC,MAAM,CAAC;KACA;IACV;QACE,OAAO;QACP,CAAC,IAAI,CAAC;KACE;IACV;QACE,QAAQ;QACR,CAAC,IAAI,CAAC;KACE;IACV;QACE,IAAI;QACJ,CAAC,IAAI,CAAC;KACE;CACX,CAAC"}
@@ -1,2 +0,0 @@
1
- import "chai/register-should.js";
2
- //# sourceMappingURL=index.spec.d.ts.map