Chinaunix

标题: python静态代码分析工具——pylint [打印本页]

作者: ning_lianjie    时间: 2010-11-24 16:11
标题: python静态代码分析工具——pylint
1·下载地址:
http://www.logilab.org/project/pylint

2·安装:
pylint-0.22.0.tar.gz
解压,然后python setup.py install
安装过程会自动下载并安装
logilab-astng-0.21.0.tar.gz  logilab-common-0.53.0.tar.gz
这两个工具。

3·使用语法:
pylint 参数 py脚本
如果不加任何参数,会有一个"No config file found, using default configuration"这样的提示,
解决办法,可以生成一个默认的配置文件
pylint --generate-rcfile > pylint.conf
然后再执行
pylint --rcfile=pylint.conf ……

4·参考
http://www.ibm.com/developerworks/cn/linux/l-cn-pylint/index.html

(C) 惯例。违反了编码风格标准
(R) 重构。写得非常糟糕的代码。
(W) 警告。某些 Python 特定的问题。
(E) 错误。很可能是代码中的错误。
(F) 致命错误。阻止 Pylint 进一步运行的错误。

5·总结:
    操作符的左右要加空格
    自定义的变量要大写并简短(([A-Z_][A-Z0-9_]*)|(__.*__))$)
    每行的代码不要太长
作者: winie10    时间: 2010-12-27 09:53
pylint 你没说他是刚什么的。至少你得简单介绍下他的功能吧?
作者: moryaden    时间: 2011-01-07 09:25
pylint自己介绍是说,它是python代码检查工具。

--------------
1. What is pylint?
Pylint is a tool that checks for errors in python code, tries to enforce a coding standard and looks for bad code smells. This is similar but nevertheless different from what pychecker provides, especially since pychecker explicitly does not bother with coding style. The default coding style used by pylint is close to Guido's style guide. For more information about code smells, refer to Martin Fowler's refactoring book
Pylint will display a number of errors and warnings as it analyzes the code, as well as some statistics about the number of warnings and errors found in different files. If you run pylint twice, it will display the statistics from the previous run together with the ones from the current run, so that you can see if the code has improved or not.
Last but not least, the code is given an overall mark, based on the number an severity of the warnings and errors. This has proven to be very motivating for programmers.
作者: moryaden    时间: 2011-01-07 09:26
其实,主要是代码的风格检查,而不是逻辑检查。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2