From 24a214f3f35652d26ab953853854419cfbdebddd Mon Sep 17 00:00:00 2001 From: Adeel Date: Sun, 16 Feb 2020 02:46:26 +0000 Subject: [PATCH 1/4] Use space-separated paths instead of comma-separated --- src/CodeFormatter.cs | 2 +- src/Program.cs | 18 +++++++++--------- src/Resources.resx | 10 +++++----- src/xlf/Resources.cs.xlf | 12 ++++++------ src/xlf/Resources.de.xlf | 12 ++++++------ src/xlf/Resources.es.xlf | 12 ++++++------ src/xlf/Resources.fr.xlf | 12 ++++++------ src/xlf/Resources.it.xlf | 12 ++++++------ src/xlf/Resources.ja.xlf | 12 ++++++------ src/xlf/Resources.ko.xlf | 12 ++++++------ src/xlf/Resources.pl.xlf | 12 ++++++------ src/xlf/Resources.pt-BR.xlf | 12 ++++++------ src/xlf/Resources.ru.xlf | 12 ++++++------ src/xlf/Resources.tr.xlf | 12 ++++++------ src/xlf/Resources.zh-Hans.xlf | 12 ++++++------ src/xlf/Resources.zh-Hant.xlf | 12 ++++++------ tests/CodeFormatterTests.cs | 4 ++-- tests/ProgramTests.cs | 4 ++-- 18 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/CodeFormatter.cs b/src/CodeFormatter.cs index 7915d34b62..7012c6736c 100644 --- a/src/CodeFormatter.cs +++ b/src/CodeFormatter.cs @@ -82,7 +82,7 @@ public static async Task FormatWorkspaceAsync( foreach (var changedDocumentId in projectChanges.GetChangedDocuments()) { var changedDocument = solution.GetDocument(changedDocumentId); - logger.LogInformation(Resources.Formatted_code_file_0, Path.GetFileName(changedDocument.FilePath)); + logger.LogInformation(Resources.Formatted_code_file_0, changedDocument.FilePath); filesFormatted++; } } diff --git a/src/Program.cs b/src/Program.cs index 8691130480..bb0a7a5ee8 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -34,8 +34,8 @@ private static async Task Main(string[] args) .UseExceptionHandler() .AddOption(new Option(new[] { "--folder", "-f" }, Resources.The_folder_to_operate_on_Cannot_be_used_with_the_workspace_option, new Argument(() => null))) .AddOption(new Option(new[] { "--workspace", "-w" }, Resources.The_solution_or_project_file_to_operate_on_If_a_file_is_not_specified_the_command_will_search_the_current_directory_for_one, new Argument(() => null))) - .AddOption(new Option(new[] { "--include", "--files" }, Resources.A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty, new Argument(() => null))) - .AddOption(new Option(new[] { "--exclude" }, Resources.A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting, new Argument(() => null))) + .AddOption(new Option(new[] { "--include", "--files" }, Resources.A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty, new Argument(() => null))) + .AddOption(new Option(new[] { "--exclude" }, Resources.A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting, new Argument(() => null))) .AddOption(new Option(new[] { "--check", "--dry-run" }, Resources.Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted, new Argument())) .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(() => null))) .AddOption(new Option(new[] { "--verbosity", "-v" }, Resources.Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic, new Argument() { Arity = ArgumentArity.ExactlyOne }.FromAmong(_verbosityLevels))) @@ -45,7 +45,7 @@ private static async Task Main(string[] args) return await parser.InvokeAsync(args).ConfigureAwait(false); } - public static async Task Run(string folder, string workspace, string verbosity, bool check, string include, string exclude, string report, IConsole console = null) + public static async Task Run(string folder, string workspace, string verbosity, bool check, string[] include, string[] exclude, string report, IConsole console = null) { // Setup logging. var serviceCollection = new ServiceCollection(); @@ -194,24 +194,24 @@ private static void ConfigureServices(ServiceCollection serviceCollection, ICons } /// - /// Converts a comma-separated list of relative file paths to a hashmap of full file paths. + /// Converts array of relative file paths to a hashmap of full file paths. /// - internal static ImmutableHashSet GetRootedPaths(string paths, string folder) + internal static ImmutableHashSet GetRootedPaths(string[] paths, string folder) { - if (string.IsNullOrEmpty(paths)) + if (paths == null) { - return ImmutableHashSet.Create(); + return ImmutableHashSet.Empty; } if (string.IsNullOrEmpty(folder)) { - return paths.Split(',') + return paths .Select(path => Path.GetFullPath(path, Environment.CurrentDirectory)) .ToImmutableHashSet(StringComparer.OrdinalIgnoreCase); } else { - return paths.Split(',') + return paths .Select(path => Path.GetFullPath(path, Environment.CurrentDirectory)) .Where(path => path.StartsWith(folder)) .ToImmutableHashSet(StringComparer.OrdinalIgnoreCase); diff --git a/src/Resources.resx b/src/Resources.resx index 0c586f74cd..8e25b61c73 100644 --- a/src/Resources.resx +++ b/src/Resources.resx @@ -174,8 +174,8 @@ Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. Formatted code file '{0}'. @@ -216,7 +216,7 @@ Writing formatting report to: '{0}'. - - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. - \ No newline at end of file + diff --git a/src/xlf/Resources.cs.xlf b/src/xlf/Resources.cs.xlf index 947ed04359..fc4dac93dd 100644 --- a/src/xlf/Resources.cs.xlf +++ b/src/xlf/Resources.cs.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.de.xlf b/src/xlf/Resources.de.xlf index 24b879d30f..e060569068 100644 --- a/src/xlf/Resources.de.xlf +++ b/src/xlf/Resources.de.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.es.xlf b/src/xlf/Resources.es.xlf index d385fd5797..1b2a2a01e9 100644 --- a/src/xlf/Resources.es.xlf +++ b/src/xlf/Resources.es.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.fr.xlf b/src/xlf/Resources.fr.xlf index 0d8b6de879..84dc09990a 100644 --- a/src/xlf/Resources.fr.xlf +++ b/src/xlf/Resources.fr.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.it.xlf b/src/xlf/Resources.it.xlf index 4130242296..b1dad16dff 100644 --- a/src/xlf/Resources.it.xlf +++ b/src/xlf/Resources.it.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.ja.xlf b/src/xlf/Resources.ja.xlf index f529430ddc..bdc69b5c93 100644 --- a/src/xlf/Resources.ja.xlf +++ b/src/xlf/Resources.ja.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.ko.xlf b/src/xlf/Resources.ko.xlf index 7a1e25a5a3..78fb2bab3c 100644 --- a/src/xlf/Resources.ko.xlf +++ b/src/xlf/Resources.ko.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.pl.xlf b/src/xlf/Resources.pl.xlf index 70b7604a23..303f09da74 100644 --- a/src/xlf/Resources.pl.xlf +++ b/src/xlf/Resources.pl.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.pt-BR.xlf b/src/xlf/Resources.pt-BR.xlf index c9e44764d0..cbed71e93c 100644 --- a/src/xlf/Resources.pt-BR.xlf +++ b/src/xlf/Resources.pt-BR.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.ru.xlf b/src/xlf/Resources.ru.xlf index dfec1ca123..080a55d76d 100644 --- a/src/xlf/Resources.ru.xlf +++ b/src/xlf/Resources.ru.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.tr.xlf b/src/xlf/Resources.tr.xlf index eba1831c46..a85d1262a0 100644 --- a/src/xlf/Resources.tr.xlf +++ b/src/xlf/Resources.tr.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.zh-Hans.xlf b/src/xlf/Resources.zh-Hans.xlf index 6d722a554d..e5c2c06b73 100644 --- a/src/xlf/Resources.zh-Hans.xlf +++ b/src/xlf/Resources.zh-Hans.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/src/xlf/Resources.zh-Hant.xlf b/src/xlf/Resources.zh-Hant.xlf index 4da8da5916..1cb6f71aa8 100644 --- a/src/xlf/Resources.zh-Hant.xlf +++ b/src/xlf/Resources.zh-Hant.xlf @@ -2,14 +2,14 @@ - - A comma separated list of relative file or folder paths to exclude from formatting. - A comma separated list of relative file or folder paths to exclude from formatting. + + A list of relative file or folder paths to exclude from formatting. + A list of relative file or folder paths to exclude from formatting. - - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. - A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty. + + A list of relative file or folder paths to include in formatting. All files are formatted if empty. + A list of relative file or folder paths to include in formatting. All files are formatted if empty. diff --git a/tests/CodeFormatterTests.cs b/tests/CodeFormatterTests.cs index 027e610a4e..ff175fd7da 100644 --- a/tests/CodeFormatterTests.cs +++ b/tests/CodeFormatterTests.cs @@ -189,7 +189,7 @@ public async Task OnlyLogFormattedFiles() var match = new Regex(pattern, RegexOptions.Multiline).Match(log); Assert.True(match.Success, log); - Assert.Equal("Program.cs", match.Groups[1].Value); + Assert.EndsWith("Program.cs", match.Groups[1].Value); } [Fact] @@ -276,7 +276,7 @@ public async Task LogFilesThatDontMatchExclude() var match = new Regex(pattern, RegexOptions.Multiline).Match(log); Assert.True(match.Success, log); - Assert.Equal("Program.cs", match.Groups[1].Value); + Assert.EndsWith("Program.cs", match.Groups[1].Value); } [Fact] diff --git a/tests/ProgramTests.cs b/tests/ProgramTests.cs index 5bb22a3339..f8ce0f5860 100644 --- a/tests/ProgramTests.cs +++ b/tests/ProgramTests.cs @@ -38,10 +38,10 @@ public void ExitCodeIsSameWithoutCheck() public void FilesFormattedDirectorySeparatorInsensitive() { var filePath = $"other_items{Path.DirectorySeparatorChar}OtherClass.cs"; - var files = Program.GetRootedPaths(filePath, folder: null); + var files = Program.GetRootedPaths(new[] { filePath }, folder: null); var filePathAlt = $"other_items{Path.AltDirectorySeparatorChar}OtherClass.cs"; - var filesAlt = Program.GetRootedPaths(filePathAlt, folder: null); + var filesAlt = Program.GetRootedPaths(new[] { filePathAlt }, folder: null); Assert.True(files.IsSubsetOf(filesAlt)); } From aba69d8cfe05b83608fd4683f309159340adc273 Mon Sep 17 00:00:00 2001 From: Adeel Date: Sun, 16 Feb 2020 05:32:18 +0000 Subject: [PATCH 2/4] Update --help output in README.md --- README.md | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6ef1b35bd3..3caf8f0197 100644 --- a/README.md +++ b/README.md @@ -42,23 +42,19 @@ dotnet tool install -g dotnet-format --version 4.0.111308 --add-source https://d By default `dotnet-format` will look in the current directory for a project or solution file and use that as the workspace to format. If more than one project or solution file is present in the current directory you will need to specify the workspace to format using the `-w` or `-f` options. You can control how verbose the output will be by using the `-v` option. -``` +```sh Usage: dotnet-format [options] Options: - --folder, -f The folder to operate on. Cannot be used with the `--workspace` option. - --workspace, -w The solution or project file to operate on. If a file is not specified, the command will search - the current directory for one. - --include A comma separated list of relative file or folder paths to include in formatting. All files are - formatted if empty. - --exclude A comma separated list of relative file or folder paths to exclude from formatting. - --check Formats files without saving changes to disk. Terminates with a non-zero exit code if any files - were formatted. - --report Writes a json file to the given directory. Defaults to 'format-report.json' if no filename given. - --verbosity, -v Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and - diag[nostic] - --version Display version information + -f, --folder The folder to operate on. Cannot be used with the `--workspace` option. + -w, --workspace The solution or project file to operate on. If a file is not specified, the command will search the current directory for one. + --files, --include A list of relative file or folder paths to include in formatting. All files are formatted if empty. + --exclude A list of relative file or folder paths to exclude from formatting. + --check, --dry-run Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted. + --report Accepts a file path, which if provided, will produce a json report in the given directory. + -v, --verbosity Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic] + --version Display version information ``` Add `format` after `dotnet` and before the command arguments that you want to run: From 755d73d2c829d512a50d46760b241c5443b5a368 Mon Sep 17 00:00:00 2001 From: Adeel Date: Sun, 16 Feb 2020 05:53:51 +0000 Subject: [PATCH 3/4] Update usage of --include option in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3caf8f0197..5deae2ed5d 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Add `format` after `dotnet` and before the command arguments that you want to ru | dotnet **format** -f <folder> | Formats a particular folder and subfolders. | | dotnet **format** -w <workspace> | Formats a specific project or solution. | | dotnet **format** -v diag | Formats with very verbose logging. | -| dotnet **format** --include Programs.cs,Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs | +| dotnet **format** --include Programs.cs Utility\Logging.cs | Formats the files Program.cs and Utility\Logging.cs | | dotnet **format** --check | Formats but does not save. Returns a non-zero exit code if any files would have been changed. | | dotnet **format** --report <report-path> | Formats and saves a json report file to the given directory. | From 197760bbdbba3bd54a30926a4906991e9715a441 Mon Sep 17 00:00:00 2001 From: Adeel Date: Sun, 16 Feb 2020 18:54:09 +0000 Subject: [PATCH 4/4] Change argument type to string[] --- src/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Program.cs b/src/Program.cs index 2061d2740e..2422845de4 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -35,11 +35,11 @@ private static async Task Main(string[] args) }, new Option(new[] { "--include", "--files" }, Resources.A_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty) { - Argument = new Argument(() => null) + Argument = new Argument(() => null) }, new Option(new[] { "--exclude" }, Resources.A_list_of_relative_file_or_folder_paths_to_exclude_from_formatting) { - Argument = new Argument(() => null) + Argument = new Argument(() => null) }, new Option(new[] { "--check", "--dry-run" }, Resources.Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted) {