Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Add new formatter: fileslist #1558

Merged
merged 5 commits into from
Sep 20, 2016
Merged

Add new formatter: fileslist #1558

merged 5 commits into from
Sep 20, 2016

Conversation

nomaed
Copy link
Contributor

@nomaed nomaed commented Sep 18, 2016

This formatter does not output any lint error details. Instead, it lists all of the files that had lint errors.
This is useful for creating lists of files that need to be taken care
of, or for bulk-opening all of the files in an editor from CLI.

Example:

Prose

$ tslint --project tsconfig.json
/Users/dude/crc-calc/src/lib/crcData.ts[139, 4]: file should end with a newline
/Users/dude/crc-calc/src/lib/crcData.ts[1, 14]: variable name must be in camelcase or uppercase
/Users/dude/crc-calc/src/lib/crc.ts[31, 5]: comment must start with a space
/Users/dude/crc-calc/src/lib/crc.ts[35, 2]: file should end with a newline
/Users/dude/crc-calc/src/lib/crc.ts[17, 7]: Forbidden bitwise operation
/Users/dude/crc-calc/src/lib/crc.ts[20, 14]: Forbidden bitwise operation
/Users/dude/crc-calc/src/lib/crc.ts[20, 31]: Forbidden bitwise operation
/Users/dude/crc-calc/src/lib/crc.ts[12, 3]: Multiple variable declarations in the same statement are forbidden
src/crc-calc.ts[14, 1]: Consecutive blank lines are forbidden
src/crc-calc.ts[2, 1]: <reference> is not allowed, use imports

Files-list

$ tslint --project tsconfig.json -t fileslist
/Users/dude/crc-calc/src/lib/crcData.ts
/Users/dude/crc-calc/src/lib/crc.ts
src/crc-calc.ts

Usage examples:

Opening all files that require fixing in an editor:

$ atom $(tslint --project tsconfig.json -t fileslist)
  (or)
$ vi $(tslint --project tsconfig.json -t fileslist)

When using Perforce RCS, checking out all files for edit:

$ tslint --project tsconfig.json -t fileslist | xargs p4 edit

This formatter does not output any lint errors. Instead, it lists all
of the files that had lint errors.
This is useful for creating lists of files that need to be taken care
of, or for bulk-opening all of the files in an editor from CLI.

Todo: test
Copy link
Contributor

@adidahiya adidahiya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, I like the idea overall.

minor name change suggestion: "files list" instead of "file list"


export class Formatter extends AbstractFormatter {
public format(failures: RuleFailure[]): string {
const files: Array<string> = [];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: please format the typedef as string[]

public format(failures: RuleFailure[]): string {
const files: Array<string> = [];

failures.forEach((failure: RuleFailure) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use a for-of loop instead of forEach, or refactor this logic into a reduce

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nomaed
Copy link
Contributor Author

nomaed commented Sep 19, 2016

Looks like VSCode decided to format-on-save tsconfig.json files to 2-space indents.
Will fix it in a moment, trying to figure out which plugin is responsible for it.

@nomaed nomaed changed the title Add formatter: filelist Add new formatter: fileslist Sep 19, 2016
@adidahiya
Copy link
Contributor

@nomaed small merge conflict to address, otherwise looks good

…matter

# Conflicts:
#	src/formatters/stylishFormatter.ts
@nomaed
Copy link
Contributor Author

nomaed commented Sep 19, 2016

@adidahiya Merge resolved

@adidahiya adidahiya merged commit 5cc19bd into palantir:master Sep 20, 2016
@adidahiya adidahiya added this to the TSLint v4.0 milestone Sep 20, 2016
@nomaed nomaed deleted the add-file-list-formatter branch September 20, 2016 17:39
}
}

return files.join("\n") + "\n";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about always printing this trailing newline. See #1553 for discussion about this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkillian I am thinking that you're talking about cases when files is empty?
Because there is a need of a newline at the end of the output, if there is an output (of course, this is not an empty line).

adidahiya pushed a commit that referenced this pull request Sep 21, 2016
Addresses review #875140 in PR #1558 for compatibility with discussion item #1553
alexeagle pushed a commit to alexeagle/tslint that referenced this pull request Sep 21, 2016
This formatter does not output any lint errors. Instead, it lists all
of the files that had lint errors.
This is useful for creating lists of files that need to be taken care
of, or for bulk-opening all of the files in an editor from CLI.
alexeagle pushed a commit to alexeagle/tslint that referenced this pull request Sep 23, 2016
)

Addresses review #875140 in PR palantir#1558 for compatibility with discussion item palantir#1553
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants