0

Is it possible to write a git pre-commit hook to permit to write only 15 lines of code per 'Method' in the .net code. I knew we can write to limit the lines of code per file, but I am not sure if we can limit the lines of code per Method in a file.

Jyothi
  • 15
  • 3
  • 1
    Yes, that is possible. You would need to call a program/script within that hook that tells you how many lines per method have been changed. – t.niese May 25 '18 at 04:48

1 Answers1

0

That must be perfectly possible.

You should write the exe that will be called by the hook and that scan your projet or even better just the files staged.

I don't know a tool that do that so you will have to write it yourself perhaps using stylecop roslyn analysers (but I don't know of a such rule. Perhaps better based on the cyclomatic complexity) or directly roslyn.

However, it will be difficult to develop and a pain when running before the commit because too long to run.

Why not running the stylecop analyzers or sonarsource analyzer or another one, even custom and fail when building? The feedback will be quicker and already in the tool where to fix it...

Philippe
  • 28,207
  • 6
  • 54
  • 78
  • Hi @Philippe, can you please help me. how i can call FxCop analyzer by pre-commit git hook? I'm new in Bash programming. – user8231110 Dec 16 '19 at 10:28