如何告诉flake8忽略评论

问题描述 投票:4回答:2

我在emacs中使用flake8来清理我的python代码。我发现将我的评论标记为错误(E501 line too long (x > 79 characters))很烦人。我想知道是否有人知道如何请求flake8忽略单行和多行的评论,但是当我的非评论行太长时仍然让我知道?

提前致谢!

python pep8 flake8
2个回答
3
投票

您可以使用flake8更改configuration file忽略的代码列表。例如,在项目目录中创建一个名为.flake8的文件,其中包含以下内容:

[flake8]
ignore =
    E121,E123,E126,E226,E24,E704,W503,W504,  # these are ignored by default
    E501,  # line too long
per-file-ignores =
    path/to/file.py: F841

这可能比使用# noqa评论更容易。


5
投票

我已经想出了一个可能的解决方案,但可能会有更好的解决方案。如果你写一个会引发E501错误的评论,即它太长,你可以用# noqa: E501附加该行,而flake8会忽略它。例如:

# This is a really really long comment that would usually be flagged by flake8 because it is longer than 79 characters

通常会提高E501,但是

# This is a really really long comment that would usually be flagged by flake8 because it is longer than 79 characters # noqa: E501

将不会。

记录here

© www.soinside.com 2019 - 2024. All rights reserved.