From 504780295372067d3c26664bc0991e1a7df37d79 Mon Sep 17 00:00:00 2001 From: tiulpin Date: Wed, 17 Jan 2024 22:25:14 +0100 Subject: [PATCH] :bug: Fix output issues (QD-6541, QD-7986) --- .github/workflows/node.yml | 2 + scan/__tests__/data/some.sarif.json | 59 +++++++++++++++++++++++++++++ scan/__tests__/main.test.ts | 14 ++++++- scan/dist/index.js | 11 +++--- scan/src/annotations.ts | 9 ++--- scan/src/output.ts | 2 +- 6 files changed, 84 insertions(+), 13 deletions(-) diff --git a/.github/workflows/node.yml b/.github/workflows/node.yml index bde0d731..02a2a320 100644 --- a/.github/workflows/node.yml +++ b/.github/workflows/node.yml @@ -31,6 +31,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} - name: Set Node.js 16.x uses: actions/setup-node@v4.0.1 with: diff --git a/scan/__tests__/data/some.sarif.json b/scan/__tests__/data/some.sarif.json index 24b744c5..38233785 100644 --- a/scan/__tests__/data/some.sarif.json +++ b/scan/__tests__/data/some.sarif.json @@ -7977,6 +7977,39 @@ } ] }, + { + "id": "RiderSolutionErrorsInspection", + "shortDescription": { + "text": "Rider toolset and environment errors" + }, + "fullDescription": { + "text": "Reports toolset and environment errors detected by Rider.", + "markdown": "Reports toolset and environment errors detected by Rider." + }, + "defaultConfiguration": { + "enabled": true, + "level": "error", + "parameters": { + "suppressToolId": "RiderSolutionErrorsInspection", + "ideaSeverity": "ERROR", + "qodanaSeverity": "Critical" + } + }, + "relationships": [ + { + "target": { + "id": "Rider/General", + "index": 134, + "toolComponent": { + "name": "QDNET" + } + }, + "kinds": [ + "superset" + ] + } + ] + }, { "id": "EqualsOrHashCode", "shortDescription": { @@ -8136,6 +8169,32 @@ ] } }, + { + "ruleId": "RiderSolutionErrorsInspection", + "kind": "fail", + "level": "warning", + "message": { + "text": "[NU1101] Unable to find package PrivatePackage. No packages exist with this id in source(s): github at (0:0) Target: ResolvePackageAssets Task: ResolvePackageAssets", + "markdown": "\\[[NU1101](http://www.google.com/search?q=NU1101)\\] Unable to find package PrivatePackage. No packages exist with this id in source(s): github at (0:0) \n\nTarget: ResolvePackageAssets \nTask: ResolvePackageAssets" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "LibraryReferencingPackage/LibraryReferencingPackage.csproj", + "uriBaseId": "SRCROOT" + } + } + } + ], + "partialFingerprints": { + "equalIndicator/v1": "2eb5998cec5651ad1ad36262cf210caa653ab138d3c22e4338d3eea704104bf6" + }, + "properties": { + "ideaSeverity": "WARNING", + "qodanaSeverity": "High" + } + }, { "ruleId": "MayBeConstant", "kind": "fail", diff --git a/scan/__tests__/main.test.ts b/scan/__tests__/main.test.ts index 00f21a53..66b6a720 100644 --- a/scan/__tests__/main.test.ts +++ b/scan/__tests__/main.test.ts @@ -178,6 +178,17 @@ export function annotationsDefaultFixture(): Annotation[] { start_column: undefined, end_column: undefined }, + { + annotation_level: 'warning', + message: + '\\[[NU1101](http://www.google.com/search?q=NU1101)\\] Unable to find package PrivatePackage. No packages exist with this id in source(s): github at (0:0) \n\nTarget: ResolvePackageAssets \nTask: ResolvePackageAssets', + end_line: 1, + start_line: 0, + path: 'LibraryReferencingPackage/LibraryReferencingPackage.csproj', + title: 'Rider toolset and environment errors', + start_column: undefined, + end_column: undefined + }, { annotation_level: 'notice', message: "Might be 'const'", @@ -239,11 +250,12 @@ export function defaultDockerRunCommandFixture(): string[] { export function markdownSummaryFixture(): string { return `# [Qodana](https://example.com/report) for JS -**3 new problems** were found +**4 new problems** were found | Inspection name | Severity | Problems | | --- | --- | --- | | \`Control flow with empty body\` | 🔴 Failure | 1 | +| \`Rider toolset and environment errors\` | 🔶 Warning | 1 | | \`Condition of 'if' expression is constant\` | 🔶 Warning | 1 | | \`Might be 'const'\` | ◽️ Notice | 1 | diff --git a/scan/dist/index.js b/scan/dist/index.js index fdfd6519..99b309a1 100644 --- a/scan/dist/index.js +++ b/scan/dist/index.js @@ -126751,8 +126751,8 @@ ${body} __name(getViewReportText, "getViewReportText"); function getRowsByLevel(annotations, level) { const problems = annotations.reduce((map, e) => { - var _a, _b; - return map.set((_a = e.title) !== null && _a !== void 0 ? _a : UNKNOWN_RULE_ID, map.get((_b = e.title) !== null && _b !== void 0 ? _b : UNKNOWN_RULE_ID) !== void 0 ? map.get(e.title) + 1 : 1); + var _a, _b, _c; + return map.set((_a = e.title) !== null && _a !== void 0 ? _a : UNKNOWN_RULE_ID, map.get((_b = e.title) !== null && _b !== void 0 ? _b : UNKNOWN_RULE_ID) !== void 0 ? map.get((_c = e.title) !== null && _c !== void 0 ? _c : UNKNOWN_RULE_ID) + 1 : 1); }, /* @__PURE__ */ new Map()); return Array.from(problems.entries()).sort((a, b) => b[1] - a[1]).map(([title, count]) => `| \`${title}\` | ${level} | ${count} |`).join("\n"); } @@ -126920,7 +126920,6 @@ var require_annotations = __commonJS({ return; } try { - problems.summary = problems.summary.replace(`# Qodana`, ""); if (problems.annotations.length >= MAX_ANNOTATIONS) { for (let i = 0; i < problems.annotations.length; i += MAX_ANNOTATIONS) { yield (0, utils_12.publishGitHubCheck)(failedByThreshold, name, { @@ -126965,7 +126964,7 @@ var require_annotations = __commonJS({ message: (_a = result.message.markdown) !== null && _a !== void 0 ? _a : result.message.text, title: (_b = rules.get(result.ruleId)) === null || _b === void 0 ? void 0 : _b.shortDescription, path: location.artifactLocation.uri, - start_line: (region === null || region === void 0 ? void 0 : region.startLine) || 1, + start_line: (region === null || region === void 0 ? void 0 : region.startLine) || 0, end_line: (region === null || region === void 0 ? void 0 : region.endLine) || (region === null || region === void 0 ? void 0 : region.startLine) || 1, start_column: (region === null || region === void 0 ? void 0 : region.startLine) === (region === null || region === void 0 ? void 0 : region.endColumn) ? region === null || region === void 0 ? void 0 : region.startColumn : void 0, end_column: (region === null || region === void 0 ? void 0 : region.startLine) === (region === null || region === void 0 ? void 0 : region.endColumn) ? region === null || region === void 0 ? void 0 : region.endColumn : void 0, @@ -127041,8 +127040,8 @@ var require_annotations = __commonJS({ return { title: a.title, file: a.path, - startLine: a.start_line, - endLine: a.end_line, + startLine: a.start_line || 0, + endLine: a.end_line || 1, startColumn: a.start_column, endColumn: a.end_column }; diff --git a/scan/src/annotations.ts b/scan/src/annotations.ts index a01aa288..6135843e 100644 --- a/scan/src/annotations.ts +++ b/scan/src/annotations.ts @@ -45,7 +45,6 @@ export async function publishAnnotations( return } try { - problems.summary = problems.summary.replace(`# Qodana`, '') if (problems.annotations.length >= MAX_ANNOTATIONS) { for (let i = 0; i < problems.annotations.length; i += MAX_ANNOTATIONS) { await publishGitHubCheck(failedByThreshold, name, { @@ -92,7 +91,7 @@ export interface Rule { } export interface Annotation { - title: string + title: string | undefined path: string start_line: number end_line: number @@ -125,7 +124,7 @@ function parseResult( message: result.message.markdown ?? result.message.text!!, title: rules.get(result.ruleId!!)?.shortDescription!!, path: location.artifactLocation!!.uri!!, - start_line: region?.startLine || 1, + start_line: region?.startLine || 0, end_line: region?.endLine || region?.startLine || 1, start_column: region?.startLine === region?.endColumn ? region?.startColumn : undefined, @@ -233,8 +232,8 @@ export function toAnnotationProperties(a: Annotation): AnnotationProperties { return { title: a.title, file: a.path, - startLine: a.start_line, - endLine: a.end_line, + startLine: a.start_line || 0, + endLine: a.end_line || 1, startColumn: a.start_column, endColumn: a.end_column } diff --git a/scan/src/output.ts b/scan/src/output.ts index 5a05c5f9..b879a82d 100644 --- a/scan/src/output.ts +++ b/scan/src/output.ts @@ -206,7 +206,7 @@ function getRowsByLevel(annotations: Annotation[], level: string): string { map.set( e.title ?? UNKNOWN_RULE_ID, map.get(e.title ?? UNKNOWN_RULE_ID) !== undefined - ? map.get(e.title)!! + 1 + ? map.get(e.title ?? UNKNOWN_RULE_ID)!! + 1 : 1 ), new Map()