dotnet / format

Home for the dotnet-format command
MIT License
1.94k stars 173 forks source link

pre-commit hook does not work if the solution is in a sub directory #1232

Open FrancisGauthier opened 3 years ago

FrancisGauthier commented 3 years ago

i use the following .pre-commit-config.yaml file.

image

The structure of the repository looks like this

image

Thanks,

tcharetteacerta commented 1 year ago

Seconded. This is still the case.

ylatuya commented 9 months ago

You can pass the path to the solution using the entry arguments, modifying the dotnet format command to your needs:

-   repo: local
    hooks:
    #Use dotnet format already installed on your machine
    -   id: dotnet-format
        name: dotnet-format
        language: system
        entry: dotnet format src/solution.sln -v normal --include
        files: ^src/.*
        types_or: ["c#", "vb"]

I case you have several solutions in your repository, you can add several hooks with the files filter, each one running against a particular solution file

-   repo: local
    hooks:
    #Use dotnet format already installed on your machine
    -   id: dotnet-format
        name: dotnet-format
        language: system
        entry: dotnet format src/project1/solution.sln -v normal --include
        files: ^src/project1/.*
        types_or: ["c#", "vb"]
    -   id: dotnet-format
        name: dotnet-format
        language: system
        entry: dotnet format src/project2/solution.sln -v normal --include
        files: ^src/project2/.*
        types_or: ["c#", "vb"]

This way files from src/project1/ will be checked with dotnet format src/project1/solution.sln and files from src/project2/ will be checked with dotnet format src/project2/solution.sln

$ git commit src/project1/MyApp/Test.cs
dotnet-format............................................................Passed
dotnet-format........................................(no files to check)Skipped