Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better noqa interpretation #717

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Better noqa interpretation #717

wants to merge 1 commit into from

Conversation

sbrunner
Copy link
Member

@sbrunner sbrunner commented Jan 21, 2025

Description

  • To completely ignore a line the # noqa should be alone
  • To ignore a code we can use # noqa: <code> ad ruff do
  • To ignore a code from a certain source use # noqa: <source>.<code>, this will also create an error if the ignored is not used.

Alternative of #714

Related Issue

fix #715

Motivation and Context

  • Be compatible with Ruff
  • Have more control on message to be ignored
  • Be notified on used ignore

How Has This Been Tested?

Test added

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

@sbrunner sbrunner force-pushed the better-noqa branch 4 times, most recently from cb93607 to e04e7c3 Compare January 21, 2025 13:46
- To completely ignore a line the `# noqa` should be alone
- To ignore a code we can use `# noqa: <code>` ad ruff do
- To ignore a code from a certain source use `# noqa: <source>.<code>`,
  this will also create an error if the ignore is not used.
@sbrunner sbrunner marked this pull request as ready for review January 21, 2025 14:23
@carlio
Copy link
Member

carlio commented Jan 21, 2025

So as I see it, it'll maintain the same behaviour (<-- I use British spelling because I am, but I won't moan about the changes in the docs 😛) for the most part.

Tools with their own syntax will do what they used to do, #noqa is still a blanket "ignore this line".

There is new syntax which is prospector-specific of #noqa flake8.F345 or similar. Prospector I think should be nothing more than a convenience wrapper and shouldn't introduce its own stuff too much, but equally there are time when flake8 or bandit might not have a way to ignore only a single line or only a specific error, so this seems like a good and valid addition to me.

@Pierre-Sassoulas
Copy link
Collaborator

#noqa atool.F345 is not the obvious way atool would implement noqa of a specific message so I would use #noqa: F345 so prospector does not require specific change to be adopted from a codebase where the noqa are already here. There might be collision if errors from various tools are in the same namespace so multiple errors are noqa'ed (flake8 F345 / ruff F345 bandit F345), but I think it's probably okay. In the case of ruff/flake8 it's actually the same message re-implemented, and for bandit/(ruff/flake8) how often is this actually going to happen that there's both a collision in message name between tooling AND one error is mistakenly silenced because this line is rewritten after the noqa was added and those two errors happens on the same line ?

@sbrunner
Copy link
Member Author

@Pierre-Sassoulas what you say is probably true, but I think that having a test that the ignored is really use is an added value, And I can do it only I'm sure that I receive the message and with Ruff it's not the case.

If you still be against that, I will remove it :-)

@Pierre-Sassoulas
Copy link
Collaborator

It's possible to do both Ruff style or '# Noqa: atool: F408' style, so if you're going to use the atool: style it you might as well add it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Be able to ignore a specific error code on a specific line of code
3 participants