Comments (10)
@arnavb With #249, we now log individual messages for each formatting issue. These are printed during --dry-run
s and when you also include the --check
flag it will log as an Error instead of a Warning.
You can try this change by installing from myget
dotnet tool install -g dotnet-format --version 3.1.36303 --add-source https://dotnet.myget.org/F/format/api/v3/index.json
from format.
Closing issue due to inactivity.
from format.
@francisminu can you post what the formatted file looks like? what does the formatter do with these settings?
from format.
When I run just --check, the files are formatted (just like running dotnet format without any options) and the response is as below:
class Program
{
static void Main(string[] args)
{
test();
Console.WriteLine("Inside Main");
}
public static void test()
{
var i = 0;
if (i == 0)
{
Console.WriteLine("i is 0");
}
else
{
Console.WriteLine("i is not 0");
}
Console.WriteLine("Inside Test method");
}
}
When I run --dry-run --check, the files are not formatted, but the message in CLI is as below and the code is given below it:
Formatting code files in workspace 'C:\Project\MyHobbyProjects\EditoConfigCLISample\ConsoleApp1\ConsoleApp1.sln'.
Loading workspace.
Workspace loaded in 1497ms.
Formatting code files in project 'ConsoleApp1'.
Formatting code file 'Program.cs'.
Formatted code file 'Program.cs'.
Formatted 1 of 3 files in 1061ms.
Format complete.
Code:
class Program
{
static void Main(string[] args)
{
test();
Console.WriteLine("Inside Main");
}
public static void test()
{
var i = 0;
if (i == 0){
Console.WriteLine("i is 0");
}
else
{
Console.WriteLine("i is not 0");
}
Console.WriteLine("Inside Test method");
}
}
The console shows the same message in either case. But while running --dry-run --check together, the file is not modified.
Thanks!
from format.
@jmarolf Hi Jonathan,
Any update on this one?
Thanks!
from format.
Haven't had time to look at this yet @JoeRobich whitespace rules are always applied correct?
from format.
If you don't mind, I think I can provide some input on this since I wrote some of the logging code. The --dry-run
option specifies that changes are not saved to disk. The log messages that say files were formatted, I believe, are output after changes are discovered but before the program decides if it needs to actually save those changes to disk. The log messages may simply need to be refactored to happen at a different time.
As for some of the other points:
- if
--dry-run --check
is not returning a non-zero exit code, that sounds like a bug to me. - I don't believe there's a way to output the specific rules that fail currently, but one of the maintainers can provide a more definitive answer on that.
from format.
I installed this version
PS> dotnet format --version
3.0.4+211cab024c37fdffa5955c5855f9d62a14703452
And ran the same command with some extra status reporting at the end
PS> dotnet format --check --dry-run; $?; $LASTEXITCODE
Formatting code files in workspace 'C:\Users\anthony\example\Example.sln'.
Formatting code files in project 'Example'.
Formatted code file 'Foo.cs'.
Formatted code file 'Bar.cs'.
Formatted code file 'Baz.cs'.
...
Format complete.
False
1
And I double-checked the git status just to be sure that check didn't change any files (adhering to the dry-run flag).
PS> git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
from format.
IMO, this behavior doesn't really make sense. Other autoformatters, like prettier or black (for JS and Python respectively), print out an error message instead of actually changing files. I feel like this tool should follow the same convention.
from format.
@AnthonyMastrean Thanks for giving it a run. That is the expected behavior. The formatter is run against each file and the files with formatting changes are printed to the console as Formatted code file 'Foo.cs'.
Because files were formatted a non-zero exit code was returned as expected.
@arnavb I think the story around logging formatting issues is one that we could improve on. Perhaps an easy change to give more meaningful feedback would be to Log the Formatted code file 'Foo.cs'.
message as Error instead of Info when the check flag is passed.
from format.
Related Issues (20)
- Please clarify if this tool is actively supported / worked on HOT 2
- Can I use dotnet format to just generate report and not make the changes to the file. HOT 2
- Issue: Limited Scope for Running the Tool on Changed Files in Pull Requests HOT 1
- running dotnet format on my unity project takes over an hour HOT 2
- .net 8.0.2 Blazor `_imports.razor` & using `IDE0005` HOT 4
- Not detect IDE0290. HOT 1
- IDE0051 format issues with Razor code behind files with SDK 8.0.200 HOT 4
- Questions around Contributing to the Repo HOT 5
- dotnet format is now part of the SDK repo HOT 1
- Wrong indentation when using primary constructor
- Simplify interpolation (IDE0071) - false positive with Enum and FormattableString
- CA1067 on C# record implementing a VB.NET interface
- Does not adhere to language set in `DOTNET_CLI_UI_LANGUAGE`
- Line wrapping and indentation of Collection Literals
- Error Changing document properties is not supported HOT 2
- CS0534 validation adding wrong code. HOT 1
- pre-commit hook fails: no compatible SDK was found HOT 1
- Feature Request: Support for Excluding Specific Subcommands with --skip in dotnet format
- Can't suppress WHITESPACE warnings HOT 2
- [NETSDKE2E][Regression]Failed to run format project with "test.cmd" command. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from format.