美文网首页工作生活
手把手教你使用pylint

手把手教你使用pylint

作者: 一百万个不确定 | 来源:发表于2019-07-03 18:00 被阅读0次

安装pylint

在terminal里面运行如下命令

reno@PS20190428UMVP:~$ pip install pylint

让我们来看看pylint

直接运行一下命令

reno@PS20190428UMVP:~$ pylint

pylint会输出一系列的help文档,然后其中重要的参数有

Master:
  --generate-rcfile=<file>
Commands:
  --help-msg=<msg-id>
Commands:
  --help-msg=<msg-id>
Message control:
  --disable=<msg-ids>
Reports:
  --files-output=<y_or_n>
  --reports=<y_or_n>
  --output-format=<format>

第一个pylint运行

待检查代码:

from datetime import datetime

def see_current_time():
    print(datetime.now())

def SSEEEWAIREDFUNC():
    SSSSSSS=0
    return SSSSSSS


if __name__ == '__main__':
    LLLLLLLong_variable = ''
    see_current_time()

讲上述代码复制到

~/pylint_example.py文件里面

运行检查

reno@PS20190428UMVP:~$ pylint pylint_example.py

得到如下结果

reno@PS20190428UMVP:/mnt/d/work_env/test_pylint$ pylint app.py
No config file found, using default configuration
************* Module app
C:  4, 0: Unnecessary parens after 'print' keyword (superfluous-parens)
C:  7, 0: Exactly one space required around assignment
    SSSSSSS=0
           ^ (bad-whitespace)
C:  1, 0: Missing module docstring (missing-docstring)
C:  3, 0: Missing function docstring (missing-docstring)
C:  6, 0: Function name "SSEEEWAIREDFUNC" doesn't conform to snake_case naming style (invalid-name)
C:  6, 0: Missing function docstring (missing-docstring)
C:  7, 4: Variable name "SSSSSSS" doesn't conform to snake_case naming style (invalid-name)
C: 12, 4: Constant name "LLLLLLLong_variable" doesn't conform to UPPER_CASE naming style (invalid-name)

------------------------------------------------------------------
Your code has been rated at 1.11/10 (previous run: 1.11/10, +0.00)

加上报告参数

reno@PS20190428UMVP:~$ pylint -r y pylint_example.py

这次的输出结果

************* Module pylint_example
C:  4, 0: Unnecessary parens after 'print' keyword (superfluous-parens)
C:  7, 0: Exactly one space required around assignment
    SSSSSSS=0
           ^ (bad-whitespace)
C:  1, 0: Missing module docstring (missing-docstring)
C:  3, 0: Missing function docstring (missing-docstring)
C:  6, 0: Function name "SSEEEWAIREDFUNC" doesn't conform to snake_case naming style (invalid-name)
C:  6, 0: Missing function docstring (missing-docstring)
C:  7, 4: Variable name "SSSSSSS" doesn't conform to snake_case naming style (invalid-name)
C: 12, 4: Constant name "LLLLLLLong_variable" doesn't conform to UPPER_CASE naming style (invalid-name)


Report
======
9 statements analysed.

Statistics by type
------------------

+---------+-------+-----------+-----------+------------+---------+
|type     |number |old number |difference |%documented |%badname |
+=========+=======+===========+===========+============+=========+
|module   |1      |1          |=          |0.00        |0.00     |
+---------+-------+-----------+-----------+------------+---------+
|class    |0      |0          |=          |0           |0        |
+---------+-------+-----------+-----------+------------+---------+
|method   |0      |0          |=          |0           |0        |
+---------+-------+-----------+-----------+------------+---------+
|function |2      |2          |=          |0.00        |50.00    |
+---------+-------+-----------+-----------+------------+---------+



Raw metrics
-----------

+----------+-------+------+---------+-----------+
|type      |number |%     |previous |difference |
+==========+=======+======+=========+===========+
|code      |10     |71.43 |10       |=          |
+----------+-------+------+---------+-----------+
|docstring |0      |0.00  |0        |=          |
+----------+-------+------+---------+-----------+
|comment   |0      |0.00  |0        |=          |
+----------+-------+------+---------+-----------+
|empty     |4      |28.57 |4        |=          |
+----------+-------+------+---------+-----------+



Duplication
-----------

+-------------------------+------+---------+-----------+
|                         |now   |previous |difference |
+=========================+======+=========+===========+
|nb duplicated lines      |0     |0        |=          |
+-------------------------+------+---------+-----------+
|percent duplicated lines |0.000 |0.000    |=          |
+-------------------------+------+---------+-----------+



Messages by category
--------------------

+-----------+-------+---------+-----------+
|type       |number |previous |difference |
+===========+=======+=========+===========+
|convention |8      |8        |=          |
+-----------+-------+---------+-----------+
|refactor   |0      |0        |=          |
+-----------+-------+---------+-----------+
|warning    |0      |0        |=          |
+-----------+-------+---------+-----------+
|error      |0      |0        |=          |
+-----------+-------+---------+-----------+



Messages
--------

+-------------------+------------+
|message id         |occurrences |
+===================+============+
|missing-docstring  |3           |
+-------------------+------------+
|invalid-name       |3           |
+-------------------+------------+
|superfluous-parens |1           |
+-------------------+------------+
|bad-whitespace     |1           |
+-------------------+------------+




------------------------------------------------------------------
Your code has been rated at 1.11/10 (previous run: 1.11/10, +0.00)


相关文章

网友评论

    本文标题:手把手教你使用pylint

    本文链接:https://www.haomeiwen.com/subject/jnvchctx.html