选项及其说明的完整列表

选项及其说明

--version

Go back to index

Flake8 的版本以及安装的所有插件的版本。

命令行用法:

flake8 --version

这个 不能 在配置文件中指定。

-h, --help

Go back to index

说明如何使用 Flake8 以及它的选择。

命令行用法:

flake8 --help
flake8 -h

这个 不能 在配置文件中指定。

-v, --verbose

Go back to index

增加 Flake8 的输出。每次指定它时,它将打印越来越多的信息。

命令行示例:

flake8 -vv

这个 不能 在配置文件中指定。

-q, --quiet

Go back to index

减少 Flake8 的输出。每次指定它时,它将打印越来越少的信息。

命令行示例:

flake8 -q

这个 can 在配置文件中指定。

配置文件用法示例:

quiet = 1
--count

Go back to index

打印错误总数。

命令行示例:

flake8 --count dir/

这个 can 在配置文件中指定。

配置文件用法示例:

count = True
--diff

Go back to index

使用标准中提供的统一diff仅检查修改的文件并报告diff中包含的错误。

命令行示例:

git diff -u | flake8 --diff

这个 不能 在配置文件中指定。

--exclude=<patterns>

Go back to index

提供要从检查中排除的glob模式的逗号分隔列表。

默认为: .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg

示例模式:

  • *.pyc will match any file that ends with .pyc

  • __pycache__ 将匹配任何具有 __pycache__ 在里面

  • lib/python 将看起来扩展使用 os.path.abspath() 寻找匹配的路径

命令行示例:

flake8 --exclude=*.pyc dir/

这个 can 在配置文件中指定。

配置文件用法示例:

exclude =
    .tox,
    __pycache__
--extend-exclude=<patterns>

Go back to index

3.8.0 新版功能.

提供一个以逗号分隔的glob模式列表,以添加到排除的模式列表中。类似于 --exclude 此处适用于该值。

不同于 --exclude 选项是,此选项可用于有选择地添加单个模式,而无需完全覆盖默认列表。

命令行示例:

flake8 --extend-exclude=legacy/,vendor/ dir/

这个 can 在配置文件中指定。

配置文件用法示例:

extend-exclude =
    legacy/,
    vendor/
extend-exclude = legacy/,vendor/
--filename=<patterns>

Go back to index

提供一个逗号分隔的glob模式列表以供检查。

默认为: *.py

示例模式:

  • *.py will match any file that ends with .py

  • __pycache__ 将匹配任何具有 __pycache__ 在里面

  • lib/python 将看起来扩展使用 os.path.abspath() 寻找匹配的路径

命令行示例:

flake8 --filename=*.py dir/

这个 can 在配置文件中指定。

配置文件用法示例:

filename =
    example.py,
    another-example*.py
--stdin-display-name=<display_name>

Go back to index

提供用于报告stdin上代码的警告和错误的名称。

而不是将错误报告为:

stdin:82:73 E501 line too long

您可以指定这个选项,让它报告您想要的任何值,而不是stdin。

默认为: stdin

命令行示例:

cat file.py | flake8 --stdin-display-name=file.py -

这个 不能 在配置文件中指定。

--format=<format>

Go back to index

选择用于向用户显示错误的格式化程序。

默认为: default

默认情况下,有两个可用的格式化程序:

  • 缺省

  • pylint

可以安装其他格式化程序。请参阅他们的文档以获取用于选择它们的名称。此外,用户可以指定自己的格式字符串。可用变量包括:

  • code

  • col

  • path

  • text

默认格式化程序的格式字符串为:

'%(path)s:%(row)d:%(col)d: %(code)s %(text)s'

命令行示例:

flake8 --format=pylint dir/
flake8 --format='%(path)s::%(row)d,%(col)d::%(code)s::%(text)s' dir/

这个 can 在配置文件中指定。

配置文件用法示例:

format=pylint
format=%(path)s::%(row)d,%(col)d::%(code)s::%(text)s
--hang-closing

Go back to index

切换pycodestyle是否应强制匹配左括号行的缩进。当您指定此选项时,它会倾向于挂起右括号而不是匹配缩进。

命令行示例:

flake8 --hang-closing dir/

这个 can 在配置文件中指定。

配置文件用法示例:

hang_closing = True
hang-closing = True
--ignore=<errors>

Go back to index

指定要忽略的代码列表。列表应以逗号分隔,不需要精确指定错误代码。因为 Flake8 3.0,这个 can 与…结合 --select . 见 --select 更多信息。

例如,如果您只想忽略 W234 ,则可以指定它。但是如果你想忽略所有以 W23 您只需指定 W23 无视他们。这也适用于 W2W (例如)。

默认为: E121,E123,E126,E226,E24,E704,W503,W504

命令行示例:

flake8 --ignore=E121,E123 dir/
flake8 --ignore=E24,E704 dir/

这个 can 在配置文件中指定。

配置文件用法示例:

ignore =
    E121,
    E123
ignore = E121,E123
--extend-ignore=<errors>

Go back to index

3.6.0 新版功能.

指定要添加到忽略的代码列表中的代码列表。类似于 --ignore 此处适用于该值。

不同于 --ignore 选项是,此选项可用于有选择地添加单个代码,而不完全覆盖默认列表。

命令行示例:

flake8 --extend-ignore=E4,E51,W234 dir/

这个 can 在配置文件中指定。

配置文件用法示例:

extend-ignore =
    E4,
    E51,
    W234
extend-ignore = E4,E51,W234
--per-file-ignores=<filename:errors>[ <filename:errors>]

Go back to index

3.7.0 新版功能.

指定文件映射的列表以及在整个文件中应忽略的代码。这样,项目就可以有一个默认的冲突列表,这些冲突列表应该被忽略,并且对于那些未被设置为符合项目规则的文件,也可以有特定于文件的冲突列表。

此选项支持类似于 --exclude 这样glob模式在这里也会起作用。

这两者都可以结合使用 --ignore--extend-ignore 实现风格选择的充分灵活性。

命令行用法:

flake8 --per-file-ignores='project/__init__.py:F401 setup.py:E121'
flake8 --per-file-ignores='project/*/__init__.py:F401 setup.py:E121'

这个 can 在配置文件中指定。

per-file-ignores =
    project/__init__.py:F401
    setup.py:E121
    other_project/*:W9
--max-line-length=<n>

Go back to index

设置任何行(除某些例外)的最大长度。

例外情况包括完全是URL的字符串或注释行。例如:

# https://some-super-long-domain-name.com/with/some/very/long/path

url = (
    'http://...'
)

默认为: 79

命令行示例:

flake8 --max-line-length 99 dir/

这个 can 在配置文件中指定。

配置文件用法示例:

max-line-length = 79
--max-doc-length=<n>

Go back to index

设置注释或docstring行的最大长度。

默认情况下,文档行长度没有限制。

命令行示例:

flake8 --max-doc-length 99 dir/

这个 can 在配置文件中指定。

配置文件用法示例:

max-doc-length = 79
--select=<errors>

Go back to index

指定所需的错误代码列表 Flake8 报告。类似于 --ignore . 您可以指定错误代码的一部分以该字符串开头。例如,您可以使用 EE4E43E431 .

默认为: E,F,W,C90

命令行示例:

flake8 --select=E431,E5,W,F dir/
flake8 --select=E,W dir/

这也可以与 --ignore

flake8 --select=E --ignore=E432 dir/

这将报告所有以 E ,但忽略 E432 明确地。这比 Flake8 以前是2.x和1.x。

这个 can 在配置文件中指定。

配置文件用法示例:

select =
    E431,
    W,
    F
--disable-noqa

Go back to index

报告所有错误,即使它与 # NOQA 评论。 # NOQA 可用于使特定行上的消息静音。有时,用户希望看到哪些错误在不编辑文件的情况下被消除。此选项允许您查看报告的所有警告、错误等。

命令行示例:

flake8 --disable-noqa dir/

这个 can 在配置文件中指定。

配置文件用法示例:

disable_noqa = True
disable-noqa = True
--show-source

Go back to index

打印生成有问题的错误/警告的源代码。

命令行示例:

flake8 --show-source dir/

这个 can 在配置文件中指定。

配置文件用法示例:

show_source = True
show-source = True
--statistics

Go back to index

计算每个错误/警告代码的出现次数并打印报告。

命令行示例:

flake8 --statistics

这个 can 在配置文件中指定。

配置文件用法示例:

statistics = True
--enable-extensions=<errors>

Go back to index

默认情况下启用关闭扩展。

插件到 Flake8 可以选择在默认情况下将自己注册为关闭。这些插件有效地将自己添加到默认的忽略列表中。

命令行示例:

flake8 --enable-extensions=H111 dir/

这个 can 在配置文件中指定。

配置文件用法示例:

enable-extensions =
    H111,
    G123
enable_extensions =
    H111,
    G123
--exit-zero

Go back to index

Flake8 即使存在错误,也要使用退出状态代码0。

默认情况下 Flake8 如果有错误,将以非零整数退出。

命令行示例:

flake8 --exit-zero dir/

这个 不能 在配置文件中指定。

--install-hook=VERSION_CONTROL_SYSTEM

Go back to index

为在提交之前或期间执行的版本控制系统安装一个钩子。

可用选项包括:

  • git

  • mercurial

命令行用法:

flake8 --install-hook=git
flake8 --install-hook=mercurial

这个 不能 在配置文件中指定。

--jobs=<n>

Go back to index

指定所需的子进程数 Flake8 将用于并行运行检查。

注解

此选项在Windows上被忽略,因为 multiprocessing 不支持所有支持的Python版本的Windows。

默认为: auto

默认行为将使用计算机上CPU的数量,如 multiprocessing.cpu_count() .

命令行示例:

flake8 --jobs=8 dir/

这个 can 在配置文件中指定。

配置文件用法示例:

jobs = 8
--output-file=<path>

Go back to index

将所有输出重定向到指定的文件。

命令行示例:

flake8 --output-file=output.txt dir/
flake8 -vv --output-file=output.txt dir/
--tee

Go back to index

如果输出文件已配置,还将输出打印到stdout。

命令行示例:

flake8 --tee --output-file=output.txt dir/

这个 can 在配置文件中指定。

配置文件用法示例:

output-file = output.txt
tee = True
--append-config=<config>

Go back to index

3.6.0 新版功能.

提供额外的配置文件以便在之后进行分析,并在 Flake8 它自己发现的。由于这些文件是最后读入配置解析器的文件,因此如果它提供在另一个配置文件中指定的选项,则具有最高的优先级。

命令行示例:

flake8 --append-config=my-extra-config.ini dir/

这个 不能 在配置文件中指定。

--config=<config>

Go back to index

提供配置文件的路径,该文件将是唯一读取和使用的配置文件。这将导致 Flake8 忽略所有存在的配置文件。

命令行示例:

flake8 --config=my-only-config.ini dir/

这个 不能 在配置文件中指定。

--isolated

Go back to index

忽略任何配置文件并使用 Flake8 好像没有找到配置文件。

命令行示例:

flake8 --isolated dir/

这个 不能 在配置文件中指定。

--builtins=<builtins>

Go back to index

提供内置函数、对象、名称等的自定义列表。

这允许您让pyflakes知道它可能无法立即识别的内置项,因此它不会报告使用未定义名称的警告。

这是由默认的PyFlakes插件注册的。

命令行示例:

flake8 --builtins=_,_LE,_LW dir/

这个 can 在配置文件中指定。

配置文件用法示例:

builtins =
    _,
    _LE,
    _LW
--doctests

Go back to index

对docstring中的doctest启用PyFlakes语法检查。

这是由默认的PyFlakes插件注册的。

命令行示例:

flake8 --doctests dir/

这个 can 在配置文件中指定。

配置文件用法示例:

doctests = True
--include-in-doctest=<paths>

Go back to index

指定PyFlakes检查哪些文件的doctest语法。

这是由默认的PyFlakes插件注册的。

命令行示例:

flake8 --include-in-doctest=dir/subdir/file.py,dir/other/file.py dir/

这个 can 在配置文件中指定。

配置文件用法示例:

include-in-doctest =
    dir/subdir/file.py,
    dir/other/file.py
include_in_doctest =
    dir/subdir/file.py,
    dir/other/file.py
--exclude-from-doctest=<paths>

Go back to index

指定PyFlakes不检查哪些文件的doctest语法。

这是由默认的PyFlakes插件注册的。

命令行示例:

flake8 --exclude-from-doctest=dir/subdir/file.py,dir/other/file.py dir/

这个 can 在配置文件中指定。

配置文件用法示例:

exclude-from-doctest =
    dir/subdir/file.py,
    dir/other/file.py
exclude_from_doctest =
    dir/subdir/file.py,
    dir/other/file.py
--benchmark

Go back to index

收集并打印此运行的基准 Flake8 . 这将合计以下总数:

  • 令牌

  • 物理线

  • 逻辑线

  • 文件夹

以及经过的秒数。

命令行用法:

flake8 --benchmark dir/

这个 不能 在配置文件中指定。

--bug-report

Go back to index

为Flake8生成完整错误报告所需的信息。这将很好地打印一个JSON blob,该blob应该被复制并粘贴到Flake8的bug报告中。

命令行用法:

flake8 --bug-report

输出应大致如下所示:

{
  "dependencies": [
    {
      "dependency": "setuptools",
      "version": "25.1.1"
    }
  ],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "2.7.12",
    "system": "Darwin"
  },
  "plugins": [
    {
      "plugin": "mccabe",
      "version": "0.5.1"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.0.0"
    },
    {
      "plugin": "pyflakes",
      "version": "1.2.3"
    }
  ],
  "version": "3.1.0.dev0"
}

这个 不能 在配置文件中指定。

--max-complexity=<n>

Go back to index

为代码块设置允许的最大McCabe复杂度值。

此选项由 mccabe 依赖关系 Flake8 插件。

命令行用法:

flake8 --max-complexity 15 dir/

这个 can 在配置文件中指定。

配置文件用法示例:

max-complexity = 15