pylint 不为 C0326 空白违规生成消息

pylint not generating messages for C0326 whitepace violations

pylint 没有为空白不符合项生成预期的约定警告消息。

python 3.6.8

pylint 2.13.5

使用这个测试脚本:

from __future__ import print_function
import os, sys
import logging
from .. import views

class DoSomething(SomeCommand) : # space before colon !

    def __init__(self):
        for i in range(1,11):   # no space after comma !!
            if self.number == i:
                print("matched")
            else:
                print ('not matched') # space before paren !!!

    def check_user(self):
        if self.user: return True
        else  : return False    # spaces before colon !

pylint 检查的结果:

PS C:\Users\PycharmProjects\coding_standard\src> pylint test_script.py
************* Module test_script
test_script.py:18:0: C0304: Final newline missing (missing-final-newline)
test_script.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test_script.py:3:0: C0410: Multiple imports on one line (os, sys) (multiple-imports)
test_script.py:5:0: E0402: Attempted relative import beyond top-level package (relative-beyond-top-level)
test_script.py:7:0: C0115: Missing class docstring (missing-class-docstring)
test_script.py:7:18: E0602: Undefined variable 'SomeCommand' (undefined-variable)
test_script.py:16:4: C0116: Missing function or method docstring (missing-function-docstring)
test_script.py:17:8: R1703: The if statement can be replaced with 'return bool(test)' (simplifiable-if-statement)
test_script.py:17:8: R1705: Unnecessary "else" after "return", remove the "else" and de-indent the code inside it (no-else-return)
test_script.py:17:22: C0321: More than one statement on a single line (multiple-statements)
test_script.py:7:0: R0903: Too few public methods (1/2) (too-few-public-methods)
test_script.py:3:0: W0611: Unused import os (unused-import)
test_script.py:3:0: W0611: Unused import sys (unused-import)
test_script.py:4:0: W0611: Unused import logging (unused-import)
test_script.py:5:0: W0611: Unused import views (unused-import)

根据文档,我希望看到注释行的 C0326 消息。

C0326要识别的条件我是参考这个: http://pylint-messages.wikidot.com/messages:c0326

对T/S这个有什么建议吗?

基于@DylanLee 的评论... 如果我这样做了,那确实是偶然的。我没有(有意)使用任何类型的配置文件来禁用消息。根据您的评论,我使用了命令行选项: $pylint --list-msgs-enabled

,生成一个列表...

Enabled messages:
  ...
  multiple-statements (C0321)
  superfluous-parens (C0325)
  mixed-line-endings (C0327)
  unexpected-line-ending-format (C0328)
  wrong-spelling-in-comment (C0401)
   ...

Disabled messages:
  raw-checker-failed (I0001)
  bad-inline-option (I0010)
  locally-disabled (I0011)
  file-ignored (I0013)
  suppressed-message (I0020)
  useless-suppression (I0021)
  deprecated-pragma (I0022)
  use-symbolic-message-instead (I0023)

所以,显然不是禁用,而是不在启用列表中! 也许对抑制该特定消息的 pylint 进行了一些更新?

bad-whitespace 已从 2.6 中的 pylint 中删除。你应该使用像 blackpre-commit 这样的自动格式化程序来自动处理这个问题。

参见:https://pylint.pycqa.org/en/latest/whatsnew/2.6.html?highlight=bad-whitespace#other-changes

bad-continuation and bad-whitespace have been removed. black or another formatter can help you with this better than Pylint