Search code examples
githookpre-commit

Is it possible to write a git pre-commit hook to permit to write 15 lines of code per method in the .net code


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.


Solution

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