From c14c5d0ff9023f8a234949acad9b44691889a7bb Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 8 Mar 2024 12:25:13 +0200 Subject: [PATCH 1/6] feat: Enable VS Code links --- src/formatter/text.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/formatter/text.ts b/src/formatter/text.ts index 7cdaf7746..fd86f87ea 100644 --- a/src/formatter/text.ts +++ b/src/formatter/text.ts @@ -1,4 +1,5 @@ import chalk from "chalk"; +import path from "node:path"; import {LintMessageSeverity, LintResult, LintMessage} from "../detectors/AbstractDetector.js"; function formatSeverity(severity: LintMessageSeverity) { @@ -41,7 +42,8 @@ export class Text { totalWarningCount += warningCount; totalFatalErrorCount += fatalErrorCount; - this.#writeln(chalk.inverse(filePath)); + // this.#writeln(chalk.inverse(filePath)); + this.#writeln(chalk.inverse(path.resolve(process.cwd(), filePath))); // Group messages by rule const rules = new Map(); @@ -72,7 +74,7 @@ export class Text { }).forEach((ruleId) => { const messages = rules.get(ruleId); if (messages) { - this.#writeln(chalk.bold(` ${ruleId} (${messages.length})`)); + this.#writeln(chalk.bold(` ${chalk.dim("0:0")} ${ruleId} (${messages.length})`)); messages.forEach((msg) => { const messageDetails = (showDetails && msg.messageDetails) ? (`\n ${chalk.white.bold("Details:")}\n ` + From 7955deb8e3a9984acd33743554154929ecd929dd Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 8 Mar 2024 15:23:20 +0200 Subject: [PATCH 2/6] fix: Include messageDetails in VS Code links --- src/formatter/text.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/formatter/text.ts b/src/formatter/text.ts index fd86f87ea..5ce9d9748 100644 --- a/src/formatter/text.ts +++ b/src/formatter/text.ts @@ -42,7 +42,6 @@ export class Text { totalWarningCount += warningCount; totalFatalErrorCount += fatalErrorCount; - // this.#writeln(chalk.inverse(filePath)); this.#writeln(chalk.inverse(path.resolve(process.cwd(), filePath))); // Group messages by rule @@ -76,13 +75,16 @@ export class Text { if (messages) { this.#writeln(chalk.bold(` ${chalk.dim("0:0")} ${ruleId} (${messages.length})`)); messages.forEach((msg) => { - const messageDetails = (showDetails && msg.messageDetails) ? - (`\n ${chalk.white.bold("Details:")}\n ` + - `${chalk.italic(msg.messageDetails.replaceAll("\n", "\n "))}`) : + const formattedLocation = + formatLocation(msg.line, msg.column, lineInfoLength, columnInfoLength); + + const messageDetails = (showDetails && msg.messageDetails) ? + (`\n ${formattedLocation} ${chalk.white.bold("Details:")} ` + + `${chalk.italic(msg.messageDetails.replaceAll("\n", `\n ${formattedLocation} `))}`) : ""; this.#writeln( - ` ${formatLocation(msg.line, msg.column, lineInfoLength, columnInfoLength)} ` + + ` ${formattedLocation} ` + `${formatSeverity(msg.severity)} ` + `${msg.message}` + `${messageDetails}`); From bc3237b1f3fe769793351f03070e73f723f059ab Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Mon, 11 Mar 2024 17:21:39 +0100 Subject: [PATCH 3/6] fix: Remove grouping, line breaks, use relative path --- src/formatter/text.ts | 75 ++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/src/formatter/text.ts b/src/formatter/text.ts index 5ce9d9748..4890773c3 100644 --- a/src/formatter/text.ts +++ b/src/formatter/text.ts @@ -1,5 +1,4 @@ import chalk from "chalk"; -import path from "node:path"; import {LintMessageSeverity, LintResult, LintMessage} from "../detectors/AbstractDetector.js"; function formatSeverity(severity: LintMessageSeverity) { @@ -14,8 +13,9 @@ function formatSeverity(severity: LintMessageSeverity) { function formatLocation(line: LintMessage["line"], column: LintMessage["column"], lineInfoLength: number, columnInfoLength: number) { - const lineStr = (line === undefined ? "?" : line.toString()).padStart(lineInfoLength, " "); - const columnStr = (column === undefined ? "?" : column.toString()).padEnd(columnInfoLength, " "); + + const lineStr = (line === undefined ? "0" : line.toString()).padStart(lineInfoLength, " "); + const columnStr = (column === undefined ? "0" : column.toString()).padEnd(columnInfoLength, " "); return chalk.dim(`${lineStr}:${columnStr}`); } @@ -42,7 +42,7 @@ export class Text { totalWarningCount += warningCount; totalFatalErrorCount += fatalErrorCount; - this.#writeln(chalk.inverse(path.resolve(process.cwd(), filePath))); + this.#writeln(chalk.inverse(filePath)); // Group messages by rule const rules = new Map(); @@ -66,48 +66,43 @@ export class Text { const lineInfoLength = maxLine.toString().length; const columnInfoLength = maxColumn.toString().length; - let addNewLineAfterModule = true; - // Sort rules alphabetically - Array.from(rules.keys()).sort((a, b) => { - return a.localeCompare(b); - }).forEach((ruleId) => { - const messages = rules.get(ruleId); - if (messages) { - this.#writeln(chalk.bold(` ${chalk.dim("0:0")} ${ruleId} (${messages.length})`)); - messages.forEach((msg) => { - const formattedLocation = - formatLocation(msg.line, msg.column, lineInfoLength, columnInfoLength); - - const messageDetails = (showDetails && msg.messageDetails) ? - (`\n ${formattedLocation} ${chalk.white.bold("Details:")} ` + - `${chalk.italic(msg.messageDetails.replaceAll("\n", `\n ${formattedLocation} `))}`) : - ""; - - this.#writeln( - ` ${formattedLocation} ` + - `${formatSeverity(msg.severity)} ` + - `${msg.message}` + - `${messageDetails}`); - - addNewLineAfterModule = true; - if (messageDetails) { - this.#writeln(""); - addNewLineAfterModule = false; - } - }); - } + // Sort by line, then by column. Use 0 if not set. + messages.sort((a, b) => (a.line ?? 0) - (b.line ?? 0) || (a.column ?? 0) - (b.column ?? 0)); + + messages.forEach((msg) => { + const formattedLocation = + formatLocation(msg.line, msg.column, lineInfoLength, columnInfoLength); + + const messageDetails = (showDetails && msg.messageDetails) ? + (`\n ${formattedLocation} ${chalk.white.bold("Details:")} ` + + `${chalk.italic(msg.messageDetails.replaceAll("\n", " "))}`) : + ""; + + this.#writeln( + ` ${formattedLocation} ` + + `${formatSeverity(msg.severity)} ` + + `${msg.message}` + + `${messageDetails}`); }); - if (addNewLineAfterModule) { - this.#writeln(""); - } + this.#writeln(""); }); + let summaryColor = chalk.green; + if (totalErrorCount > 0) { + summaryColor = chalk.red; + } else if (totalWarningCount > 0) { + summaryColor = chalk.yellow; + } + this.#writeln( - `${totalErrorCount + totalWarningCount} problems ` + - `(${totalErrorCount} errors, ${totalWarningCount} warnings)`); + summaryColor( + `${totalErrorCount + totalWarningCount} problems ` + + `(${totalErrorCount} errors, ${totalWarningCount} warnings)` + ) + ); if (totalFatalErrorCount) { - this.#writeln(`${totalFatalErrorCount} fatal errors`); + this.#writeln(summaryColor(`${totalFatalErrorCount} fatal errors`)); } if (!showDetails && (totalErrorCount + totalWarningCount + totalFatalErrorCount) > 0) { From 200a307dbfba978d0dfbc265de63efd9350956bd Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Wed, 13 Mar 2024 11:55:43 +0200 Subject: [PATCH 4/6] fix: Log issues with absolute path --- src/formatter/text.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/formatter/text.ts b/src/formatter/text.ts index 4890773c3..9795ecb34 100644 --- a/src/formatter/text.ts +++ b/src/formatter/text.ts @@ -1,4 +1,5 @@ import chalk from "chalk"; +import path from "node:path"; import {LintMessageSeverity, LintResult, LintMessage} from "../detectors/AbstractDetector.js"; function formatSeverity(severity: LintMessageSeverity) { @@ -42,7 +43,7 @@ export class Text { totalWarningCount += warningCount; totalFatalErrorCount += fatalErrorCount; - this.#writeln(chalk.inverse(filePath)); + this.#writeln(chalk.inverse(path.resolve(process.cwd(), filePath))); // Group messages by rule const rules = new Map(); From 3c67b932c07d426a8d359c0ff4c61cacc35fc6ef Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Wed, 13 Mar 2024 12:14:42 +0200 Subject: [PATCH 5/6] fix: Resolve merge conflicts --- src/formatter/text.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/formatter/text.ts b/src/formatter/text.ts index 9795ecb34..511065673 100644 --- a/src/formatter/text.ts +++ b/src/formatter/text.ts @@ -14,7 +14,6 @@ function formatSeverity(severity: LintMessageSeverity) { function formatLocation(line: LintMessage["line"], column: LintMessage["column"], lineInfoLength: number, columnInfoLength: number) { - const lineStr = (line === undefined ? "0" : line.toString()).padStart(lineInfoLength, " "); const columnStr = (column === undefined ? "0" : column.toString()).padEnd(columnInfoLength, " "); @@ -68,15 +67,15 @@ export class Text { const columnInfoLength = maxColumn.toString().length; // Sort by line, then by column. Use 0 if not set. - messages.sort((a, b) => (a.line ?? 0) - (b.line ?? 0) || (a.column ?? 0) - (b.column ?? 0)); + messages.sort((a, b) => (a.line ?? 0) - (b.line ?? 0) || (a.column ?? 0) - (b.column ?? 0)); messages.forEach((msg) => { const formattedLocation = formatLocation(msg.line, msg.column, lineInfoLength, columnInfoLength); const messageDetails = (showDetails && msg.messageDetails) ? - (`\n ${formattedLocation} ${chalk.white.bold("Details:")} ` + - `${chalk.italic(msg.messageDetails.replaceAll("\n", " "))}`) : + (`\n ${formattedLocation} ${chalk.white.bold("Details:")} ` + + `${chalk.italic(msg.messageDetails.replaceAll("\n", " "))}`) : ""; this.#writeln( From e2a582148b7a655fd1a3ba6423468cbd5eaf428c Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Wed, 13 Mar 2024 11:15:15 +0100 Subject: [PATCH 6/6] docs: Update ui5lint example output --- README.md | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index da0883178..6da983e1d 100644 --- a/README.md +++ b/README.md @@ -46,25 +46,20 @@ ui5lint ## UI5Lint Report ## -webapp/controller/App.controller.js - ui5-linter-no-deprecated-api (1) - 10:4 error Call to deprecated function 'attachTap' of class 'Button' - -webapp/manifest.json - ui5-linter-no-deprecated-api (1) - 81:17 error Use of deprecated model type 'sap.ui5/models/odata/type="sap.ui.model.odata.ODataModel"' - -webapp/test/unit/unitTests.qunit.js - ui5-linter-no-deprecated-api (2) - 6:1 error Call to deprecated function 'attachInit' of class 'Core' - 6:1 error Call to deprecated function 'getCore' (sap.ui.getCore) - ui5-linter-no-globals-js (1) - 6:1 error Access of global variable 'sap' (sap.ui.getCore) - -webapp/view/Main.view.xml - ui5-linter-no-deprecated-api (2) - 16:39 error Import of deprecated module 'sap/m/MessagePage' - 22:5 error Use of deprecated property 'blocked' of class 'Button' +/application/webapp/controller/App.controller.js + 10:4 error Call to deprecated function 'attachTap' of class 'Button' + +/application/webapp/manifest.json + 81:17 error Use of deprecated model type 'sap.ui5/models/odata/type="sap.ui.model.odata.ODataModel"' + +/application/webapp/test/unit/unitTests.qunit.js + 6:1 error Call to deprecated function 'attachInit' of class 'Core' + 6:1 error Call to deprecated function 'getCore' (sap.ui.getCore) + 6:1 error Access of global variable 'sap' (sap.ui.getCore) + +/application/webapp/view/Main.view.xml + 16:39 error Import of deprecated module 'sap/m/MessagePage' + 22:5 error Use of deprecated property 'blocked' of class 'Button' 7 problems (7 errors, 0 warnings)