Skip to content

Commit

Permalink
feat: Enable links in VS Code terminal (#6)
Browse files Browse the repository at this point in the history
JIRA: CPOUI5FOUNDATION-820

We want to be able to click on the lint text and be able to open the
destination file and point to the exact `row:column` where the linter
found an issue.

---------

Co-authored-by: Matthias Osswald <[email protected]>
  • Loading branch information
d3xter666 and matz3 authored Mar 13, 2024
1 parent d56ec44 commit 1572f77
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 55 deletions.
33 changes: 14 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
71 changes: 35 additions & 36 deletions src/formatter/text.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -13,8 +14,8 @@ 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}`);
}
Expand All @@ -41,7 +42,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<string, LintMessage[]>();
Expand All @@ -65,45 +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(` ${ruleId} (${messages.length})`));
messages.forEach((msg) => {
const messageDetails = (showDetails && msg.messageDetails) ?
(`\n ${chalk.white.bold("Details:")}\n ` +
`${chalk.italic(msg.messageDetails.replaceAll("\n", "\n "))}`) :
"";

this.#writeln(
` ${formatLocation(msg.line, msg.column, lineInfoLength, columnInfoLength)} ` +
`${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) {
Expand Down

0 comments on commit 1572f77

Please sign in to comment.