Giter VIP home page Giter VIP logo

Comments (10)

JoeRobich avatar JoeRobich commented on September 15, 2024 1

@arnavb With #249, we now log individual messages for each formatting issue. These are printed during --dry-runs 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.

JoeRobich avatar JoeRobich commented on September 15, 2024 1

Closing issue due to inactivity.

from format.

jmarolf avatar jmarolf commented on September 15, 2024

@francisminu can you post what the formatted file looks like? what does the formatter do with these settings?

from format.

francisminu avatar francisminu commented on September 15, 2024

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.

francisminu avatar francisminu commented on September 15, 2024

@jmarolf Hi Jonathan,
Any update on this one?

Thanks!

from format.

jmarolf avatar jmarolf commented on September 15, 2024

Haven't had time to look at this yet @JoeRobich whitespace rules are always applied correct?

from format.

 avatar commented on September 15, 2024

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:

  1. if --dry-run --check is not returning a non-zero exit code, that sounds like a bug to me.
  2. 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.

AnthonyMastrean avatar AnthonyMastrean commented on September 15, 2024

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.

arnavb avatar arnavb commented on September 15, 2024

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.

JoeRobich avatar JoeRobich commented on September 15, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.