I. INTRODUCTION
Flake8 was released by the official Python Python code to detect whether an auxiliary tool specification, flake8 is encapsulated in the following three tools:
- PyFlakes
- Pep8
- NedBatchelder’s McCabe script
Flake8 run through all the tools to start a separate flake8 script, it displays a warning in Per file, merge into the output.
Also add some features:
- This file contains the line will be ignored: # flake8: noqa
- The end of the line will not publish comments containing #noqa alarm
- GIT and Mercurial hook
- McCabe complexity inspector
- It can be extended by the entry point flake8.extension
Second, the use
1, check the files in the specified directory (including all subfolders in this directory)
For example: We have a catalog Zbj_project, if I want to check all the files in this directory is normative: (Use [ie the windows cmd] in the command line)
flake8 Zbj_project
2, the specific type of error (eg, E123) if you just want to check these files
flake8 --select E123 Zbj_project
3. If you need to select the error codes that begin with a particular type, eg: beginning with E
flake8 - SELECT E Zbj_project
If you need to select a plurality of specific error code on it with a comma
4, ignoring specific error code
Static code checking ignore H233 type error
flake8 --ignore H233 Zbj_prioject
5, ignoring the specific files / folders
Static code checking ignore test2.py file
flake8 --exclude Zbj_project/path/test.py Zbj_project
6, Flake8 more about Command Reference
flake8 –-help
7, Flake8 small plug
Compared Flake8 other Python static code checking tool advantage is its good scalability, the following is a description Flake8 several popular plug-ins:
1.hacking
Plug-in installation
pip install hacking
After hackinghacking plug-in installation is complete, a new category of error return codes beginning with H: H ***: Error Type hacking returned.
In some type of error detection in hacking is off by default, or by command-line switches to modify the configuration file: enable-extensions = H106, H203
2.pep8, we
Pep8 not yet supported for the current naming convention checks, this section was developed as a plug-in rule supplement.
Pep8-naming plug after installation is complete, a new class of error return code beginning with N: N ***: Error Type pep8-naming returned.
installation
pip install pep8-naming
8, analysis flake8 report on Jenkins
Plug-in installed on Flake8, flake8 junit report--flake8 report will be converted to junit format
1. Installation flake8-junit-report
pip install flake8-junit-report
2. Output Flake8 test report
flake8 --output-file flake8.txt shadowtest
3. The test result is converted into junit xml
python -m junit_conversor flake8.txt flake8_junit.xml