此代码由黑色创建
def test_schema_org_script_from_list():
assert (
schema_org_script_from_list([1, 2])
== '<script type="application/ld+json">1</script>\n<script type="application/ld+json">2</script>'
)但现在flake8抱怨道:
test/test_utils.py:59:9:二进制运算符之前的W503行中断 test/test_utils.py:59:101: E501行过长(105个>100个字符)
我如何格式化上面的行并使flake8高兴呢?
我使用这个.pre-commit-config.yaml
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: 'https://gitlab.com/pycqa/flake8'
rev: 3.8.4
hooks:
- id: flake8
- repo: 'https://github.com/pre-commit/mirrors-isort'
rev: v5.7.0
hooks:
- id: isorttox.ini:
[flake8]
max-line-length = 100
exclude = .git,*/migrations/*,node_modules,migrate
# W504 line break after binary operator
ignore = W504(我认为flake8从一个属于另一个工具的文件中读取配置有点奇怪)。
发布于 2021-01-26 20:35:08
根据您的配置,您已经设置了ignore = W504
ignore不是您想要的选项,因为它重置默认的忽略(带来了很多东西,包括W503)。
如果删除ignore=,则W504和W503都处于默认的忽略状态,因此不会被捕获。
至于您的E501 (行太长),可以选择extend-ignore = E501,也可以适当地设置max-line-length
对于黑色,这是建议配置
[flake8]
max-line-length = 88
extend-ignore = E203请注意,在某些情况下,黑色不能使行足够短(正如您所看到的) --无论是长字符串还是长变量名。
免责声明:我现在是flake8的维护者
https://stackoverflow.com/questions/65809122
复制相似问题