Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Options:
the current directory for one.
--verbosity, -v Set the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and
diag[nostic]
--dry-run Format files, but do not save changes to disk.
--check Terminates with a non-zero exit code if any files were formatted.
--check, --dry-run Formats files without saving changes to disk. Terminates with a non-zero exit code if any files
were formatted.
--include, --files 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.
Expand All @@ -70,7 +70,7 @@ Add `format` after `dotnet` and before the command arguments that you want to ru
| 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** --check --dry-run | Formats but does not save. Returns a non-zero exit code if any files would have been changed. |
| 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. |

### How To Uninstall
Expand Down
16 changes: 10 additions & 6 deletions eng/format-verifier.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ try {
Write-Output "$(Get-Date) - $solutionFile - Formatting Workspace"
$output = dotnet.exe run -p "$currentLocation\src\dotnet-format.csproj" -c Release -- -w $solution -v d --dry-run | Out-String
Write-Output $output.TrimEnd()

if ($LastExitCode -ne 0) {

# Ignore CheckFailedExitCode since we don't expect these repos to be properly formatted.
if ($LastExitCode -ne 0 -and $LastExitCode -ne 2) {
Write-Output "$(Get-Date) - Formatting failed with error code $LastExitCode."
exit -1
}

if (($output -notmatch "(?m)Formatted \d+ of (\d+) files") -or ($Matches[1] -eq "0")) {
Write-Output "$(Get-Date) - No files found for solution."
exit -1
Expand All @@ -78,19 +79,22 @@ try {
Write-Output "$(Get-Date) - $folderName - Formatting Folder"
$output = dotnet.exe run -p "$currentLocation\src\dotnet-format.csproj" -c Release -- -f $repoPath -v d --dry-run | Out-String
Write-Output $output.TrimEnd()

if ($LastExitCode -ne 0) {

# Ignore CheckFailedExitCode since we don't expect these repos to be properly formatted.
if ($LastExitCode -ne 0 -and $LastExitCode -ne 2) {
Write-Output "$(Get-Date) - Formatting failed with error code $LastExitCode."
exit -1
}

if (($output -notmatch "(?m)Formatted \d+ of (\d+) files") -or ($Matches[1] -eq "0")) {
Write-Output "$(Get-Date) - No files found for solution."
exit -1
}

Write-Output "$(Get-Date) - $folderName - Complete"
}

exit 0
}
catch {
exit -1
Expand Down
15 changes: 8 additions & 7 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace Microsoft.CodeAnalysis.Tools
internal class Program
{
private static readonly string[] _verbosityLevels = new[] { "q", "quiet", "m", "minimal", "n", "normal", "d", "detailed", "diag", "diagnostic" };
internal const int UnhandledExceptionExitCode = 1;
internal const int CheckFailedExitCode = 2;

private static async Task<int> Main(string[] args)
{
Expand All @@ -33,8 +35,7 @@ private static async Task<int> Main(string[] args)
.AddOption(new Option(new[] { "--folder", "-f" }, Resources.The_folder_to_operate_on_Cannot_be_used_with_the_workspace_option, new Argument<string>(() => 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<string>(() => null)))
.AddOption(new Option(new[] { "--verbosity", "-v" }, Resources.Set_the_verbosity_level_Allowed_values_are_quiet_minimal_normal_detailed_and_diagnostic, new Argument<string>() { Arity = ArgumentArity.ExactlyOne }.FromAmong(_verbosityLevels)))
.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[] { "--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<bool>()))
.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<string>(() => null)))
.AddOption(new Option(new[] { "--exclude" }, Resources.A_comma_separated_list_of_relative_file_or_folder_paths_to_exclude_from_formatting, 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)))
Expand All @@ -44,7 +45,7 @@ private static async Task<int> Main(string[] args)
return await parser.InvokeAsync(args).ConfigureAwait(false);
}

public static async Task<int> Run(string folder, string workspace, string verbosity, bool dryRun, bool check, string include, string exclude, string report, IConsole console = null)
public static async Task<int> Run(string folder, string workspace, string verbosity, bool check, string include, string exclude, string report, IConsole console = null)
{
// Setup logging.
var serviceCollection = new ServiceCollection();
Expand Down Expand Up @@ -121,7 +122,7 @@ public static async Task<int> Run(string folder, string workspace, string verbos
workspacePath,
workspaceType,
logLevel,
saveFormattedFiles: !dryRun,
saveFormattedFiles: !check,
changesAreErrors: check,
pathsToInclude,
pathsToExclude,
Expand All @@ -137,11 +138,11 @@ public static async Task<int> Run(string folder, string workspace, string verbos
catch (FileNotFoundException fex)
{
logger.LogError(fex.Message);
return 1;
return UnhandledExceptionExitCode;
}
catch (OperationCanceledException)
{
return 1;
return UnhandledExceptionExitCode;
}
finally
{
Expand All @@ -159,7 +160,7 @@ internal static int GetExitCode(WorkspaceFormatResult formatResult, bool check)
return formatResult.ExitCode;
}

return formatResult.FilesFormatted == 0 ? 0 : 1;
return formatResult.FilesFormatted == 0 ? 0 : CheckFailedExitCode;
}

internal static LogLevel GetLogLevel(string verbosity)
Expand Down
4 changes: 2 additions & 2 deletions src/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
<data name="Format_files_but_do_not_save_changes_to_disk" xml:space="preserve">
<value>Format files, but do not save changes to disk.</value>
</data>
<data name="Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted" xml:space="preserve">
<value>Terminates with a non-zero exit code if any files were formatted.</value>
<data name="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted" xml:space="preserve">
<value>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</value>
</data>
<data name="A_comma_separated_list_of_relative_file_or_folder_paths_to_include_in_formatting_All_files_are_formatted_if_empty" xml:space="preserve">
<value>A comma separated list of relative file or folder paths to include in formatting. All files are formatted if empty.</value>
Expand Down
10 changes: 5 additions & 5 deletions src/xlf/Resources.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Soubory se naformátují, ale změny se neuloží na disk.</target>
<note />
</trans-unit>
<trans-unit id="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files">
<source>Formatted {0} of {1} files.</source>
<target state="new">Formatted {0} of {1} files.</target>
Expand Down Expand Up @@ -127,11 +132,6 @@
<target state="translated">Přeskočí se odkazovaný projekt {0}.</target>
<note />
</trans-unit>
<trans-unit id="Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="The_file_0_does_not_appear_to_be_a_valid_project_or_solution_file">
<source>The file '{0}' does not appear to be a valid project or solution file.</source>
<target state="translated">Soubor {0} zřejmě není platný soubor projektu nebo řešení.</target>
Expand Down
10 changes: 5 additions & 5 deletions src/xlf/Resources.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Dateien formatieren, Änderungen aber nicht auf Festplatte speichern.</target>
<note />
</trans-unit>
<trans-unit id="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files">
<source>Formatted {0} of {1} files.</source>
<target state="new">Formatted {0} of {1} files.</target>
Expand Down Expand Up @@ -127,11 +132,6 @@
<target state="translated">Überspringen von referenziertem Projekt "{0}".</target>
<note />
</trans-unit>
<trans-unit id="Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="The_file_0_does_not_appear_to_be_a_valid_project_or_solution_file">
<source>The file '{0}' does not appear to be a valid project or solution file.</source>
<target state="translated">Die Datei "{0}" ist weder ein gültiges Projekt noch eine Projektmappendatei.</target>
Expand Down
10 changes: 5 additions & 5 deletions src/xlf/Resources.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Formato de archivos, pero no guardar los cambios al disco.</target>
<note />
</trans-unit>
<trans-unit id="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files">
<source>Formatted {0} of {1} files.</source>
<target state="new">Formatted {0} of {1} files.</target>
Expand Down Expand Up @@ -127,11 +132,6 @@
<target state="translated">Omitiendo projecto al que se hace referencia "{0}".</target>
<note />
</trans-unit>
<trans-unit id="Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="The_file_0_does_not_appear_to_be_a_valid_project_or_solution_file">
<source>The file '{0}' does not appear to be a valid project or solution file.</source>
<target state="translated">El archivo "{0}" no parece ser un proyecto o archivo de solución válido.</target>
Expand Down
10 changes: 5 additions & 5 deletions src/xlf/Resources.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Mettez en forme les fichiers, mais n'enregistrez pas les changements sur le disque.</target>
<note />
</trans-unit>
<trans-unit id="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files">
<source>Formatted {0} of {1} files.</source>
<target state="new">Formatted {0} of {1} files.</target>
Expand Down Expand Up @@ -127,11 +132,6 @@
<target state="translated">Saut du projet référencé '{0}'.</target>
<note />
</trans-unit>
<trans-unit id="Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="The_file_0_does_not_appear_to_be_a_valid_project_or_solution_file">
<source>The file '{0}' does not appear to be a valid project or solution file.</source>
<target state="translated">Le fichier '{0}' ne semble pas être un fichier projet ou solution valide.</target>
Expand Down
10 changes: 5 additions & 5 deletions src/xlf/Resources.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">Formatta i file, ma non salvare le modifiche sul disco.</target>
<note />
</trans-unit>
<trans-unit id="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files">
<source>Formatted {0} of {1} files.</source>
<target state="new">Formatted {0} of {1} files.</target>
Expand Down Expand Up @@ -127,11 +132,6 @@
<target state="translated">Il progetto di riferimento '{0}' verrà ignorato.</target>
<note />
</trans-unit>
<trans-unit id="Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="The_file_0_does_not_appear_to_be_a_valid_project_or_solution_file">
<source>The file '{0}' does not appear to be a valid project or solution file.</source>
<target state="translated">Il file '{0}' non sembra essere un file di progetto o di soluzione valido.</target>
Expand Down
10 changes: 5 additions & 5 deletions src/xlf/Resources.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">ファイルを書式設定しますが、変更をディスクに保存しません。</target>
<note />
</trans-unit>
<trans-unit id="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files">
<source>Formatted {0} of {1} files.</source>
<target state="new">Formatted {0} of {1} files.</target>
Expand Down Expand Up @@ -127,11 +132,6 @@
<target state="translated">参照プロジェクト '{0}' をスキップしています。</target>
<note />
</trans-unit>
<trans-unit id="Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="The_file_0_does_not_appear_to_be_a_valid_project_or_solution_file">
<source>The file '{0}' does not appear to be a valid project or solution file.</source>
<target state="translated">ファイル '{0}' が、有効なプロジェクト ファイルまたはソリューション ファイルではない可能性があります。</target>
Expand Down
10 changes: 5 additions & 5 deletions src/xlf/Resources.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
<target state="translated">파일의 형식을 지정하지만 변경 내용을 디스크에 저장하지 않습니다.</target>
<note />
</trans-unit>
<trans-unit id="Formats_files_without_saving_changes_to_disk_Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Formats files without saving changes to disk. Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="Formatted_0_of_1_files">
<source>Formatted {0} of {1} files.</source>
<target state="new">Formatted {0} of {1} files.</target>
Expand Down Expand Up @@ -127,11 +132,6 @@
<target state="translated">참조된 프로젝트 '{0}'을(를) 건너뜁니다.</target>
<note />
</trans-unit>
<trans-unit id="Terminate_with_a_non_zero_exit_code_if_any_files_were_formatted">
<source>Terminates with a non-zero exit code if any files were formatted.</source>
<target state="new">Terminates with a non-zero exit code if any files were formatted.</target>
<note />
</trans-unit>
<trans-unit id="The_file_0_does_not_appear_to_be_a_valid_project_or_solution_file">
<source>The file '{0}' does not appear to be a valid project or solution file.</source>
<target state="translated">'{0}' 파일은 유효한 프로젝트 또는 솔루션 파일이 아닌 것 같습니다.</target>
Expand Down
Loading