简体   繁体   English

如何同时在一行中抑制 pylint 和 Flake8 的警告

[英]How to suppress a warning in one line for pylint and Flake8 at the same time

I would like to ignore a specific line in static code analysis.我想忽略 static 代码分析中的特定行。

For Flake8, I'd use the syntax # noqa: F401 .对于 Flake8,我会使用语法# noqa: F401

For pylint, I'd use the syntax # pylint: disable=unused-import .对于 pylint,我会使用语法# pylint: disable=unused-import

As I am working on a code generation framework, I would like the code to support both linters.当我在开发代码生成框架时,我希望代码支持这两种 linter。 Is there a way to combine both directives such that both of them are correctly detected?有没有办法将这两个指令结合起来,以便正确检测到它们?

both of these combinations work for me:这两种组合都对我有用:

import os  # noqa: F401 # pylint:disable=unused-import
import sys  # pylint:disable=unused-import # noqa: F401

I was having similar issue.我有类似的问题。 Having used pylint initially, I had that directive first which caused errors.最初使用 pylint 后,我首先使用了导致错误的指令。 Reversing the order so that flake8 is first worked for me.颠倒顺序,以便 flake8 首先为我工作。

# noqa: 501  pylint: disable=unused-argument

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM