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
--check returns exit code 2 when no files are changed #979
Comments
I think we should definitely add a "allow warnings" option that does this. I could also see someone making a change to the project file that causes dotnet format to not be able to apply things and you would want to know about that |
there are all kind of warnings showing up which are not related to formatting. just a short part of the logs. but yes, there are also non-fixable compiler diagnostics warnings. do you think only the non-fixable diagnostics are the problem?
|
Diagnostics which begin with CS typically are compiler diagnostics. Could you install a nightly build (these are the instructions), which contains the fix that I mentioned earlier, and let us know if that resolves the issue for you? |
just tried with version 6.0.211701 and it gives also exit code 2. i guess it really reports all rule violations as errors. |
just did a simple test with a single rule violation. is this expected? i guess "format" shouldn't report on linting rules. IDE1006 results in exit code 2.
|
This behavior is expected. Since you are passing the |
that's unfortunate as we would like to fix all style and analyzer issues too. there should be an option which checks if dotnet format makes actual changes to files instead of reporting compiler errors/warnings. isn't that the job of dotnet build/msbuild to break on compiler validation? i expected dotnet format to auto-format and --check to validate if the format is up to date. |
The |
yes i know. my problem with this tool is that it reports on issues it isn‘t able to auto-fix. |
i really expected this to behave like it states in the docs.
|
I understand your issue better now. This PR #776 changed the behavior of how It loooks like we have two sets of users we need to satisfy. One wants to strictly validate that the options set in .editorconfig are being followed. The other does not want to penalize for issues that cannot be automatically resolved. |
the main problem i see here is that you try to implement dotnet format as a linter and formatter at the same time. https://taiyr.me/what-is-the-difference-between-code-linters-and-formatters/ imho dotnet format should be a formatter and dotnet build can be used as a linter with ruleset/editorconfig. |
While I agree with the overall goal, there exists no mechanism in dotnet build to enforce some of these rules. Someday when that is not the case we can consider leaving enforcement behind and only focus on fixes. |
@OneCyrus Here is a workaround that would work with git. This workflow assumes there are no unstaged changes in the repo. First, you could run dotnet-format without the No files available for staging because no files were fixed during the format. ~/Source/format [git-test]> dotnet format --fix-analyzers info --fix-style info --fix-whitespace -v d
The dotnet format version is '5.0.211103+b95e1694941ca2595941f1c9cd0d9727b6c53d43'.
The dotnet runtime version is '6.0.0-alpha.1.21064.11'.
Formatting code files in workspace '/Users/joeyrobichaud/Source/format/format.sln'.
Running 52 analyzers on dotnet-format.
Running 52 analyzers on dotnet-format.UnitTests.
Running 52 analyzers on dotnet-format.Performance.
src/Program.cs(44,39): Naming rule violation: These words must begin with upper case characters: run (IDE1006)
Running 1 analyzers on dotnet-format.
Unable to fix IDE1006. Code fix NamingStyleCodeFixProvider doesn't support Fix All in Solution.
Unable to fix IDE1006. Code fix NamingStyleCodeFixProvider doesn't support Fix All in Solution.
Unable to fix IDE1006. Code fix NamingStyleCodeFixProvider doesn't support Fix All in Solution.
Running 18 analyzers on dotnet-format.
Running 55 analyzers on dotnet-format.UnitTests.
Running 18 analyzers on dotnet-format.Performance.
Formatted code file '/Users/joeyrobichaud/Source/format/src/Program.cs'.
Formatted 1 of 97 files.
Format complete in 8485ms.
~/Source/format [git-test]> git diff-files --quiet
~/Source/format [git-test]> $lastexitcode
0 File available for staging because a file was formatted during the format. ~/Source/format [git-test]> dotnet format --fix-analyzers info --fix-style info --fix-whitespace -v d
The dotnet format version is '5.0.211103+b95e1694941ca2595941f1c9cd0d9727b6c53d43'.
The dotnet runtime version is '6.0.0-alpha.1.21064.11'.
Formatting code files in workspace '/Users/joeyrobichaud/Source/format/format.sln'.
Running 52 analyzers on dotnet-format.
Running 52 analyzers on dotnet-format.UnitTests.
Running 52 analyzers on dotnet-format.Performance.
Running 18 analyzers on dotnet-format.
Running 55 analyzers on dotnet-format.UnitTests.
Running 18 analyzers on dotnet-format.Performance.
Formatted code file '/Users/joeyrobichaud/Source/format/src/Program.cs'.
Formatted 1 of 97 files.
Format complete in 8871ms.
~/Source/format [git-test +0 ~1 -0 !]> git diff-files --quiet
~/Source/format [git-test +0 ~1 -0 !]> $lastexitcode
1 |
hmm what's the issue there? we are currently enforcing them with the severity of the rules e.g. for the same issue we can set the rule to error and it breaks the build: |
ok. yes that could work. may be we can get also a new switch like |
@OneCyrus I assume you are using the brand new to 16.8 Either way these are currently experimental, but I have a plan to have it work be fully supported by .NET 6. This option is not available to folks on older versions of the SDK however so We'll need to decide that we want to do there. |
no, we don't use this parameter. our builds break when we enforce rules in the .editorconfig file. |
Closing this issue as we've seen no reply to the request for more information. If you are able to get the requested information, please add it to the issue and we will retriage it. |
i guess the "needs more info" tag is wrong. @jmarolf any update on this? especially as you mentioned .NET 6, are there any changes in this regard now that this tool is part of the SDK? |
the --check argument returns exit code 2 when there are some warnings from the analyzers which aren't related to formatting. --check should always return a 0 when no changes are made to files so we can use it in CI pipelines.
The text was updated successfully, but these errors were encountered: