radon icon indicating copy to clipboard operation
radon copied to clipboard

[feature] Add support for pre-commit

Open Freed-Wu opened this issue 2 years ago • 3 comments

@Freed-Wu What would this support entail? From a quick read it would seem all configuration is created in each repository where pre-commit is installed.

rubik avatar Feb 23 '22 20:02 rubik

As Freed-Wui didn't react. It's actually only a yaml config on how to use radon in a project. E.g: black: https://github.com/psf/black/blob/main/.pre-commit-hooks.yaml isort: https://github.com/PyCQA/isort/blob/main/.pre-commit-hooks.yaml

After that I (and others) could implement radon in our pre-commit hooks and let it fail on one of those metrics.

Edit: this would also mean, that we get some kind of exit code != 0, when metrics N (e.g. mccabe) is above a given threshold.

tzmara avatar Jun 08 '22 13:06 tzmara

Hey, sorry for late.

Just add a .pre-commit-config.yaml in the root directory of the repository is OK. Like https://github.com/PyCQA/doc8.

Freed-Wu avatar Jul 21 '22 03:07 Freed-Wu

@tzmara @Freed-Wu In that case, since the exit code is important, xenon is the program to use. Radon is meant for human use, Xenon is for programmatic use. It already has a pre-commit hook. You can configure it to fail when specific thresholds are surpassed.

rubik avatar Sep 03 '22 06:09 rubik

Here is a snippet to be put in .pre-commit-config.yaml to use xenon:

  # monitor code’s complexity
  - repo: https://github.com/rubik/xenon
    rev: v0.9.0
    hooks:
      - id: xenon
        args: [ --max-absolute B, --max-modules A, --max-average A ]

Maybe someone will find it useful.

izikeros avatar Nov 17 '22 13:11 izikeros