-
Notifications
You must be signed in to change notification settings - Fork 172
format-379: Add --report command line argument to export json format report to given directory
#495
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Microsoft.CodeAnalysis.Text; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Tools | ||
| { | ||
| public class FileChange | ||
| { | ||
| public int LineNumber { get; } | ||
|
|
||
| public int CharNumber { get; } | ||
|
|
||
| public string FormatDescription { get; } | ||
|
|
||
| public FileChange(LinePosition changePosition, string formatDescription) | ||
| { | ||
| // LinePosition is zero based so we need to increment to report numbers people expect. | ||
| LineNumber = changePosition.Line + 1; | ||
| CharNumber = changePosition.Character + 1; | ||
| FormatDescription = formatDescription; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Microsoft.CodeAnalysis.Tools | ||
| { | ||
| public class FormattedFile | ||
| { | ||
| public DocumentId DocumentId { get; } | ||
|
|
||
| public string FileName { get; } | ||
|
|
||
| public string FilePath { get; } | ||
|
|
||
| public IEnumerable<FileChange> FileChanges { get; } | ||
|
|
||
| public FormattedFile(Document document, IEnumerable<FileChange> fileChanges) | ||
| { | ||
| DocumentId = document.Id; | ||
| FileName = document.Name; | ||
| FilePath = document.FilePath; | ||
| FileChanges = fileChanges; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, good point. |
||
| .UseVersionOption() | ||
| .Build(); | ||
|
|
||
| return await parser.InvokeAsync(args).ConfigureAwait(false); | ||
| } | ||
|
|
||
| public static async Task<int> Run(string folder, string workspace, string verbosity, bool dryRun, bool check, string files, IConsole console = null) | ||
| public static async Task<int> Run(string folder, string workspace, string verbosity, bool dryRun, bool check, string files, string report, IConsole console = null) | ||
| { | ||
| // Setup logging. | ||
| var serviceCollection = new ServiceCollection(); | ||
|
|
@@ -120,7 +121,8 @@ public static async Task<int> Run(string folder, string workspace, string verbos | |
| logLevel, | ||
| saveFormattedFiles: !dryRun, | ||
| changesAreErrors: check, | ||
| filesToFormat); | ||
| filesToFormat, | ||
| reportPath: report); | ||
|
|
||
| var formatResult = await CodeFormatter.FormatWorkspaceAsync( | ||
| formatOptions, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.