PyCQA / flake8

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.
https://flake8.pycqa.org
Other
3.45k stars 308 forks source link

Issue an error when there are unused --per-file-ignores rules #669

Closed asottile closed 3 years ago

asottile commented 3 years ago

In GitLab by @qxv0 on Jan 30, 2019, 06:44

Please provide the exact, unmodified output of flake8 --bug-report

flake8 --bug-report
{
  "dependencies": [
    {
      "dependency": "entrypoints",
      "version": "0.3"
    }
  ],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.7.2",
    "system": "Windows"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "ProxyChecker",
      "version": "0.0.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-comprehensions",
      "version": "1.4.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-docstrings",
      "version": "1.3.0, pydocstyle: 3.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-future-import",
      "version": "0.4.5"
    },
    {
      "is_local": false,
      "plugin": "flake8-mock",
      "version": "0.3"
    },
    {
      "is_local": false,
      "plugin": "flake8-no-u-prefixed-strings",
      "version": "0.2"
    },
    {
      "is_local": false,
      "plugin": "flake8-print",
      "version": "3.1.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-string-format",
      "version": "0.2.3"
    },
    {
      "is_local": false,
      "plugin": "flake8-tuple",
      "version": "0.2.13"
    },
    {
      "is_local": false,
      "plugin": "flake8_coding",
      "version": "1.3.1"
    },
    {
      "is_local": false,
      "plugin": "flake8_quotes",
      "version": "1.0.0"
    },
    {
      "is_local": false,
      "plugin": "hacking.core",
      "version": "0.0.1"
    },
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "naming",
      "version": "0.8.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.5.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.1.0"
    }
  ],
  "version": "3.7.1"
}

Please describe the problem or feature We have been using flake8-per-file-ignores plugin. With the recent release of flake8 provides a build-in --per-file-ignores option. But unlike the plugin the now built-in option won't complain if any of the ignored errors are not used anymore.

It's a useful feature because:

If an ignored error no longer occurs for a given file it will trigger an X100 error to make you progressively reduce the number of ignores as legacy code gets rewritten or removed. which helps in keeping the ignore rules clean an up-to-date.

asottile commented 3 years ago

In GitLab by @asottile on Jan 30, 2019, 08:36

Seems like a good idea, would happily take a patch for this feature.

There's a related issue as well that I've been meaning to work on: #352

asottile commented 3 years ago

In GitLab by @qxv0 on Jan 31, 2019, 24:41

changed title from Issue an error when there are unsed --per-file-ignores rules to Issue an error when there are un{+u+}sed --per-file-ignores rules

asottile commented 3 years ago

In GitLab by @asottile on Mar 24, 2020, 09:50

so unfortunately, due to the differences between the plugin I'm not sure this is possible. in the plugin, the per-file-ignores were filenames, but in flake8 they are filename patterns

this subtlety means that from a given invocation we can't know whether the rule applies or not

consider this example:

per-file-ignores =
    tests/*: E501

if we invoke flake8 tests/test1.py and it doesn't have E501 it shouldn't be an unused rule, but we would need to be able to find all things matching that glob to know if it's unused or not

asottile commented 3 years ago

In GitLab by @sigmavirus24 on Apr 9, 2020, 05:44

I agree @asottile. I think we can safely close this for now. There hasn't been much support of this since it was opened

asottile commented 3 years ago

In GitLab by @sigmavirus24 on Apr 9, 2020, 05:44

closed