Skip to content

Commit

Permalink
Display all files only with --verbose + defaut failure with info mode
Browse files Browse the repository at this point in the history
Fixes #243
--failon "info" by default
  • Loading branch information
nvuillam committed Oct 5, 2022
1 parent 6a166d0 commit 1378f4b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## UNRELEASED

## [11.0.0] 2022-10-06

- `--failon` is now `ìnfo` by default
- Display all files in console log only if `--verbose` is used

## [10.1.0] 2022-08-15

- Allow to send groovy sources as input from stdin
Expand Down
2 changes: 1 addition & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = optionator({
option: "failon",
type: "String",
enum: ["error", "warning", "info", "none"],
default: "none",
default: "info",
description:
"Defines the error level where CLI will fail (return code = 1). error,warning,info or none. Every failure level includes the more critical ones.",
example: ["error", "warning", "info", "none"]
Expand Down
11 changes: 8 additions & 3 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
// Errors
for (const fileNm of Object.keys(lintResult.files)) {
const fileErrors = lintResult.files[fileNm].errors;
outputString += c.underline(fileNm) + "\n";
let fileOutputString = c.underline(fileNm) + "\n";
let showFileInOutput = false ;
for (const err of fileErrors) {
if (!isErrorInLogLevelScope(err.severity, options.loglevel)) {
continue;
}
showFileInOutput = true ;
let color = "grey";
switch (err.severity) {
case "error":
Expand All @@ -135,7 +137,7 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
}
}
// Build error output line
outputString +=
fileOutputString +=
" " +
err.line.toString().padEnd(4, " ") +
" " +
Expand All @@ -146,7 +148,10 @@ async function processOutput(outputType, output, lintResult, options, fixer = nu
err.rule.padEnd(24, " ") +
"\n";
}
outputString += "\n";
fileOutputString += "\n";
if (showFileInOutput || options.verbose) {
outputString += fileOutputString ;
}
}
outputString += "\nnpm-groovy-lint results in " + c.bold(lintResult.summary.totalFilesLinted) + " linted files:";

Expand Down
18 changes: 16 additions & 2 deletions test/lint-build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("Lint with executable", () => {
'lib/example/' + SAMPLE_FILE_SMALL,
'lib/example/' + SAMPLE_FILE_BIG
];
let hasError = true ;
let hasError = true;
try {
await exec(NPM_GROOVY_LINT + params.join(" "));
hasError = false;
Expand All @@ -99,7 +99,7 @@ describe("Lint with executable", () => {
assert(sarif.runs[0].results.length > 0, "There should be results in SARIF");
assert(sarif.runs[0].artifacts.length == 2, "There should be 2 files in SARIF results");
}
assert(hasError === true,"There should have been an error with failon = info");
assert(hasError === true, "There should have been an error with failon = info");
});

it("(EXE:file) should lint a directory", async () => {
Expand Down Expand Up @@ -134,6 +134,20 @@ describe("Lint with executable", () => {
);
});

it("(EXE:file) should ignore fake_node_modules pattern with --noserver", async () => {
const params = ["--ignorepattern", "**/fake_node_modules/**", "--no-insight", "--output", "txt", "--noserver"];
const { stdout, stderr } = await exec("cd lib/example && " + NPM_GROOVY_LINT + params.join(" "));
if (stderr) {
console.error(stderr);
}
assert(stdout, "stdout is set");
assert(!stdout.includes(`ToIgnore.groovy`), `ToIgnore.groovy has been ignored \n${stdout}`);
assert(
stdout.includes(`npm-groovy-lint results in ${c.bold(11)} linted files`),
`Number of linted files is displayed in summary \n${stdout}`
);
});

it("(EXE:file) should generate codenarc HTML file report", async () => {
const reportFileName = path.resolve("ReportTestCodenarc.html");
const params = [
Expand Down

0 comments on commit 1378f4b

Please sign in to comment.