Skip to main content

Flake8 noqa Plugin

Project description

flake8-noqa

flake8 plugin to validate # noqa comments.

flake8 is very particular about formatting of # noqa comments. If your # noqa isn't exactly what flake8 expects, it can easily cause your # noqa comment to be ignored.

However, forgetting a colon or adding an extra space in the wrong place will turn a strict # noqa: <code> comment into a blanket # noqa comment, which is likely not what you intended. For example: # noqa F841 will be interpreted as # noqa and may hide other errors you care about.

This plugin looks for noqa comments that do not match the proper formatting so your # noqa comments work and do only what you expect them to.

Optionally, it can also enforce usage of codes with all # noqa comments.

In addition, this plugin looks for # noqa comments that are unnecessary because either there are no matching violations on the line or they contain codes that do not match existing violations.

Errors reported by this module cannot be prevented via # noqa comments, otherwise you'd never see many of the errors it produces. Use ignore, extend-ignore, or per-file-ignores to ignore them.

Installation

Standard python package installation:

pip install flake8-noqa

Options

noqa-require-code : Require code(s) to be included in # noqa comments

noqa-no-require-code : Do not require code(s) in # noqa comments (default setting)

noqa-include-name : Include plugin name in messages (default setting)

noqa-no-include-name : Remove plugin name from messages

All options may be specified on the command line with a -- prefix, or can be placed in your flake8 config file.

Error Codes

Code Message
NQA001 "#noqa" must have a single space after the hash, e.g. "# noqa"
NQA002 "# noqa X000" must have a colon, e.g. "# noqa: X000"
NQA003 "# noqa: X000" must have at most one space before the codes, e.g. "# noqa: X000"
NQA004 "# noqa" comment must have one or more codes, e.g. "# noqa: X000" (enable via noqa-require-code)
NQA005 "# noqa: X000, X000" has duplicate codes, remove X000
NQA010 "#flake8: noqa" must have a single space after the hash, e.g. "# flake8: noqa"
NQA011 "# flake8 noqa" must have a colon or equals, e.g. "# flake8: noqa"
NQA101 No violations, remove "# noqa"
NQA102 No matching violations, remove "# noqa: X000"
NQA103 Unused code(s) present in "# noqa: X000, X001", remove X001

Examples

#flake8 noqa   <-- ignored (NQA010)
x = 1+2  #noqa  <-- ignored (NQA001)
x = 1+2  # noqa E226  <-- treated as a blanket noqa (NQA002)
x = 1+2  # noqa:  E226  <-- treated as a blanket noqa (NQA003)
x = 1+2 # noqa: X101, E261 <-- unused code (NQA103)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

flake8_noqa-1.0.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file flake8_noqa-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: flake8_noqa-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.7

File hashes

Hashes for flake8_noqa-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34bfa462942eaf15a5225c4753abf8f52960e29b8a5ef2fab6ba49404eaa0c98
MD5 23fb7b6a381050f16613414b6bc93f37
BLAKE2b-256 2d518d9d74814f5f27df90a603d3b724daa0f4770ca79a9a383773b3d71f150e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page