-
Notifications
You must be signed in to change notification settings - Fork 885
Stylish Formatter: output all file names #1557
Conversation
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.
@@ -26,15 +26,24 @@ export class Formatter extends AbstractFormatter { | |||
return "\n"; | |||
} | |||
|
|||
const fileName = failures[0].getFileName(); | |||
const outputLines: Array<string> = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please format the type def as string[]
const fileName = failure.getFileName(); | ||
if (currentFile !== fileName) { | ||
if (currentFile) { | ||
outputLines.push(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this just happen once, at the beginning of the lint output? if so, I think this can be refactored out of the loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It happens every time a new file is reached.
The idea is that whenever we start a new file, we add an empty line before it to separate the output from the previous list of lint errors.
I'll refactor it out of the loop by adding the first file-name before it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adidahiya Actually, if I move the first file out of the loop, I still need to add a test for whether we're at the first iteration or not, so it won't really make it cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably should've commented on L40 -- why would currentFile
be undefined multiple times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't be. It would be only for the first file, which is the case I'm trying to catch here, to avoid adding an empty line.
It's either that, or adding the line even at the first time, and then unshifting it out of the outputLines before returning it. Although then there is a need to checked whether the array is not empty and etc.
Currently the stylish formatter prints only 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.