@code-pushup/eslint-plugin 0.4.5 → 0.5.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.
- package/bin.js +30 -24
- package/index.js +32 -26
- package/package.json +1 -1
package/bin.js
CHANGED
|
@@ -122,12 +122,14 @@ function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessa
|
|
|
122
122
|
return z.object(
|
|
123
123
|
{
|
|
124
124
|
slug: slugSchema('Human-readable unique ID, e.g. "performance"'),
|
|
125
|
-
refs: z.array(refSchema).refine(
|
|
125
|
+
refs: z.array(refSchema).min(1).refine(
|
|
126
126
|
(refs) => !duplicateCheckFn(refs),
|
|
127
127
|
(refs) => ({
|
|
128
128
|
message: duplicateMessageFn(refs)
|
|
129
129
|
})
|
|
130
|
-
)
|
|
130
|
+
).refine(hasWeightedRefsInCategories, () => ({
|
|
131
|
+
message: `In a category there has to be at least one ref with weight > 0`
|
|
132
|
+
}))
|
|
131
133
|
},
|
|
132
134
|
{ description }
|
|
133
135
|
);
|
|
@@ -136,6 +138,9 @@ var materialIconSchema = z.enum(
|
|
|
136
138
|
MATERIAL_ICONS,
|
|
137
139
|
{ description: "Icon from VSCode Material Icons extension" }
|
|
138
140
|
);
|
|
141
|
+
function hasWeightedRefsInCategories(categoryRefs) {
|
|
142
|
+
return categoryRefs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
143
|
+
}
|
|
139
144
|
|
|
140
145
|
// packages/models/src/lib/category-config.ts
|
|
141
146
|
var categoryRefSchema = weightedRefSchema(
|
|
@@ -181,6 +186,23 @@ function getDuplicateRefsInCategoryMetrics(metrics) {
|
|
|
181
186
|
metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
|
|
182
187
|
);
|
|
183
188
|
}
|
|
189
|
+
var categoriesSchema = z2.array(categoryConfigSchema, {
|
|
190
|
+
description: "Categorization of individual audits"
|
|
191
|
+
}).min(1).refine(
|
|
192
|
+
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
193
|
+
(categoryCfg) => ({
|
|
194
|
+
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
195
|
+
})
|
|
196
|
+
);
|
|
197
|
+
function duplicateSlugCategoriesErrorMsg(categories) {
|
|
198
|
+
const duplicateStringSlugs = getDuplicateSlugCategories(categories);
|
|
199
|
+
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
200
|
+
duplicateStringSlugs
|
|
201
|
+
)}`;
|
|
202
|
+
}
|
|
203
|
+
function getDuplicateSlugCategories(categories) {
|
|
204
|
+
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
205
|
+
}
|
|
184
206
|
|
|
185
207
|
// packages/models/src/lib/core-config.ts
|
|
186
208
|
import { z as z11 } from "zod";
|
|
@@ -189,10 +211,10 @@ import { z as z11 } from "zod";
|
|
|
189
211
|
import { z as z3 } from "zod";
|
|
190
212
|
var formatSchema = z3.enum(["json", "md"]);
|
|
191
213
|
var persistConfigSchema = z3.object({
|
|
192
|
-
outputDir: filePathSchema("Artifacts folder"),
|
|
193
|
-
filename: fileNameSchema(
|
|
194
|
-
"
|
|
195
|
-
),
|
|
214
|
+
outputDir: filePathSchema("Artifacts folder").optional(),
|
|
215
|
+
filename: fileNameSchema(
|
|
216
|
+
"Artifacts file name (without extension)"
|
|
217
|
+
).optional(),
|
|
196
218
|
format: z3.array(formatSchema).default(["json"]).optional()
|
|
197
219
|
// @TODO remove default or optional value and otherwise it will not set defaults.
|
|
198
220
|
});
|
|
@@ -428,17 +450,10 @@ var unrefinedCoreConfigSchema = z11.object({
|
|
|
428
450
|
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
429
451
|
}),
|
|
430
452
|
/** portal configuration for persisting results */
|
|
431
|
-
persist: persistConfigSchema,
|
|
453
|
+
persist: persistConfigSchema.optional(),
|
|
432
454
|
/** portal configuration for uploading results */
|
|
433
455
|
upload: uploadConfigSchema.optional(),
|
|
434
|
-
categories:
|
|
435
|
-
description: "Categorization of individual audits"
|
|
436
|
-
}).refine(
|
|
437
|
-
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
438
|
-
(categoryCfg) => ({
|
|
439
|
-
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
440
|
-
})
|
|
441
|
-
)
|
|
456
|
+
categories: categoriesSchema
|
|
442
457
|
});
|
|
443
458
|
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
444
459
|
function refineCoreConfig(schema) {
|
|
@@ -489,15 +504,6 @@ function getMissingRefsForCategories(coreCfg) {
|
|
|
489
504
|
}
|
|
490
505
|
return missingRefs.length ? missingRefs : false;
|
|
491
506
|
}
|
|
492
|
-
function duplicateSlugCategoriesErrorMsg(categories) {
|
|
493
|
-
const duplicateStringSlugs = getDuplicateSlugCategories(categories);
|
|
494
|
-
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
495
|
-
duplicateStringSlugs
|
|
496
|
-
)}`;
|
|
497
|
-
}
|
|
498
|
-
function getDuplicateSlugCategories(categories) {
|
|
499
|
-
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
500
|
-
}
|
|
501
507
|
|
|
502
508
|
// packages/models/src/lib/report.ts
|
|
503
509
|
import { z as z12 } from "zod";
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "url";
|
|
|
5
5
|
|
|
6
6
|
// packages/plugin-eslint/package.json
|
|
7
7
|
var name = "@code-pushup/eslint-plugin";
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.5.1";
|
|
9
9
|
|
|
10
10
|
// packages/plugin-eslint/src/lib/config.ts
|
|
11
11
|
import { z } from "zod";
|
|
@@ -144,12 +144,14 @@ function scorableSchema(description, refSchema, duplicateCheckFn, duplicateMessa
|
|
|
144
144
|
return z2.object(
|
|
145
145
|
{
|
|
146
146
|
slug: slugSchema('Human-readable unique ID, e.g. "performance"'),
|
|
147
|
-
refs: z2.array(refSchema).refine(
|
|
147
|
+
refs: z2.array(refSchema).min(1).refine(
|
|
148
148
|
(refs) => !duplicateCheckFn(refs),
|
|
149
149
|
(refs) => ({
|
|
150
150
|
message: duplicateMessageFn(refs)
|
|
151
151
|
})
|
|
152
|
-
)
|
|
152
|
+
).refine(hasWeightedRefsInCategories, () => ({
|
|
153
|
+
message: `In a category there has to be at least one ref with weight > 0`
|
|
154
|
+
}))
|
|
153
155
|
},
|
|
154
156
|
{ description }
|
|
155
157
|
);
|
|
@@ -158,6 +160,9 @@ var materialIconSchema = z2.enum(
|
|
|
158
160
|
MATERIAL_ICONS,
|
|
159
161
|
{ description: "Icon from VSCode Material Icons extension" }
|
|
160
162
|
);
|
|
163
|
+
function hasWeightedRefsInCategories(categoryRefs) {
|
|
164
|
+
return categoryRefs.reduce((acc, { weight }) => weight + acc, 0) !== 0;
|
|
165
|
+
}
|
|
161
166
|
|
|
162
167
|
// packages/models/src/lib/category-config.ts
|
|
163
168
|
var categoryRefSchema = weightedRefSchema(
|
|
@@ -203,6 +208,23 @@ function getDuplicateRefsInCategoryMetrics(metrics) {
|
|
|
203
208
|
metrics.map(({ slug, type, plugin }) => `${type} :: ${plugin} / ${slug}`)
|
|
204
209
|
);
|
|
205
210
|
}
|
|
211
|
+
var categoriesSchema = z3.array(categoryConfigSchema, {
|
|
212
|
+
description: "Categorization of individual audits"
|
|
213
|
+
}).min(1).refine(
|
|
214
|
+
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
215
|
+
(categoryCfg) => ({
|
|
216
|
+
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
217
|
+
})
|
|
218
|
+
);
|
|
219
|
+
function duplicateSlugCategoriesErrorMsg(categories) {
|
|
220
|
+
const duplicateStringSlugs = getDuplicateSlugCategories(categories);
|
|
221
|
+
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
222
|
+
duplicateStringSlugs
|
|
223
|
+
)}`;
|
|
224
|
+
}
|
|
225
|
+
function getDuplicateSlugCategories(categories) {
|
|
226
|
+
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
227
|
+
}
|
|
206
228
|
|
|
207
229
|
// packages/models/src/lib/core-config.ts
|
|
208
230
|
import { z as z12 } from "zod";
|
|
@@ -211,10 +233,10 @@ import { z as z12 } from "zod";
|
|
|
211
233
|
import { z as z4 } from "zod";
|
|
212
234
|
var formatSchema = z4.enum(["json", "md"]);
|
|
213
235
|
var persistConfigSchema = z4.object({
|
|
214
|
-
outputDir: filePathSchema("Artifacts folder"),
|
|
215
|
-
filename: fileNameSchema(
|
|
216
|
-
"
|
|
217
|
-
),
|
|
236
|
+
outputDir: filePathSchema("Artifacts folder").optional(),
|
|
237
|
+
filename: fileNameSchema(
|
|
238
|
+
"Artifacts file name (without extension)"
|
|
239
|
+
).optional(),
|
|
218
240
|
format: z4.array(formatSchema).default(["json"]).optional()
|
|
219
241
|
// @TODO remove default or optional value and otherwise it will not set defaults.
|
|
220
242
|
});
|
|
@@ -450,17 +472,10 @@ var unrefinedCoreConfigSchema = z12.object({
|
|
|
450
472
|
description: "List of plugins to be used (official, community-provided, or custom)"
|
|
451
473
|
}),
|
|
452
474
|
/** portal configuration for persisting results */
|
|
453
|
-
persist: persistConfigSchema,
|
|
475
|
+
persist: persistConfigSchema.optional(),
|
|
454
476
|
/** portal configuration for uploading results */
|
|
455
477
|
upload: uploadConfigSchema.optional(),
|
|
456
|
-
categories:
|
|
457
|
-
description: "Categorization of individual audits"
|
|
458
|
-
}).refine(
|
|
459
|
-
(categoryCfg) => !getDuplicateSlugCategories(categoryCfg),
|
|
460
|
-
(categoryCfg) => ({
|
|
461
|
-
message: duplicateSlugCategoriesErrorMsg(categoryCfg)
|
|
462
|
-
})
|
|
463
|
-
)
|
|
478
|
+
categories: categoriesSchema
|
|
464
479
|
});
|
|
465
480
|
var coreConfigSchema = refineCoreConfig(unrefinedCoreConfigSchema);
|
|
466
481
|
function refineCoreConfig(schema) {
|
|
@@ -511,15 +526,6 @@ function getMissingRefsForCategories(coreCfg) {
|
|
|
511
526
|
}
|
|
512
527
|
return missingRefs.length ? missingRefs : false;
|
|
513
528
|
}
|
|
514
|
-
function duplicateSlugCategoriesErrorMsg(categories) {
|
|
515
|
-
const duplicateStringSlugs = getDuplicateSlugCategories(categories);
|
|
516
|
-
return `In the categories, the following slugs are duplicated: ${errorItems(
|
|
517
|
-
duplicateStringSlugs
|
|
518
|
-
)}`;
|
|
519
|
-
}
|
|
520
|
-
function getDuplicateSlugCategories(categories) {
|
|
521
|
-
return hasDuplicateStrings(categories.map(({ slug }) => slug));
|
|
522
|
-
}
|
|
523
529
|
|
|
524
530
|
// packages/models/src/lib/report.ts
|
|
525
531
|
import { z as z13 } from "zod";
|
|
@@ -760,7 +766,7 @@ function groupsFromRuleTypes(rules) {
|
|
|
760
766
|
refs: auditSlugsMap[type]?.map(
|
|
761
767
|
(slug) => ({ slug, weight: 1 })
|
|
762
768
|
) ?? []
|
|
763
|
-
}));
|
|
769
|
+
})).filter((group) => group.refs.length);
|
|
764
770
|
}
|
|
765
771
|
function groupsFromRuleCategories(rules) {
|
|
766
772
|
const categoriesMap = rules.reduce(
|