flake8-noqa


Nameflake8-noqa JSON
Version 1.4.0 PyPI version JSON
download
home_page
SummaryFlake8 noqa comment validation
upload_time2024-01-07 22:35:50
maintainer
docs_urlNone
author
requires_python>=3.7
licenseGNU Lesser General Public License v3
keywords flake8 noqa
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [flake8-noqa](https://github.com/plinss/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`,
`# noqa : F841`,
and `# noqa:  F841`
will be interpreted as `# noqa`
and may, as a result,
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 as needed.
Alternatively, if you have a comment that this plugin thinks is a
`# noqa` with codes,
but isn't,
e.g. `# noqa : X100 is not a code`,
you can make the comment look less like a proper `# noqa` comment.
e.g. `# noqa - X100 is not a code`
(flake8 will interpret both of those as `# noqa`).

Usage Note:
When determining if violations have matched a `# noqa` comment,
this plugin requires flake8 to have been made aware of the violations
that would otherwise apply.
Some plugins do their own processing of `# noqa` comments 
and stop sending violation reports to flake8 when they see a `# noqa` comment.
A plugin doing so will cause this plugin to stop seeing the violation,
and it may report the lack of a violation or matching code.
When you then remove the `# noqa` comment or violation code, 
the other plugin will resume sending the violation,
prompting you to restore the `# noqa` comment or code.

The best fix for this situation is to try to get the offending plugin
to stop respecting `# noqa` comments.
A plugin doing so is considered an anti-pattern,
and it's best to allow flake8 to determine if violations should be 
surfaced to the user or not.
The offending plugin may have an option to control this behavior
(note the flake8 `--disable-noqa` option will disable *all* noqa comments,
so is not a suitable fix for this situation).
If the plugin does not have an option to control its `# noqa` behavior, 
the best course of action may be to contact the maintainers of 
the plugin via the appropriate issue reporting system.

If the plugin is unmaintained,
or the maintainers decline to address the issue for whatever reason,
feel free to file an issue on this plugin
to see if a work-around can be established.


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

`noqa-no-include-name`
: Do not include plugin name in messages (default setting)

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 not have a space before the colon, e.g. "# noqa: X000"' |
| NQA004 | "<code># noqa:&nbsp;&nbsp;X000</code>" must have at most one space before the codes, e.g. "`# noqa: X000`" |
| NQA005 | "`# noqa: X000, X000`" has duplicate codes, remove X000 |
| NQA011 | "`#flake8: noqa`" must have a single space after the hash, e.g. "`# flake8: noqa`" |
| NQA012 | "`# flake8 noqa`" must have a colon or equals, e.g. "`# flake8: noqa`" |
| NQA013 | "`# flake8 : noqa`" must not have a space before the colon, e.g. "# flake8: noqa" |
| NQA101 | "`# noqa`" has no violations |
| NQA102 | "`# noqa: X000`" has no matching violations |
| NQA103 | "`# noqa: X000, X001`" has unmatched code(s), remove X001 |
| NQA104 | "`# noqa`" must have codes, e.g. "`# noqa: X000`" (enable via `noqa-require-code`) |


Examples
--------

```
#flake8 noqa   <-- ignored (NQA011)
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:  E226  <-- treated as a blanket noqa (NQA004)
x = 1+2 # noqa: X101, E261 <-- unmatched code (NQA103)
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "flake8-noqa",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "flake8,noqa",
    "author": "",
    "author_email": "Peter Linss <pypi@linss.com>",
    "download_url": "https://files.pythonhosted.org/packages/71/d0/88b930e9da2f333c71474a2d8207954178d71724a6673a111d9117aff1c6/flake8-noqa-1.4.0.tar.gz",
    "platform": null,
    "description": "[flake8-noqa](https://github.com/plinss/flake8-noqa)\n==========\n\nflake8 plugin to validate `# noqa` comments.\n\nflake8 is very particular about formatting of `# noqa` comments.\nIf your `# noqa` isn't exactly what flake8 expects,\nit can easily cause your `# noqa` comment to be ignored.\n\nHowever, forgetting a colon or adding an extra space in the wrong place\nwill turn a strict `# noqa: <code>` comment\ninto a blanket `# noqa` comment,\nwhich is likely not what you intended.\nFor example:\n`# noqa F841`,\n`# noqa : F841`,\nand `# noqa:  F841`\nwill be interpreted as `# noqa`\nand may, as a result,\nhide other errors you care about.\n\nThis plugin looks for noqa comments\nthat do not match the proper formatting\nso your `# noqa` comments work and do only what you expect them to.\n\nOptionally, it can also enforce usage of codes with all `# noqa` comments.\n\nIn addition, this plugin looks for `# noqa` comments that are unnecessary\nbecause either there are no matching violations on the line\nor they contain codes that do not match existing violations.\n\nErrors reported by this module cannot be prevented via `# noqa` comments,\notherwise you'd never see many of the errors it produces.\nUse `ignore`, `extend-ignore`, or `per-file-ignores` to ignore them as needed.\nAlternatively, if you have a comment that this plugin thinks is a\n`# noqa` with codes,\nbut isn't,\ne.g. `# noqa : X100 is not a code`,\nyou can make the comment look less like a proper `# noqa` comment.\ne.g. `# noqa - X100 is not a code`\n(flake8 will interpret both of those as `# noqa`).\n\nUsage Note:\nWhen determining if violations have matched a `# noqa` comment,\nthis plugin requires flake8 to have been made aware of the violations\nthat would otherwise apply.\nSome plugins do their own processing of `# noqa` comments \nand stop sending violation reports to flake8 when they see a `# noqa` comment.\nA plugin doing so will cause this plugin to stop seeing the violation,\nand it may report the lack of a violation or matching code.\nWhen you then remove the `# noqa` comment or violation code, \nthe other plugin will resume sending the violation,\nprompting you to restore the `# noqa` comment or code.\n\nThe best fix for this situation is to try to get the offending plugin\nto stop respecting `# noqa` comments.\nA plugin doing so is considered an anti-pattern,\nand it's best to allow flake8 to determine if violations should be \nsurfaced to the user or not.\nThe offending plugin may have an option to control this behavior\n(note the flake8 `--disable-noqa` option will disable *all* noqa comments,\nso is not a suitable fix for this situation).\nIf the plugin does not have an option to control its `# noqa` behavior, \nthe best course of action may be to contact the maintainers of \nthe plugin via the appropriate issue reporting system.\n\nIf the plugin is unmaintained,\nor the maintainers decline to address the issue for whatever reason,\nfeel free to file an issue on this plugin\nto see if a work-around can be established.\n\n\nInstallation\n------------\n\nStandard python package installation:\n\n    pip install flake8-noqa\n\n\nOptions\n-------\n`noqa-require-code`\n: Require code(s) to be included in  `# noqa` comments\n\n`noqa-no-require-code`\n: Do not require code(s) in `# noqa` comments (default setting)\n\n`noqa-include-name`\n: Include plugin name in messages\n\n`noqa-no-include-name`\n: Do not include plugin name in messages (default setting)\n\nAll options may be specified on the command line with a `--` prefix,\nor can be placed in your flake8 config file.\n\n\nError Codes\n-----------\n\n| Code   | Message |\n|--------|---------|\n| NQA001 | \"`#noqa`\" must have a single space after the hash, e.g. \"`# noqa`\" |\n| NQA002 | \"`# noqa X000`\" must have a colon, e.g. \"`# noqa: X000`\" |\n| NQA003 | \"`# noqa : X000`\" must not have a space before the colon, e.g. \"# noqa: X000\"' |\n| NQA004 | \"<code># noqa:&nbsp;&nbsp;X000</code>\" must have at most one space before the codes, e.g. \"`# noqa: X000`\" |\n| NQA005 | \"`# noqa: X000, X000`\" has duplicate codes, remove X000 |\n| NQA011 | \"`#flake8: noqa`\" must have a single space after the hash, e.g. \"`# flake8: noqa`\" |\n| NQA012 | \"`# flake8 noqa`\" must have a colon or equals, e.g. \"`# flake8: noqa`\" |\n| NQA013 | \"`# flake8 : noqa`\" must not have a space before the colon, e.g. \"# flake8: noqa\" |\n| NQA101 | \"`# noqa`\" has no violations |\n| NQA102 | \"`# noqa: X000`\" has no matching violations |\n| NQA103 | \"`# noqa: X000, X001`\" has unmatched code(s), remove X001 |\n| NQA104 | \"`# noqa`\" must have codes, e.g. \"`# noqa: X000`\" (enable via `noqa-require-code`) |\n\n\nExamples\n--------\n\n```\n#flake8 noqa   <-- ignored (NQA011)\nx = 1+2  #noqa  <-- ignored (NQA001)\nx = 1+2  # noqa E226  <-- treated as a blanket noqa (NQA002)\nx = 1+2  # noqa : E226  <-- treated as a blanket noqa (NQA003)\nx = 1+2  # noqa:  E226  <-- treated as a blanket noqa (NQA004)\nx = 1+2 # noqa: X101, E261 <-- unmatched code (NQA103)\n```\n",
    "bugtrack_url": null,
    "license": "GNU Lesser General Public License v3",
    "summary": "Flake8 noqa comment validation",
    "version": "1.4.0",
    "project_urls": {
        "homepage": "https://github.com/plinss/flake8-noqa"
    },
    "split_keywords": [
        "flake8",
        "noqa"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01ec0eab800b28f3c2d1eeae2561eda4962ca5291e97668728405f9fddfdc768",
                "md5": "83beff32c0e6957531d60a6372ae30f4",
                "sha256": "4465e16a19be433980f6f563d05540e2e54797eb11facb9feb50fed60624dc45"
            },
            "downloads": -1,
            "filename": "flake8_noqa-1.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "83beff32c0e6957531d60a6372ae30f4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 24819,
            "upload_time": "2024-01-07T22:35:48",
            "upload_time_iso_8601": "2024-01-07T22:35:48.805286Z",
            "url": "https://files.pythonhosted.org/packages/01/ec/0eab800b28f3c2d1eeae2561eda4962ca5291e97668728405f9fddfdc768/flake8_noqa-1.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "71d088b930e9da2f333c71474a2d8207954178d71724a6673a111d9117aff1c6",
                "md5": "fb4ef6188987489a35a4c619f25e811d",
                "sha256": "771765ab27d1efd157528379acd15131147f9ae578a72d17fb432ca197881243"
            },
            "downloads": -1,
            "filename": "flake8-noqa-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fb4ef6188987489a35a4c619f25e811d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 27077,
            "upload_time": "2024-01-07T22:35:50",
            "upload_time_iso_8601": "2024-01-07T22:35:50.584038Z",
            "url": "https://files.pythonhosted.org/packages/71/d0/88b930e9da2f333c71474a2d8207954178d71724a6673a111d9117aff1c6/flake8-noqa-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-07 22:35:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "plinss",
    "github_project": "flake8-noqa",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "flake8-noqa"
}
        
Elapsed time: 0.17231s