Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format-379: Add --report command line argument to export json format report to given directory #495

Merged
merged 3 commits into from Feb 5, 2020

Conversation

ghost
Copy link

@ghost ghost commented Jan 21, 2020

PR for this task. I diverged a tad from the original ask (generate a report when the --dry-run is provided) and decided that this would probably be useful in both normal and --dry-run modes. Also allowed the user to provide the output directory for the report, which I felt would be handy too (e.g. publishing it to a report viewer in Jenkins).

…json report of which files have/would have been formatted
@dnfclas
Copy link

dnfclas commented Jan 21, 2020

CLA assistant check
All CLA requirements met.

src/dotnet-format.csproj Outdated Show resolved Hide resolved
@ghost ghost mentioned this pull request Jan 21, 2020
@ghost ghost changed the title format-379-report: Add --report command line argument to export json format report to given directory format-379: Add --report command line argument to export json format report to given directory Jan 21, 2020
@ghost
Copy link
Author

ghost commented Jan 21, 2020

Below is an example output of this change. Let me know if you'd prefer this be converted to camelCase.

[
  {
    "DocumentId": {
      "ProjectId": {
        "Id": "18cf4766-380a-4dc6-ab56-bc1e3b7625a8"
      },
      "Id": "81d1c87b-2187-4a7c-905d-9c413b17f0af"
    },
    "FileName": "CodeFormatter.cs",
    "FilePath": "C:\\projects\\format\\src\\CodeFormatter.cs",
    "FileChanges": [
      {
        "LineNumber": 291,
        "CharNumber": 30,
        "FormatDescription": "Fix whitespace formatting."
      }
    ]
  }
]

@jmarolf jmarolf requested a review from JoeRobich January 21, 2020 15:51
@jmarolf
Copy link
Contributor

jmarolf commented Jan 21, 2020

@JoeRobich ptal

src/CodeFormatter.cs Outdated Show resolved Hide resolved
src/CodeFormatter.cs Outdated Show resolved Hide resolved
src/CodeFormatter.cs Outdated Show resolved Hide resolved
src/CodeFormatter.cs Outdated Show resolved Hide resolved
@jmarolf
Copy link
Contributor

jmarolf commented Jan 21, 2020

@jpshrader looks like a fantastic start! Thanks for the controbution! I left a few comments and I want @JoeRobich to take a look before merging

src/FileChange.cs Outdated Show resolved Hide resolved
src/FormattedFile.cs Outdated Show resolved Hide resolved
@@ -36,13 +36,14 @@ private static async Task<int> Main(string[] args)
.AddOption(new Option(new[] { "--dry-run" }, Resources.Format_files_but_do_not_save_changes_to_disk, new Argument<bool>()))
.AddOption(new Option(new[] { "--check" }, Resources.Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted, new Argument<bool>()))
.AddOption(new Option(new[] { "--files" }, Resources.A_comma_separated_list_of_relative_file_paths_to_format_All_files_are_formatted_if_empty, new Argument<string>(() => null)))
.AddOption(new Option(new[] { "--report" }, Resources.Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory, new Argument<string>(() => null)))
Copy link
Member

Choose a reason for hiding this comment

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

If we made the default value ".", then if just the option is provided it would drop the report in the current folder.

Copy link
Author

Choose a reason for hiding this comment

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

I think there may be difficulty distinguishing between providing an empty argument vs not providing the option at all (unless I'm missing something). Changing the default argument to "." will set 'reportPath` even if you don't provide the argument at all.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, good point.

src/CodeFormatter.cs Show resolved Hide resolved
@JoeRobich
Copy link
Member

@jpshrader Thanks for working on this. It is a good start to providing more report options such as patch file support.

1. Add unit tests for Formatted Files behaviour
2. Use System.Text.Json
3. Path.Combine/StringBuilder and pathing options
4. Pass ref to list instead of returning tuple
@ghost ghost requested review from jmarolf and JoeRobich February 1, 2020 18:26
@jmarolf
Copy link
Contributor

jmarolf commented Feb 1, 2020

@jpshrader looks good to me! If @JoeRobich signs off I'll merge it

Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

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

Thanks so much for this. Just requesting a few changes before we merge it in. =)

@@ -36,13 +36,14 @@ private static async Task<int> Main(string[] args)
.AddOption(new Option(new[] { "--dry-run" }, Resources.Format_files_but_do_not_save_changes_to_disk, new Argument<bool>()))
.AddOption(new Option(new[] { "--check" }, Resources.Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted, new Argument<bool>()))
.AddOption(new Option(new[] { "--files" }, Resources.A_comma_separated_list_of_relative_file_paths_to_format_All_files_are_formatted_if_empty, new Argument<string>(() => null)))
.AddOption(new Option(new[] { "--report" }, Resources.Accepts_a_file_path_which_if_provided_will_produce_a_format_report_json_file_in_the_given_directory, new Argument<string>(() => null)))
Copy link
Member

Choose a reason for hiding this comment

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

Ah, good point.

tests/Formatters/FormattedFilesTests.cs Outdated Show resolved Hide resolved
src/Resources.resx Outdated Show resolved Hide resolved
src/Formatters/DocumentFormatter.cs Outdated Show resolved Hide resolved
Copy link
Member

@JoeRobich JoeRobich left a comment

Choose a reason for hiding this comment

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

LGTM!

@jmarolf do you have any final thoughts?

@jmarolf
Copy link
Contributor

jmarolf commented Feb 5, 2020

@JoeRobich looks good to merge to me!

@ghost
Copy link
Author

ghost commented Feb 5, 2020

Awesome, thanks @JoeRobich / @jmarolf ! Appreciate the reviews!

@JoeRobich JoeRobich merged commit 22cf1af into dotnet:master Feb 5, 2020
@JoeRobich JoeRobich mentioned this pull request Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants