@code-pushup/core 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.
Files changed (2) hide show
  1. package/index.js +34 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -824,6 +824,14 @@ function sortAudits(a, b) {
824
824
  }
825
825
  return a.title.localeCompare(b.title);
826
826
  }
827
+ function compareIssueSeverity(severity1, severity2) {
828
+ const levels = {
829
+ info: 0,
830
+ warning: 1,
831
+ error: 2
832
+ };
833
+ return levels[severity1] - levels[severity2];
834
+ }
827
835
  async function loadReport(options) {
828
836
  const { outputDir, filename, format } = options;
829
837
  await ensureDirectoryExists(outputDir);
@@ -840,6 +848,30 @@ function throwIsNotPresentError(itemName, presentPlace) {
840
848
  function getPluginNameFromSlug(slug, plugins) {
841
849
  return plugins.find(({ slug: pluginSlug }) => pluginSlug === slug)?.title || slug;
842
850
  }
851
+ function compareIssues(a, b) {
852
+ if (a.severity !== b.severity) {
853
+ return -compareIssueSeverity(a.severity, b.severity);
854
+ }
855
+ if (!a.source && b.source) {
856
+ return -1;
857
+ }
858
+ if (a.source && !b.source) {
859
+ return 1;
860
+ }
861
+ if (a.source?.file !== b.source?.file) {
862
+ return a.source?.file.localeCompare(b.source?.file || "") || 0;
863
+ }
864
+ if (!a.source?.position && b.source?.position) {
865
+ return -1;
866
+ }
867
+ if (a.source?.position && !b.source?.position) {
868
+ return 1;
869
+ }
870
+ if (a.source?.position?.startLine !== b.source?.position?.startLine) {
871
+ return (a.source?.position?.startLine || 0) - (b.source?.position?.startLine || 0);
872
+ }
873
+ return 0;
874
+ }
843
875
 
844
876
  // packages/utils/src/lib/execute-process.ts
845
877
  var ProcessError = class extends Error {
@@ -1171,7 +1203,7 @@ function reportToAuditsSection(report) {
1171
1203
  }
1172
1204
  const detailsTableData = [
1173
1205
  detailsTableHeaders,
1174
- ...audit.details.issues.map((issue) => {
1206
+ ...audit.details.issues.sort(compareIssues).map((issue) => {
1175
1207
  const severity = `${getSeverityIcon(issue.severity)} <i>${issue.severity}</i>`;
1176
1208
  const message = issue.message;
1177
1209
  if (!issue.source) {
@@ -1601,7 +1633,7 @@ function auditOutputsCorrelateWithPluginOutput(auditOutputs, pluginConfigAudits)
1601
1633
 
1602
1634
  // packages/core/package.json
1603
1635
  var name = "@code-pushup/core";
1604
- var version = "0.3.2";
1636
+ var version = "0.4.1";
1605
1637
 
1606
1638
  // packages/core/src/lib/implementation/collect.ts
1607
1639
  async function collect(options) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-pushup/core",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "dependencies": {
5
5
  "@code-pushup/models": "*",
6
6
  "@code-pushup/utils": "*",