1

Prompt with lint-stage.

The front is angular, the back is dot net.

On the front, the lint-stage is successfully used with husky, in order to format the commited files in a pre-commit hook. I'm trying to attach the back by analogy to the lint-stage, but a problem appears - the lint-stage throws the correct path only if the file is in the front directory (since package.json with the lint-stage configuration is in the root of the proj/frontend/package.json).

I also need to format files from the proj/backend directory. I tried to add the second backend pattern to the lint-stage in this form

"../**/*.cs": "dotnet format --include", 

but then the path with dots "../backend/program.cs" is thrown in dotnet format, which it cannot process.

What is the best way to proceed in this situation - while both my solutions are bad, move the package.json part with the lint-stage configuration to a higher level, i.e. in proj/package.json then the problem will go away. Or expand the configuration and write a function into it to delete points at the beginning of the path for a given pattern. Can you tell me the best option?

Package.json config

"husky": {
    "hooks": {
      "pre-commit": "lint-staged --r"
    }
  },
  "lint-staged": {
    "../**/*.cs": "dotnet format --include",
    "*.cs": "dotnet format --include"
  }
}

2 Answers2

0

I installed https://github.com/belav/csharpier and them just used: "../**/*.cs": [ "dotnet csharpier" ], worked like a charm

0

I suggest using dotnet-format with husky.net to make the whole process faster and automatic.

check it out:

https://github.com/alirezanet/Husky.Net

Documentation

AliReza Sabouri
  • 4,355
  • 2
  • 25
  • 37