在 Sublime 中配置插件几乎总是使用相同的过程:点击 Preferences -> Package Settings -> Plugin Name -> Settings-Default 打开(惊喜)默认设置。该文件通常包含插件的所有可能设置,通常与 cmets 一起解释每个设置的作用。此文件无法修改,因此要自定义您打开 Preferences -> Package Settings -> Plugin Name -> Settings-User 的任何设置。我一般将默认设置的全部内容复制到用户文件中,然后根据需要自定义,然后保存并关闭。
在这个特定插件的情况下,虽然它确实使用了pyflakes(如宣传的那样),但它也使用了pep8,这是一个样式检查器,它使用了相同的PEP-8官方Python样式指南I cmets中提到。这个知识很有用,因为pyflakes 不使用特定的错误代码,而pep8 可以。
因此,在检查插件的设置文件后,我们发现了一个"pep8_ignore" 选项以及一个"pyflakes_ignore" 选项。由于error codes 来自pep8,我们将使用该设置:
"pep8_ignore": [ "E501", // line too long
"E303", // too many blank lines (3)
"E402" // module level import not at top of file
]
请注意,代码 E121、E123、E126、E133、E226、E241、E242 和 E704 在默认情况下会被忽略,因为它们不是一致接受的规则,而且 PEP 8 不会强制执行它们。
关于长线:
有时,排长队是不可避免的。 PEP-8 的recommendation 79 个字符行是基于古代历史,当时终端监视器只有 80 个字符宽的屏幕,但它一直持续到今天有几个原因:它向后兼容旧代码,一些设备仍在使用与这些限制一起使用,它看起来不错,它可以在更宽的显示器上更轻松地并排打开多个文件,并且它是可读的(在编码时应该始终牢记这一点)。如果您更喜欢 90 或 100 个字符的限制,那很好(如果您的团队/项目同意),但请始终使用它,并注意其他人可能使用不同的值。如果您想将 pep8 设置为大于默认值 80 的值,只需修改 "pep8_max_line_length" 设置即可。
有很多方法可以减少行的字符数以保持在限制范围内,或者将长行拆分为多个较短的行。对于您在 cmets 中的示例:
flag, message = FacebookUserController.AddFBUserToDB(iOSUserId, fburl, fbsecret, code)
你可以做几件事:
# shorten the module/class name
fbuc = FacebookUserController
# or
import FacebookUserController as fbuc
flag, message = fbuc.AddFBUserToDB(iOSUserId, fburl, fbsecret, code)
# or eliminate it all together
from FacebookUserController import AddFBUserToDB
flag, message = AddFBUserToDB(iOSUserId, fburl, fbsecret, code)
# split the function's arguments onto separate lines
flag, message = FacebookUserController.AddFBUserToDB(iOSUserId,
fburl,
fbsecret,
code)
# There are multiple ways of doing this, just make sure the subsequent
# line(s) are indented. You don't need to escape newlines inside of
# braces, brackets, and parentheses, but you do need to outside of them.