Python - Analyse statique de code
Comment analyser statiquement son code Python et améliorer sa qualité et cohérence en réduisant les erreurs "évitables".
2 outils sortent du lot :
ruff
pylint
ruff
Écrit en rust, très rapide
Installation
Sous MacOs
via brew
1brew install ruff
Usage
1$ cd /codebase/project
2$ ruff check .
3infocapt/fullmaj.py:7:1: E401 Multiple imports on one line
4infocapt/fullmaj.py:7:23: F401 [*] `re` imported but unused
5infocapt/fullmaj.py:13:1: E402 Module level import not at top of file
6infocapt/fullmaj.py:38:20: E701 Multiple statements on one line (colon)
7infocapt/fullmaj.py:39:9: E701 Multiple statements on one line (colon)
8(...)
9Found 337 errors.
10[*] 63 potentially fixable with the --fix option.
Configuration
à écrire
pylint
Écrit en python
, plus lent
Installation
Sous MacOS
via brew
1brew install pylint
Note: ne s'ajoute pas au path !
Usage
1cd /codebase/project
2$ /usr/local/opt/pylint/bin/pylint push/autoliv.py
3************* Module autoliv
4push/autoliv.py:2:0: C0301: Line too long (104/100) (line-too-long)
5push/autoliv.py:4:0: C0301: Line too long (104/100) (line-too-long)
6push/autoliv.py:50:0: C0301: Line too long (109/100) (line-too-long)
7push/autoliv.py:51:0: C0325: Unnecessary parens after 'not' keyword (superfluous-parens)
8(...)
9
10-----------------------------------
11Your code has been rated at 1.31/10
Configuration
à écrire
Ressources
comments powered by Disqus