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

Pass all linted file names to formatter #3838

Merged
merged 4 commits into from
Feb 23, 2019

Conversation

mastermatt
Copy link
Contributor

PR checklist

Overview of change:

Allows the Checkstyle and JUnit formatters to output the
files that did not have any failures.

Is there anything you'd like reviewers to focus on?

Adding a third argument to IFormatter.format seems like a more reasonable option than changing its signature and having a breaking change, but it's not pretty.

CHANGELOG.md entry:

[enhancement] Formatters now receive the full list of of linted file paths as a third argument.
[enhancement] Checkstyle formatter includes every file linted regardless of lint errors.

@palantirtech
Copy link
Member

Thanks for your interest in palantir/tslint, @mastermatt! Before we can accept your pull request, you need to sign our contributor license agreement - just visit https://cla.palantir.com/ and follow the instructions. Once you sign, I'll automatically update this pull request.

Copy link

@giladgray giladgray left a comment

Choose a reason for hiding this comment

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

this looks really great! just one small comment about the formatter interface

@@ -20,7 +20,7 @@ import { IFormatter, IFormatterMetadata } from "./formatter";

export abstract class AbstractFormatter implements IFormatter {
public static metadata: IFormatterMetadata;
public abstract format(failures: RuleFailure[]): string;
public abstract format(failures: RuleFailure[], fixes?: RuleFailure[], fileNames?: string[]): string;

Choose a reason for hiding this comment

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

correct me if i'm wrong: these parameters in the interface definition should not have ? as they are always passed to the implementation. implementors should instead choose to omit the args from their implementations if unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@giladgray I think you're right. I was following the convention already on fixes in IFormatter, however, since the args are always provided they shouldn't be marked as optional.
I've pushed a patch to remove the ?s.

*/
format(failures: RuleFailure[], fixes?: RuleFailure[]): string;
format(failures: RuleFailure[], fixes?: RuleFailure[], fileNames?: string[]): string;

Choose a reason for hiding this comment

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

again, pretty sure the params should not be marked optional

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure what you mean or if this is still relevant. required arguments can't come after optional arguments. and we don't want to break this API.

mastermatt added a commit to mastermatt/tslint that referenced this pull request May 7, 2018
As noted in comments on palantir#3838, these parameters in the interface definition should not have `?` as they are always passed to the implementation.
Implementors should instead choose to _omit_ the args from their implementations if unused.
@mastermatt
Copy link
Contributor Author

@giladgray I was quick to push a patch that removed the ?s, but now looking at the CI errors I remember why I had kept them.
The formatters are meant to be extended by third parties. As illustrated by the errors when trying to build, no longer making them optional breaks backwards compatibility with existing formatters and therefore this change would require a major release.
I'm going to remove the second commit and leave this PR as it was.

@giladgray
Copy link

@mastermatt the CI failures do not look related to the formatter syntax. i don't see any such incompatibilities.

@mastermatt
Copy link
Contributor Author

@giladgray these are the errors I get:

> ~/src/tslint: yarn compile
yarn run v1.6.0
$ npm-run-all -p compile:core compile:test -s compile:scripts
$ tsc -p test
$ tsc -p src
test/formatters/codeFrameFormatterTests.ts(95,39): error TS2554: Expected 3 arguments, but got 1.
test/formatters/codeFrameFormatterTests.ts(101,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/externalFormatterTests.ts(49,30): error TS2554: Expected 3 arguments, but got 1.
test/formatters/externalFormatterTests.ts(58,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/fileslistFormatterTests.ts(44,30): error TS2554: Expected 3 arguments, but got 1.
test/formatters/fileslistFormatterTests.ts(49,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/jsonFormatterTests.ts(104,41): error TS2554: Expected 3 arguments, but got 1.
test/formatters/jsonFormatterTests.ts(109,35): error TS2554: Expected 3 arguments, but got 1.
test/formatters/junitFormatterTests.ts(78,22): error TS2554: Expected 3 arguments, but got 1.
test/formatters/junitFormatterTests.ts(82,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/msbuildFormatterTests.ts(49,30): error TS2554: Expected 3 arguments, but got 1.
test/formatters/msbuildFormatterTests.ts(54,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/pmdFormatterTests.ts(63,22): error TS2554: Expected 3 arguments, but got 1.
test/formatters/pmdFormatterTests.ts(67,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/proseFormatterTests.ts(49,30): error TS2554: Expected 3 arguments, but got 1.
test/formatters/proseFormatterTests.ts(72,30): error TS2554: Expected 3 arguments, but got 2.
test/formatters/proseFormatterTests.ts(77,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/stylishFormatterTests.ts(57,22): error TS2554: Expected 3 arguments, but got 1.
test/formatters/stylishFormatterTests.ts(61,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/tapFormatterTests.ts(50,30): error TS2554: Expected 3 arguments, but got 1.
test/formatters/tapFormatterTests.ts(55,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/verboseFormatterTests.ts(49,30): error TS2554: Expected 3 arguments, but got 1.
test/formatters/verboseFormatterTests.ts(54,24): error TS2554: Expected 3 arguments, but got 1.
test/formatters/vsoFormatterTests.ts(48,30): error TS2554: Expected 3 arguments, but got 1.
test/formatters/vsoFormatterTests.ts(68,30): error TS2554: Expected 3 arguments, but got 2.
test/formatters/vsoFormatterTests.ts(73,24): error TS2554: Expected 3 arguments, but got 1.```

@mastermatt
Copy link
Contributor Author

@giladgray any thoughts on this?

@johnwiseheart
Copy link
Contributor

@mastermatt as a brief follow up, it looks to me like the failing tests are because those tests are using the format method calling it with only two arguments. By adding another argument, you probably need to update those tests.

@mastermatt mastermatt force-pushed the file-names-to-formatters branch 2 times, most recently from ad2e789 to 7a6fbe8 Compare October 26, 2018 18:36
@mastermatt
Copy link
Contributor Author

Could I get some eyes on this again?

To address the comments by @giladgray and @johnwiseheart: @giladgray was right with his first set of comments. The args should not be marked as optional on the AbstractFormatter class and allow implementers to optionally omit those args if they choose. However, making those same two args required in IFormatter is problematic as it would cause the tests of third-party formatters to suddenly fail.
I propose moving forward with this PR as is, since marking fixes in IFormatter.format as optional is the status quo, and I'll open another PR that fixes IFormatter. Since the new PR will have back-breaking changes it can sit around until the next major is ready to go.

@giladgray
Copy link

@mastermatt can you resolve merge conflicts here so we can merge this PR?

For palantir#3837, allows the Checkstyle and JUnit formatters to output the
files that did not have any failures.

Adding a third argument to `IFormatter.format` seems like a more
reasonable option than changing its signature and having a breaking
change.
@mastermatt
Copy link
Contributor Author

@giladgray done.

const groupedFailures: { [k: string]: RuleFailure[] } = {};
for (const failure of failures) {
const fileName = failure.getFileName();
if (fileName in groupedFailures) {
Copy link
Contributor

Choose a reason for hiding this comment

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

typically we don't use the in operator (sorry, I know we should lint for it)

*/
format(failures: RuleFailure[], fixes?: RuleFailure[]): string;
format(failures: RuleFailure[], fixes?: RuleFailure[], fileNames?: string[]): string;
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure what you mean or if this is still relevant. required arguments can't come after optional arguments. and we don't want to break this API.

@@ -55,6 +55,7 @@ export interface IFormatter {
* Formats linter results
* @param failures Linter failures that were not fixed
* @param fixes Fixed linter failures. Available when the `--fix` argument is used on the command line
* @param fileNames All of file paths that were linted
Copy link
Contributor

Choose a reason for hiding this comment

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

"All of the file paths that were linted"

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.

LGTM, but let's wait until we're ready to release 5.13 before merging this (I think there will be a 5.12.1 release before that)

@adidahiya adidahiya changed the title Pass all listed file names to formatter. Pass all linted file names to formatter Feb 23, 2019
@adidahiya
Copy link
Contributor

Lint failure is unrelated due to a semantic merge conflict, I'll fix it on master

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.

6 participants