@code-pushup/utils 0.3.2 → 0.4.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/index.js CHANGED
@@ -905,6 +905,30 @@ function throwIsNotPresentError(itemName, presentPlace) {
905
905
  function getPluginNameFromSlug(slug, plugins) {
906
906
  return plugins.find(({ slug: pluginSlug }) => pluginSlug === slug)?.title || slug;
907
907
  }
908
+ function compareIssues(a, b) {
909
+ if (a.severity !== b.severity) {
910
+ return -compareIssueSeverity(a.severity, b.severity);
911
+ }
912
+ if (!a.source && b.source) {
913
+ return -1;
914
+ }
915
+ if (a.source && !b.source) {
916
+ return 1;
917
+ }
918
+ if (a.source?.file !== b.source?.file) {
919
+ return a.source?.file.localeCompare(b.source?.file || "") || 0;
920
+ }
921
+ if (!a.source?.position && b.source?.position) {
922
+ return -1;
923
+ }
924
+ if (a.source?.position && !b.source?.position) {
925
+ return 1;
926
+ }
927
+ if (a.source?.position?.startLine !== b.source?.position?.startLine) {
928
+ return (a.source?.position?.startLine || 0) - (b.source?.position?.startLine || 0);
929
+ }
930
+ return 0;
931
+ }
908
932
 
909
933
  // packages/utils/src/lib/execute-process.ts
910
934
  var ProcessError = class extends Error {
@@ -1236,7 +1260,7 @@ function reportToAuditsSection(report) {
1236
1260
  }
1237
1261
  const detailsTableData = [
1238
1262
  detailsTableHeaders,
1239
- ...audit.details.issues.map((issue) => {
1263
+ ...audit.details.issues.sort(compareIssues).map((issue) => {
1240
1264
  const severity = `${getSeverityIcon(issue.severity)} <i>${issue.severity}</i>`;
1241
1265
  const message = issue.message;
1242
1266
  if (!issue.source) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/utils",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "bundle-require": "^4.0.1",
@@ -1,4 +1,4 @@
1
- import { CategoryRef, IssueSeverity as CliIssueSeverity, Format, PersistConfig, Report } from '@code-pushup/models';
1
+ import { CategoryRef, IssueSeverity as CliIssueSeverity, Format, Issue, PersistConfig, Report } from '@code-pushup/models';
2
2
  import { EnrichedAuditReport, EnrichedScoredAuditGroupWithAudits, ScoredReport, WeighedAuditReport } from './scoring';
3
3
  export declare const FOOTER_PREFIX = "Made with \u2764 by";
4
4
  export declare const CODE_PUSHUP_DOMAIN = "code-pushup.dev";
@@ -27,4 +27,5 @@ export declare function loadReport<T extends Format>(options: Required<Pick<Pers
27
27
  }): Promise<LoadedReportFormat<T>>;
28
28
  export declare function throwIsNotPresentError(itemName: string, presentPlace: string): never;
29
29
  export declare function getPluginNameFromSlug(slug: string, plugins: ScoredReport['plugins']): string;
30
+ export declare function compareIssues(a: Issue, b: Issue): number;
30
31
  export {};