Skip to content

Commit 936e329

Browse files
committed
fix: review changes
1 parent c492e2d commit 936e329

File tree

5 files changed

+40
-45
lines changed

5 files changed

+40
-45
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
- [`--details`](#--details)
2222
- [`--format`](#--format)
2323
- [`--fix`](#--fix)
24-
- [Dry Run Mode](#dry-run-mode)
2524
- [`--quiet`](#--quiet)
2625
- [`--ignore-pattern`](#--ignore-pattern)
2726
- [`--config`](#--config)

src/cli/base.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {isLogLevelEnabled} from "@ui5/logger";
1010
import ConsoleWriter from "@ui5/logger/writers/Console";
1111
import {getVersion} from "./version.js";
1212
import {ui5lint} from "../index.js";
13-
import type {LintResult} from "../linter/LinterContext.js";
1413
import {LintMessageSeverity} from "../linter/messages.js";
1514

1615
export interface LinterArg {
@@ -180,39 +179,37 @@ async function handleLint(argv: ArgumentsCamelCase<LinterArg>) {
180179
ui5Config,
181180
});
182181

183-
// Define a simple function to filter a single result set
184-
const applyQuietFilter = (results: LintResult[]): LintResult[] => {
185-
if (!quiet) {
186-
return results;
182+
// Apply quiet mode filtering directly to the results if needed
183+
if (quiet) {
184+
// Filter out warnings from all result objects
185+
for (const result of res) {
186+
// Keep only error messages (severity === 2)
187+
result.messages = result.messages.filter((msg) => msg.severity === LintMessageSeverity.Error);
188+
// Reset warning counts
189+
result.warningCount = 0;
190+
// Reset fixableWarningCount if it exists
191+
if ("fixableWarningCount" in result) {
192+
result.fixableWarningCount = 0;
193+
}
187194
}
188-
return results.map((file) => ({
189-
...file,
190-
messages: file.messages.filter((msg) => msg.severity === LintMessageSeverity.Error),
191-
warningCount: 0,
192-
fixableWarningCount: 0,
193-
}));
194-
};
195+
}
195196

196197
if (coverage) {
197198
const coverageFormatter = new Coverage();
198-
const filteredResults = applyQuietFilter(res);
199-
await writeFile("ui5lint-report.html", await coverageFormatter.format(filteredResults, new Date()));
199+
await writeFile("ui5lint-report.html", await coverageFormatter.format(res, new Date()));
200200
}
201201

202202
if (format === "json") {
203203
const jsonFormatter = new Json();
204-
const filteredResults = applyQuietFilter(res);
205-
process.stdout.write(jsonFormatter.format(filteredResults, details, quiet));
204+
process.stdout.write(jsonFormatter.format(res, details, quiet));
206205
process.stdout.write("\n");
207206
} else if (format === "markdown") {
208207
const markdownFormatter = new Markdown();
209-
const filteredResults = applyQuietFilter(res);
210-
process.stdout.write(markdownFormatter.format(filteredResults, details, getVersion(), fix, quiet));
208+
process.stdout.write(markdownFormatter.format(res, details, getVersion(), fix, quiet));
211209
process.stdout.write("\n");
212210
} else if (format === "" || format === "stylish") {
213211
const textFormatter = new Text(rootDir);
214-
const filteredResults = applyQuietFilter(res);
215-
process.stderr.write(textFormatter.format(filteredResults, details, fix, quiet));
212+
process.stderr.write(textFormatter.format(res, details, fix, quiet));
216213
}
217214
// Stop profiling after CLI finished execution
218215
if (profile) {

src/formatter/json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Json {
2828
filePath: oLintedFile.filePath,
2929
messages: aFileMessages,
3030
errorCount: oLintedFile.errorCount,
31-
warningCount: quiet ? 0 : oLintedFile.warningCount,
31+
warningCount: oLintedFile.warningCount,
3232
fatalErrorCount: oLintedFile.fatalErrorCount,
3333
});
3434
}

src/formatter/markdown.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,17 @@ export class Markdown {
6565
});
6666

6767
let summary = "## Summary\n\n";
68-
if (quiet) {
69-
summary +=
70-
`> ${totalErrorCount} ${totalErrorCount === 1 ? "problem" : "problems"} ` +
71-
`(${totalErrorCount} ${totalErrorCount === 1 ? "error" : "errors"}) \n`;
72-
} else {
73-
summary +=
74-
`> ${totalErrorCount + totalWarningCount} problems ` +
75-
`(${totalErrorCount} errors, ${totalWarningCount} warnings) \n`;
68+
const errorsText = `${totalErrorCount} ${totalErrorCount === 1 ? "error" : "errors"}`;
69+
let warningsText = "";
70+
if (!quiet) {
71+
warningsText = `, ${totalWarningCount} ${totalWarningCount === 1 ? "warning" : "warnings"}`;
7672
}
73+
74+
const totalCount = quiet ? totalErrorCount : totalErrorCount + totalWarningCount;
75+
const problemsText = `${totalCount} ${totalCount === 1 ? "problem" : "problems"}`;
76+
77+
summary += `> ${problemsText} (${errorsText}${warningsText}) \n`;
78+
7779
if (totalFatalErrorCount) {
7880
summary += `> **${totalFatalErrorCount} fatal errors**\n`;
7981
}

src/formatter/text.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,19 @@ export class Text {
101101
summaryColor = chalk.yellow;
102102
}
103103

104-
// In quiet mode, only mention errors in the summary
105-
if (quiet) {
106-
this.#writeln(
107-
summaryColor(
108-
`${totalErrorCount} ${totalErrorCount === 1 ? "problem" : "problems"} ` +
109-
`(${totalErrorCount} ${totalErrorCount === 1 ? "error" : "errors"})`
110-
)
111-
);
112-
} else {
113-
this.#writeln(
114-
summaryColor(
115-
`${totalErrorCount + totalWarningCount} problems ` +
116-
`(${totalErrorCount} errors, ${totalWarningCount} warnings)`
117-
)
118-
);
104+
const errorsText = `${totalErrorCount} ${totalErrorCount === 1 ? "error" : "errors"}`;
105+
let warningsText = "";
106+
if (!quiet) {
107+
warningsText = `, ${totalWarningCount} ${totalWarningCount === 1 ? "warning" : "warnings"}`;
119108
}
109+
110+
const totalCount = quiet ? totalErrorCount : totalErrorCount + totalWarningCount;
111+
const problemsText = `${totalCount} ${totalCount === 1 ? "problem" : "problems"}`;
112+
113+
this.#writeln(
114+
summaryColor(`${problemsText} (${errorsText}${warningsText})`)
115+
);
116+
120117
if (!autofix && (totalErrorCount + totalWarningCount > 0)) {
121118
this.#writeln(" Run \"ui5lint --fix\" to resolve all auto-fixable problems\n");
122119
}

0 commit comments

Comments
 (0)