Skip to content

Commit

Permalink
Stylish Formatter: output all file names (palantir#1557)
Browse files Browse the repository at this point in the history
Currently the stylish formatter *only* prints the first fileName, and
then a list of lint errors from all files without specifying to which
file they belong.
After this fix, each time a new file is reached, a new line will be
added, and then the name of the file, so each group of lint failures
will be group with their fileName.
  • Loading branch information
nomaed authored and adidahiya committed Sep 19, 2016
1 parent 7dd127b commit 6cb1f11
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/formatters/stylishFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,22 @@ export class Formatter extends AbstractFormatter {
return "\n";
}

const fileName = failures[0].getFileName();
const positionMaxSize = this.getPositionMaxSize(failures);
const ruleMaxSize = this.getRuleMaxSize(failures);
const outputLines: string[] = [];
const positionMaxSize = this.getPositionMaxSize(failures);
const ruleMaxSize = this.getRuleMaxSize(failures);

const outputLines = [
fileName,
];
let currentFile: string;

for (const failure of failures) {
const fileName = failure.getFileName();

// Output the name of each file once
if (currentFile !== fileName) {
outputLines.push("");
outputLines.push(fileName);
currentFile = fileName;
}

const failureString = failure.getFailure();

// Rule
Expand All @@ -55,6 +62,11 @@ export class Formatter extends AbstractFormatter {
outputLines.push(output);
}

// Removes initial blank line
if (outputLines[0] === "") {
outputLines.shift();
}

return outputLines.join("\n") + "\n\n";
}

Expand Down

0 comments on commit 6cb1f11

Please sign in to comment.