@code-pushup/eslint-plugin 0.26.1 → 0.28.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.
Files changed (3) hide show
  1. package/bin.js +148 -23
  2. package/index.js +135 -15
  3. package/package.json +1 -1
package/bin.js CHANGED
@@ -88,6 +88,9 @@ var descriptionSchema = z.string({ description: "Description (markdown)" }).max(
88
88
  var urlSchema = z.string().url();
89
89
  var docsUrlSchema = urlSchema.optional().or(z.literal("")).describe("Documentation site");
90
90
  var titleSchema = z.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
91
+ var scoreSchema = z.number({
92
+ description: "Value between 0 and 1"
93
+ }).min(0).max(1);
91
94
  function metaSchema(options) {
92
95
  const {
93
96
  descriptionDescription,
@@ -219,6 +222,8 @@ var issueSchema = z3.object(
219
222
  );
220
223
 
221
224
  // packages/models/src/lib/audit-output.ts
225
+ var auditValueSchema = nonnegativeIntSchema.describe("Raw numeric value");
226
+ var auditDisplayValueSchema = z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
222
227
  var auditDetailsSchema = z4.object(
223
228
  {
224
229
  issues: z4.array(issueSchema, { description: "List of findings" })
@@ -228,11 +233,9 @@ var auditDetailsSchema = z4.object(
228
233
  var auditOutputSchema = z4.object(
229
234
  {
230
235
  slug: slugSchema.describe("Reference to audit"),
231
- displayValue: z4.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(),
232
- value: nonnegativeIntSchema.describe("Raw numeric value"),
233
- score: z4.number({
234
- description: "Value between 0 and 1"
235
- }).min(0).max(1),
236
+ displayValue: auditDisplayValueSchema,
237
+ value: auditValueSchema,
238
+ score: scoreSchema,
236
239
  details: auditDetailsSchema.optional()
237
240
  },
238
241
  { description: "Audit information" }
@@ -555,9 +558,99 @@ var reportSchema = packageVersionSchema({
555
558
  })
556
559
  );
557
560
 
561
+ // packages/models/src/lib/reports-diff.ts
562
+ import { z as z14 } from "zod";
563
+ function makeComparisonSchema(schema) {
564
+ const sharedDescription = schema.description || "Result";
565
+ return z14.object({
566
+ before: schema.describe(`${sharedDescription} (source commit)`),
567
+ after: schema.describe(`${sharedDescription} (target commit)`)
568
+ });
569
+ }
570
+ function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
571
+ return z14.object(
572
+ {
573
+ changed: z14.array(diffSchema),
574
+ unchanged: z14.array(resultSchema),
575
+ added: z14.array(resultSchema),
576
+ removed: z14.array(resultSchema)
577
+ },
578
+ { description }
579
+ );
580
+ }
581
+ var scorableMetaSchema = z14.object({ slug: slugSchema, title: titleSchema });
582
+ var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
583
+ z14.object({
584
+ plugin: pluginMetaSchema.pick({ slug: true, title: true }).describe("Plugin which defines it")
585
+ })
586
+ );
587
+ var scorableDiffSchema = scorableMetaSchema.merge(
588
+ z14.object({
589
+ scores: makeComparisonSchema(scoreSchema).merge(
590
+ z14.object({
591
+ diff: z14.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
592
+ })
593
+ ).describe("Score comparison")
594
+ })
595
+ );
596
+ var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
597
+ scorableWithPluginMetaSchema
598
+ );
599
+ var categoryDiffSchema = scorableDiffSchema;
600
+ var groupDiffSchema = scorableWithPluginDiffSchema;
601
+ var auditDiffSchema = scorableWithPluginDiffSchema.merge(
602
+ z14.object({
603
+ values: makeComparisonSchema(auditValueSchema).merge(
604
+ z14.object({
605
+ diff: z14.number().int().describe("Value change (`values.after - values.before`)")
606
+ })
607
+ ).describe("Audit `value` comparison"),
608
+ displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
609
+ "Audit `displayValue` comparison"
610
+ )
611
+ })
612
+ );
613
+ var categoryResultSchema = scorableMetaSchema.merge(
614
+ z14.object({ score: scoreSchema })
615
+ );
616
+ var groupResultSchema = scorableWithPluginMetaSchema.merge(
617
+ z14.object({ score: scoreSchema })
618
+ );
619
+ var auditResultSchema = scorableWithPluginMetaSchema.merge(
620
+ auditOutputSchema.pick({ score: true, value: true, displayValue: true })
621
+ );
622
+ var reportsDiffSchema = z14.object({
623
+ commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
624
+ categories: makeArraysComparisonSchema(
625
+ categoryDiffSchema,
626
+ categoryResultSchema,
627
+ "Changes affecting categories"
628
+ ),
629
+ groups: makeArraysComparisonSchema(
630
+ groupDiffSchema,
631
+ groupResultSchema,
632
+ "Changes affecting groups"
633
+ ),
634
+ audits: makeArraysComparisonSchema(
635
+ auditDiffSchema,
636
+ auditResultSchema,
637
+ "Changes affecting audits"
638
+ )
639
+ }).merge(
640
+ packageVersionSchema({
641
+ versionDescription: "NPM version of the CLI (when `compare` was run)",
642
+ required: true
643
+ })
644
+ ).merge(
645
+ executionMetaSchema({
646
+ descriptionDate: "Start date and time of the compare run",
647
+ descriptionDuration: "Duration of the compare run in ms"
648
+ })
649
+ );
650
+
558
651
  // packages/utils/src/lib/file-system.ts
559
652
  import { bundleRequire } from "bundle-require";
560
- import chalk from "chalk";
653
+ import chalk2 from "chalk";
561
654
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
562
655
  import { join } from "node:path";
563
656
 
@@ -565,7 +658,10 @@ import { join } from "node:path";
565
658
  function slugify(text) {
566
659
  return text.trim().toLowerCase().replace(/\s+|\//g, "-").replace(/[^a-z\d-]/g, "");
567
660
  }
568
- function pluralize(text) {
661
+ function pluralize(text, amount) {
662
+ if (amount != null && Math.abs(amount) === 1) {
663
+ return text;
664
+ }
569
665
  if (text.endsWith("y")) {
570
666
  return `${text.slice(0, -1)}ies`;
571
667
  }
@@ -574,7 +670,7 @@ function pluralize(text) {
574
670
  }
575
671
  return `${text}s`;
576
672
  }
577
- function pluralizeToken(token, times = 0) {
673
+ function pluralizeToken(token, times) {
578
674
  return `${times} ${Math.abs(times) === 1 ? token : pluralize(token)}`;
579
675
  }
580
676
  function truncateText(text, maxChars) {
@@ -588,6 +684,38 @@ function truncateIssueMessage(text) {
588
684
  return truncateText(text, MAX_ISSUE_MESSAGE_LENGTH);
589
685
  }
590
686
 
687
+ // packages/utils/src/lib/logging.ts
688
+ import isaacs_cliui from "@isaacs/cliui";
689
+ import { cliui } from "@poppinss/cliui";
690
+ import chalk from "chalk";
691
+
692
+ // packages/utils/src/lib/reports/constants.ts
693
+ var TERMINAL_WIDTH = 80;
694
+
695
+ // packages/utils/src/lib/logging.ts
696
+ var singletonUiInstance;
697
+ function ui() {
698
+ if (singletonUiInstance === void 0) {
699
+ singletonUiInstance = cliui();
700
+ }
701
+ return {
702
+ ...singletonUiInstance,
703
+ row: (args) => {
704
+ logListItem(args);
705
+ }
706
+ };
707
+ }
708
+ var singletonisaacUi;
709
+ function logListItem(args) {
710
+ if (singletonisaacUi === void 0) {
711
+ singletonisaacUi = isaacs_cliui({ width: TERMINAL_WIDTH });
712
+ }
713
+ singletonisaacUi.div(...args);
714
+ const content = singletonisaacUi.toString();
715
+ singletonisaacUi.rows = [];
716
+ singletonUiInstance?.logger.log(content);
717
+ }
718
+
591
719
  // packages/utils/src/lib/file-system.ts
592
720
  async function readTextFile(path) {
593
721
  const buffer = await readFile(path);
@@ -602,7 +730,7 @@ async function ensureDirectoryExists(baseDir) {
602
730
  await mkdir(baseDir, { recursive: true });
603
731
  return;
604
732
  } catch (error) {
605
- console.error(error.message);
733
+ ui().logger.error(error.message);
606
734
  if (error.code !== "EEXIST") {
607
735
  throw error;
608
736
  }
@@ -642,17 +770,12 @@ function distinct(array) {
642
770
  return [...new Set(array)];
643
771
  }
644
772
 
645
- // packages/utils/src/lib/logging.ts
646
- import chalk2 from "chalk";
647
-
648
773
  // packages/utils/src/lib/progress.ts
649
774
  import chalk3 from "chalk";
650
775
  import { MultiProgressBars } from "multi-progress-bars";
651
776
 
652
- // packages/utils/src/lib/reports/generate-stdout-summary.ts
653
- import cliui from "@isaacs/cliui";
777
+ // packages/utils/src/lib/reports/log-stdout-summary.ts
654
778
  import chalk4 from "chalk";
655
- import CliTable3 from "cli-table3";
656
779
 
657
780
  // packages/plugin-eslint/src/lib/setup.ts
658
781
  import { ESLint } from "eslint";
@@ -722,7 +845,7 @@ function lintResultsToAudits({
722
845
  ).reduce((acc, issue) => {
723
846
  const { ruleId, message, filePath } = issue;
724
847
  if (!ruleId) {
725
- console.warn(`ESLint core error - ${message}`);
848
+ ui().logger.warning(`ESLint core error - ${message}`);
726
849
  return acc;
727
850
  }
728
851
  const options = ruleOptionsPerFile[filePath]?.[ruleId] ?? [];
@@ -754,13 +877,15 @@ function convertIssue(issue) {
754
877
  severity: convertSeverity(issue.severity),
755
878
  source: {
756
879
  file: issue.filePath,
757
- position: {
758
- startLine: issue.line,
759
- ...issue.column > 0 && { startColumn: issue.column },
760
- ...issue.endLine && issue.endLine > 0 && {
761
- endLine: issue.endLine
762
- },
763
- ...issue.endColumn && issue.endColumn > 0 && { endColumn: issue.endColumn }
880
+ ...issue.line > 0 && {
881
+ position: {
882
+ startLine: issue.line,
883
+ ...issue.column > 0 && { startColumn: issue.column },
884
+ ...issue.endLine && issue.endLine > 0 && {
885
+ endLine: issue.endLine
886
+ },
887
+ ...issue.endColumn && issue.endColumn > 0 && { endColumn: issue.endColumn }
888
+ }
764
889
  }
765
890
  }
766
891
  };
package/index.js CHANGED
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
5
5
 
6
6
  // packages/plugin-eslint/package.json
7
7
  var name = "@code-pushup/eslint-plugin";
8
- var version = "0.26.1";
8
+ var version = "0.28.0";
9
9
 
10
10
  // packages/plugin-eslint/src/lib/config.ts
11
11
  import { z } from "zod";
@@ -110,6 +110,9 @@ var descriptionSchema = z2.string({ description: "Description (markdown)" }).max
110
110
  var urlSchema = z2.string().url();
111
111
  var docsUrlSchema = urlSchema.optional().or(z2.literal("")).describe("Documentation site");
112
112
  var titleSchema = z2.string({ description: "Descriptive name" }).max(MAX_TITLE_LENGTH);
113
+ var scoreSchema = z2.number({
114
+ description: "Value between 0 and 1"
115
+ }).min(0).max(1);
113
116
  function metaSchema(options) {
114
117
  const {
115
118
  descriptionDescription,
@@ -241,6 +244,8 @@ var issueSchema = z4.object(
241
244
  );
242
245
 
243
246
  // packages/models/src/lib/audit-output.ts
247
+ var auditValueSchema = nonnegativeIntSchema.describe("Raw numeric value");
248
+ var auditDisplayValueSchema = z5.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional();
244
249
  var auditDetailsSchema = z5.object(
245
250
  {
246
251
  issues: z5.array(issueSchema, { description: "List of findings" })
@@ -250,11 +255,9 @@ var auditDetailsSchema = z5.object(
250
255
  var auditOutputSchema = z5.object(
251
256
  {
252
257
  slug: slugSchema.describe("Reference to audit"),
253
- displayValue: z5.string({ description: "Formatted value (e.g. '0.9 s', '2.1 MB')" }).optional(),
254
- value: nonnegativeIntSchema.describe("Raw numeric value"),
255
- score: z5.number({
256
- description: "Value between 0 and 1"
257
- }).min(0).max(1),
258
+ displayValue: auditDisplayValueSchema,
259
+ value: auditValueSchema,
260
+ score: scoreSchema,
258
261
  details: auditDetailsSchema.optional()
259
262
  },
260
263
  { description: "Audit information" }
@@ -577,9 +580,99 @@ var reportSchema = packageVersionSchema({
577
580
  })
578
581
  );
579
582
 
583
+ // packages/models/src/lib/reports-diff.ts
584
+ import { z as z15 } from "zod";
585
+ function makeComparisonSchema(schema) {
586
+ const sharedDescription = schema.description || "Result";
587
+ return z15.object({
588
+ before: schema.describe(`${sharedDescription} (source commit)`),
589
+ after: schema.describe(`${sharedDescription} (target commit)`)
590
+ });
591
+ }
592
+ function makeArraysComparisonSchema(diffSchema, resultSchema, description) {
593
+ return z15.object(
594
+ {
595
+ changed: z15.array(diffSchema),
596
+ unchanged: z15.array(resultSchema),
597
+ added: z15.array(resultSchema),
598
+ removed: z15.array(resultSchema)
599
+ },
600
+ { description }
601
+ );
602
+ }
603
+ var scorableMetaSchema = z15.object({ slug: slugSchema, title: titleSchema });
604
+ var scorableWithPluginMetaSchema = scorableMetaSchema.merge(
605
+ z15.object({
606
+ plugin: pluginMetaSchema.pick({ slug: true, title: true }).describe("Plugin which defines it")
607
+ })
608
+ );
609
+ var scorableDiffSchema = scorableMetaSchema.merge(
610
+ z15.object({
611
+ scores: makeComparisonSchema(scoreSchema).merge(
612
+ z15.object({
613
+ diff: z15.number().min(-1).max(1).describe("Score change (`scores.after - scores.before`)")
614
+ })
615
+ ).describe("Score comparison")
616
+ })
617
+ );
618
+ var scorableWithPluginDiffSchema = scorableDiffSchema.merge(
619
+ scorableWithPluginMetaSchema
620
+ );
621
+ var categoryDiffSchema = scorableDiffSchema;
622
+ var groupDiffSchema = scorableWithPluginDiffSchema;
623
+ var auditDiffSchema = scorableWithPluginDiffSchema.merge(
624
+ z15.object({
625
+ values: makeComparisonSchema(auditValueSchema).merge(
626
+ z15.object({
627
+ diff: z15.number().int().describe("Value change (`values.after - values.before`)")
628
+ })
629
+ ).describe("Audit `value` comparison"),
630
+ displayValues: makeComparisonSchema(auditDisplayValueSchema).describe(
631
+ "Audit `displayValue` comparison"
632
+ )
633
+ })
634
+ );
635
+ var categoryResultSchema = scorableMetaSchema.merge(
636
+ z15.object({ score: scoreSchema })
637
+ );
638
+ var groupResultSchema = scorableWithPluginMetaSchema.merge(
639
+ z15.object({ score: scoreSchema })
640
+ );
641
+ var auditResultSchema = scorableWithPluginMetaSchema.merge(
642
+ auditOutputSchema.pick({ score: true, value: true, displayValue: true })
643
+ );
644
+ var reportsDiffSchema = z15.object({
645
+ commits: makeComparisonSchema(commitSchema).nullable().describe("Commits identifying compared reports"),
646
+ categories: makeArraysComparisonSchema(
647
+ categoryDiffSchema,
648
+ categoryResultSchema,
649
+ "Changes affecting categories"
650
+ ),
651
+ groups: makeArraysComparisonSchema(
652
+ groupDiffSchema,
653
+ groupResultSchema,
654
+ "Changes affecting groups"
655
+ ),
656
+ audits: makeArraysComparisonSchema(
657
+ auditDiffSchema,
658
+ auditResultSchema,
659
+ "Changes affecting audits"
660
+ )
661
+ }).merge(
662
+ packageVersionSchema({
663
+ versionDescription: "NPM version of the CLI (when `compare` was run)",
664
+ required: true
665
+ })
666
+ ).merge(
667
+ executionMetaSchema({
668
+ descriptionDate: "Start date and time of the compare run",
669
+ descriptionDuration: "Duration of the compare run in ms"
670
+ })
671
+ );
672
+
580
673
  // packages/utils/src/lib/file-system.ts
581
674
  import { bundleRequire } from "bundle-require";
582
- import chalk from "chalk";
675
+ import chalk2 from "chalk";
583
676
  import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
584
677
  import { join } from "node:path";
585
678
 
@@ -601,6 +694,38 @@ function truncateDescription(text) {
601
694
  return truncateText(text, MAX_DESCRIPTION_LENGTH);
602
695
  }
603
696
 
697
+ // packages/utils/src/lib/logging.ts
698
+ import isaacs_cliui from "@isaacs/cliui";
699
+ import { cliui } from "@poppinss/cliui";
700
+ import chalk from "chalk";
701
+
702
+ // packages/utils/src/lib/reports/constants.ts
703
+ var TERMINAL_WIDTH = 80;
704
+
705
+ // packages/utils/src/lib/logging.ts
706
+ var singletonUiInstance;
707
+ function ui() {
708
+ if (singletonUiInstance === void 0) {
709
+ singletonUiInstance = cliui();
710
+ }
711
+ return {
712
+ ...singletonUiInstance,
713
+ row: (args) => {
714
+ logListItem(args);
715
+ }
716
+ };
717
+ }
718
+ var singletonisaacUi;
719
+ function logListItem(args) {
720
+ if (singletonisaacUi === void 0) {
721
+ singletonisaacUi = isaacs_cliui({ width: TERMINAL_WIDTH });
722
+ }
723
+ singletonisaacUi.div(...args);
724
+ const content = singletonisaacUi.toString();
725
+ singletonisaacUi.rows = [];
726
+ singletonUiInstance?.logger.log(content);
727
+ }
728
+
604
729
  // packages/utils/src/lib/file-system.ts
605
730
  async function fileExists(path) {
606
731
  try {
@@ -615,7 +740,7 @@ async function ensureDirectoryExists(baseDir) {
615
740
  await mkdir(baseDir, { recursive: true });
616
741
  return;
617
742
  } catch (error) {
618
- console.error(error.message);
743
+ ui().logger.error(error.message);
619
744
  if (error.code !== "EEXIST") {
620
745
  throw error;
621
746
  }
@@ -639,17 +764,12 @@ function distinct(array) {
639
764
  return [...new Set(array)];
640
765
  }
641
766
 
642
- // packages/utils/src/lib/logging.ts
643
- import chalk2 from "chalk";
644
-
645
767
  // packages/utils/src/lib/progress.ts
646
768
  import chalk3 from "chalk";
647
769
  import { MultiProgressBars } from "multi-progress-bars";
648
770
 
649
- // packages/utils/src/lib/reports/generate-stdout-summary.ts
650
- import cliui from "@isaacs/cliui";
771
+ // packages/utils/src/lib/reports/log-stdout-summary.ts
651
772
  import chalk4 from "chalk";
652
- import CliTable3 from "cli-table3";
653
773
 
654
774
  // packages/plugin-eslint/src/lib/meta/hash.ts
655
775
  import { createHash } from "node:crypto";
@@ -687,7 +807,7 @@ async function listRules(eslint, patterns) {
687
807
  (acc, [ruleId, ruleEntry]) => {
688
808
  const meta = rulesMeta[ruleId];
689
809
  if (!meta) {
690
- console.warn(`Metadata not found for ESLint rule ${ruleId}`);
810
+ ui().logger.warning(`Metadata not found for ESLint rule ${ruleId}`);
691
811
  return acc;
692
812
  }
693
813
  const options = toArray(ruleEntry).slice(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/eslint-plugin",
3
- "version": "0.26.1",
3
+ "version": "0.28.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "@code-pushup/utils": "*",