@code-pushup/eslint-plugin 0.46.0 → 0.47.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 +46 -20
  2. package/index.js +47 -21
  3. package/package.json +3 -3
package/bin.js CHANGED
@@ -67,7 +67,7 @@ function missingRefsForCategoriesErrorMsg(categories, plugins) {
67
67
  }
68
68
 
69
69
  // packages/models/src/lib/implementation/schemas.ts
70
- var primitiveValueSchema = z.union([z.string(), z.number()]);
70
+ var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
71
71
  function executionMetaSchema(options = {
72
72
  descriptionDate: "Execution start date and time",
73
73
  descriptionDuration: "Execution duration in ms"
@@ -231,10 +231,10 @@ var tableColumnObjectSchema = z4.object({
231
231
  label: z4.string().optional(),
232
232
  align: tableAlignmentSchema.optional()
233
233
  });
234
- var tableRowObjectSchema = z4.record(primitiveValueSchema, {
234
+ var tableRowObjectSchema = z4.record(tableCellValueSchema, {
235
235
  description: "Object row"
236
236
  });
237
- var tableRowPrimitiveSchema = z4.array(primitiveValueSchema, {
237
+ var tableRowPrimitiveSchema = z4.array(tableCellValueSchema, {
238
238
  description: "Primitive row"
239
239
  });
240
240
  var tableSharedSchema = z4.object({
@@ -725,12 +725,25 @@ function pluralize(text, amount) {
725
725
  function pluralizeToken(token, times) {
726
726
  return `${times} ${Math.abs(times) === 1 ? token : pluralize(token)}`;
727
727
  }
728
- function truncateText(text, maxChars) {
728
+ function truncateText(text, options) {
729
+ const {
730
+ maxChars,
731
+ position = "end",
732
+ ellipsis = "..."
733
+ } = typeof options === "number" ? { maxChars: options } : options;
729
734
  if (text.length <= maxChars) {
730
735
  return text;
731
736
  }
732
- const ellipsis = "...";
733
- return text.slice(0, maxChars - ellipsis.length) + ellipsis;
737
+ const maxLength = maxChars - ellipsis.length;
738
+ switch (position) {
739
+ case "start":
740
+ return ellipsis + text.slice(-maxLength).trim();
741
+ case "middle":
742
+ const halfMaxChars = Math.floor(maxLength / 2);
743
+ return text.slice(0, halfMaxChars).trim() + ellipsis + text.slice(-halfMaxChars).trim();
744
+ case "end":
745
+ return text.slice(0, maxLength).trim() + ellipsis;
746
+ }
734
747
  }
735
748
  function truncateIssueMessage(text) {
736
749
  return truncateText(text, MAX_ISSUE_MESSAGE_LENGTH);
@@ -824,7 +837,7 @@ function code(text) {
824
837
 
825
838
  // packages/utils/src/lib/text-formats/html/link.ts
826
839
  function link(href, text) {
827
- return `<a href="${href}">${text || href}"</a>`;
840
+ return `<a href="${href}">${text || href}</a>`;
828
841
  }
829
842
 
830
843
  // packages/utils/src/lib/transform.ts
@@ -849,7 +862,7 @@ function capitalize(text) {
849
862
  )}`;
850
863
  }
851
864
 
852
- // packages/utils/src/lib/table.ts
865
+ // packages/utils/src/lib/text-formats/table.ts
853
866
  function rowToStringArray({ rows, columns = [] }) {
854
867
  if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
855
868
  throw new TypeError(
@@ -862,14 +875,19 @@ function rowToStringArray({ rows, columns = [] }) {
862
875
  }
863
876
  const objectRow = row;
864
877
  if (columns.length === 0 || typeof columns.at(0) === "string") {
865
- return Object.values(objectRow).map(String);
878
+ return Object.values(objectRow).map(
879
+ (value) => value == null ? "" : String(value)
880
+ );
866
881
  }
867
882
  return columns.map(
868
- ({ key }) => String(objectRow[key])
883
+ ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
869
884
  );
870
885
  });
871
886
  }
872
- function columnsToStringArray({ rows, columns = [] }) {
887
+ function columnsToStringArray({
888
+ rows,
889
+ columns = []
890
+ }) {
873
891
  const firstRow = rows.at(0);
874
892
  const primitiveRows = Array.isArray(firstRow);
875
893
  if (typeof columns.at(0) === "string" && !primitiveRows) {
@@ -909,10 +927,8 @@ function getColumnAlignmentForIndex(targetIdx, columns = []) {
909
927
  return "center";
910
928
  }
911
929
  }
912
- function getColumnAlignments({
913
- rows,
914
- columns = []
915
- }) {
930
+ function getColumnAlignments(tableData) {
931
+ const { rows, columns = [] } = tableData;
916
932
  if (rows.at(0) == null) {
917
933
  throw new Error("first row can`t be undefined.");
918
934
  }
@@ -922,10 +938,17 @@ function getColumnAlignments({
922
938
  (_, idx) => getColumnAlignmentForIndex(idx, columns)
923
939
  );
924
940
  }
925
- const firstObject = rows.at(0);
926
- return Object.keys(firstObject).map(
927
- (key, idx) => getColumnAlignmentForKeyAndIndex(key, idx, columns)
928
- );
941
+ const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
942
+ if (columns.length > 0) {
943
+ return columns.map(
944
+ (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
945
+ column.key,
946
+ idx,
947
+ columns
948
+ )
949
+ );
950
+ }
951
+ return Object.keys(biggestRow ?? {}).map((_) => "center");
929
952
  }
930
953
 
931
954
  // packages/utils/src/lib/text-formats/html/table.ts
@@ -1022,7 +1045,10 @@ function section(...contents) {
1022
1045
  return `${lines(...contents)}${NEW_LINE}`;
1023
1046
  }
1024
1047
  function lines(...contents) {
1025
- return `${contents.filter(Boolean).join(NEW_LINE)}`;
1048
+ const filteredContent = contents.filter(
1049
+ (value) => value != null && value !== "" && value !== false
1050
+ );
1051
+ return `${filteredContent.join(NEW_LINE)}`;
1026
1052
  }
1027
1053
 
1028
1054
  // packages/utils/src/lib/text-formats/md/table.ts
package/index.js CHANGED
@@ -4,7 +4,7 @@ import { fileURLToPath } from "node:url";
4
4
 
5
5
  // packages/plugin-eslint/package.json
6
6
  var name = "@code-pushup/eslint-plugin";
7
- var version = "0.46.0";
7
+ var version = "0.47.0";
8
8
 
9
9
  // packages/plugin-eslint/src/lib/config.ts
10
10
  import { z as z16 } from "zod";
@@ -74,7 +74,7 @@ function missingRefsForCategoriesErrorMsg(categories, plugins) {
74
74
  }
75
75
 
76
76
  // packages/models/src/lib/implementation/schemas.ts
77
- var primitiveValueSchema = z.union([z.string(), z.number()]);
77
+ var tableCellValueSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]).default(null);
78
78
  function executionMetaSchema(options = {
79
79
  descriptionDate: "Execution start date and time",
80
80
  descriptionDuration: "Execution duration in ms"
@@ -238,10 +238,10 @@ var tableColumnObjectSchema = z4.object({
238
238
  label: z4.string().optional(),
239
239
  align: tableAlignmentSchema.optional()
240
240
  });
241
- var tableRowObjectSchema = z4.record(primitiveValueSchema, {
241
+ var tableRowObjectSchema = z4.record(tableCellValueSchema, {
242
242
  description: "Object row"
243
243
  });
244
- var tableRowPrimitiveSchema = z4.array(primitiveValueSchema, {
244
+ var tableRowPrimitiveSchema = z4.array(tableCellValueSchema, {
245
245
  description: "Primitive row"
246
246
  });
247
247
  var tableSharedSchema = z4.object({
@@ -714,12 +714,25 @@ import { join } from "node:path";
714
714
  function slugify(text) {
715
715
  return text.trim().toLowerCase().replace(/\s+|\//g, "-").replace(/[^a-z\d-]/g, "");
716
716
  }
717
- function truncateText(text, maxChars) {
717
+ function truncateText(text, options) {
718
+ const {
719
+ maxChars,
720
+ position = "end",
721
+ ellipsis = "..."
722
+ } = typeof options === "number" ? { maxChars: options } : options;
718
723
  if (text.length <= maxChars) {
719
724
  return text;
720
725
  }
721
- const ellipsis = "...";
722
- return text.slice(0, maxChars - ellipsis.length) + ellipsis;
726
+ const maxLength = maxChars - ellipsis.length;
727
+ switch (position) {
728
+ case "start":
729
+ return ellipsis + text.slice(-maxLength).trim();
730
+ case "middle":
731
+ const halfMaxChars = Math.floor(maxLength / 2);
732
+ return text.slice(0, halfMaxChars).trim() + ellipsis + text.slice(-halfMaxChars).trim();
733
+ case "end":
734
+ return text.slice(0, maxLength).trim() + ellipsis;
735
+ }
723
736
  }
724
737
  function truncateTitle(text) {
725
738
  return truncateText(text, MAX_TITLE_LENGTH);
@@ -816,7 +829,7 @@ function code(text) {
816
829
 
817
830
  // packages/utils/src/lib/text-formats/html/link.ts
818
831
  function link(href, text) {
819
- return `<a href="${href}">${text || href}"</a>`;
832
+ return `<a href="${href}">${text || href}</a>`;
820
833
  }
821
834
 
822
835
  // packages/utils/src/lib/transform.ts
@@ -835,7 +848,7 @@ function capitalize(text) {
835
848
  )}`;
836
849
  }
837
850
 
838
- // packages/utils/src/lib/table.ts
851
+ // packages/utils/src/lib/text-formats/table.ts
839
852
  function rowToStringArray({ rows, columns = [] }) {
840
853
  if (Array.isArray(rows.at(0)) && typeof columns.at(0) === "object") {
841
854
  throw new TypeError(
@@ -848,14 +861,19 @@ function rowToStringArray({ rows, columns = [] }) {
848
861
  }
849
862
  const objectRow = row;
850
863
  if (columns.length === 0 || typeof columns.at(0) === "string") {
851
- return Object.values(objectRow).map(String);
864
+ return Object.values(objectRow).map(
865
+ (value) => value == null ? "" : String(value)
866
+ );
852
867
  }
853
868
  return columns.map(
854
- ({ key }) => String(objectRow[key])
869
+ ({ key }) => objectRow[key] == null ? "" : String(objectRow[key])
855
870
  );
856
871
  });
857
872
  }
858
- function columnsToStringArray({ rows, columns = [] }) {
873
+ function columnsToStringArray({
874
+ rows,
875
+ columns = []
876
+ }) {
859
877
  const firstRow = rows.at(0);
860
878
  const primitiveRows = Array.isArray(firstRow);
861
879
  if (typeof columns.at(0) === "string" && !primitiveRows) {
@@ -895,10 +913,8 @@ function getColumnAlignmentForIndex(targetIdx, columns = []) {
895
913
  return "center";
896
914
  }
897
915
  }
898
- function getColumnAlignments({
899
- rows,
900
- columns = []
901
- }) {
916
+ function getColumnAlignments(tableData) {
917
+ const { rows, columns = [] } = tableData;
902
918
  if (rows.at(0) == null) {
903
919
  throw new Error("first row can`t be undefined.");
904
920
  }
@@ -908,10 +924,17 @@ function getColumnAlignments({
908
924
  (_, idx) => getColumnAlignmentForIndex(idx, columns)
909
925
  );
910
926
  }
911
- const firstObject = rows.at(0);
912
- return Object.keys(firstObject).map(
913
- (key, idx) => getColumnAlignmentForKeyAndIndex(key, idx, columns)
914
- );
927
+ const biggestRow = [...rows].sort((a, b) => Object.keys(a).length - Object.keys(b).length).at(-1);
928
+ if (columns.length > 0) {
929
+ return columns.map(
930
+ (column, idx) => typeof column === "string" ? column : getColumnAlignmentForKeyAndIndex(
931
+ column.key,
932
+ idx,
933
+ columns
934
+ )
935
+ );
936
+ }
937
+ return Object.keys(biggestRow ?? {}).map((_) => "center");
915
938
  }
916
939
 
917
940
  // packages/utils/src/lib/text-formats/html/table.ts
@@ -1008,7 +1031,10 @@ function section(...contents) {
1008
1031
  return `${lines(...contents)}${NEW_LINE}`;
1009
1032
  }
1010
1033
  function lines(...contents) {
1011
- return `${contents.filter(Boolean).join(NEW_LINE)}`;
1034
+ const filteredContent = contents.filter(
1035
+ (value) => value != null && value !== "" && value !== false
1036
+ );
1037
+ return `${filteredContent.join(NEW_LINE)}`;
1012
1038
  }
1013
1039
 
1014
1040
  // packages/utils/src/lib/text-formats/md/table.ts
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@code-pushup/eslint-plugin",
3
- "version": "0.46.0",
3
+ "version": "0.47.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
- "@code-pushup/utils": "0.46.0",
7
- "@code-pushup/models": "0.46.0",
6
+ "@code-pushup/utils": "0.47.0",
7
+ "@code-pushup/models": "0.47.0",
8
8
  "eslint": "^8.46.0",
9
9
  "zod": "^3.22.4"
10
10
  },