junxnone / xwiki

https://junxnone.github.io/xwiki/
0 stars 0 forks source link

Programing Python Tools pylint #92

Open junxnone opened 4 years ago

junxnone commented 4 years ago

pylint 代码分析工具

Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的错误,查找不符合代码风格标准和有潜在问题的代码。

MESSAGE_TYPE 有如下几种:

部分问题可以通过 yapf / autopep8 修复

Install

pip install pylint

UseCase

检查单个文件

pylint  test.py

多个文件

pylint -ry -j 4 *.py */*.py 

配置文件

pylint --generate-rcfile > pylint.conf
pylint --rcfile=pylint.conf test.py

配置选项

解决 c-extension 导致的问题

pylint  --ignored-modules=openvino.inference_engine,tensorflow,cv2 --errors-only -ry test.py

忽略某选项

生成报告

pylint -ry --rcfile=pylint.conf test.py

Report

Report ``` Report ====== 113 statements analysed. Statistics by type ------------------ +---------+-------+-----------+-----------+------------+---------+ |type |number |old number |difference |%documented |%badname | +=========+=======+===========+===========+============+=========+ |module |1 |NC |NC |0.00 |0.00 | +---------+-------+-----------+-----------+------------+---------+ |class |0 |NC |NC |0 |0 | +---------+-------+-----------+-----------+------------+---------+ |method |0 |NC |NC |0 |0 | +---------+-------+-----------+-----------+------------+---------+ |function |1 |NC |NC |0.00 |0.00 | +---------+-------+-----------+-----------+------------+---------+ External dependencies --------------------- :: config (train) cv2 (train) matplotlib (train) \-pyplot (train) numpy (train) pandas (train) sklearn \-metrics (train) \-utils \-multiclass (train) utils \-xxxx (train) \-xxxx(train) \-xxx(train) Raw metrics ----------- +----------+-------+------+---------+-----------+ |type |number |% |previous |difference | +==========+=======+======+=========+===========+ |code |166 |84.69 |NC |NC | +----------+-------+------+---------+-----------+ |docstring |0 |0.00 |NC |NC | +----------+-------+------+---------+-----------+ |comment |4 |2.04 |NC |NC | +----------+-------+------+---------+-----------+ |empty |26 |13.27 |NC |NC | +----------+-------+------+---------+-----------+ Duplication ----------- +-------------------------+------+---------+-----------+ | |now |previous |difference | +=========================+======+=========+===========+ |nb duplicated lines |0 |NC |NC | +-------------------------+------+---------+-----------+ |percent duplicated lines |0.000 |NC |NC | +-------------------------+------+---------+-----------+ Messages by category -------------------- +-----------+-------+---------+-----------+ |type |number |previous |difference | +===========+=======+=========+===========+ |convention |99 |NC |NC | +-----------+-------+---------+-----------+ |refactor |0 |NC |NC | +-----------+-------+---------+-----------+ |warning |12 |NC |NC | +-----------+-------+---------+-----------+ |error |13 |NC |NC | +-----------+-------+---------+-----------+ Messages -------- +---------------------------+------------+ |message id |occurrences | +===========================+============+ |bad-continuation |45 | +---------------------------+------------+ |bad-whitespace |33 | +---------------------------+------------+ |import-error |13 | +---------------------------+------------+ |unused-import |11 | +---------------------------+------------+ |wrong-import-order |8 | +---------------------------+------------+ |wrong-import-position |5 | +---------------------------+------------+ |line-too-long |4 | +---------------------------+------------+ |trailing-whitespace |2 | +---------------------------+------------+ |pointless-string-statement |1 | +---------------------------+------------+ |missing-module-docstring |1 | +---------------------------+------------+ |missing-function-docstring |1 | +---------------------------+------------+ -------------------------------------------------------------------- Your code has been rated at -5.58/10 (previous run: -5.58/10, +0.00) ```

Reference

junxnone commented 4 years ago

junxnone/examples#184