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

Bad identification of unused noqa statements (RUF100) #14320

Closed
jankatins opened this issue Nov 13, 2024 · 1 comment
Closed

Bad identification of unused noqa statements (RUF100) #14320

jankatins opened this issue Nov 13, 2024 · 1 comment

Comments

@jankatins
Copy link
Contributor

The following file has two errors, one wrong:

"""Test."""

class Whatever:
    """A class."
    def __init__(self, password: str) -> None:
        """A class init."""
        self.password = password

Whatever(password="test_password")
Whatever(password="test_password")  # noqa: S106
Whatever(password="test_password")  # noqa: S106 Possible hardcoded password
λ  ruff check --select=ALL utils/__init__.py
utils/__init__.py:9:10: S106 Possible hardcoded password assigned to argument: "password"
   |
 7 |         self.password = password
 8 | 
 9 | Whatever(password="test_password")
   |          ^^^^^^^^^^^^^^^^^^^^^^^^ S106
10 | Whatever(password="test_password")  # noqa: S106
11 | Whatever(password="test_password")  # noqa: S106 Possible hardcoded password
   |

utils/__init__.py:11:37: RUF100 [*] Unused `noqa` directive (unknown: `Possible`)
   |
 9 | Whatever(password="test_password")
10 | Whatever(password="test_password")  # noqa: S106
11 | Whatever(password="test_password")  # noqa: S106 Possible hardcoded password
   |                                     ^^^^^^^^^^^^^^^^^^^^^ RUF100
   |
   = help: Remove unused `noqa` directive

Found 2 errors.
[*] 1 fixable with the `--fix` option.

The S106 is correct, but the RUF100 tells me that the noqa statement is wrong. And If I fix it via adding --fix to the ruff call, the last line in the file is shortened to

Whatever(password="test_password")  # noqa: S106 hardcoded password

and now it's not anymore complained about:

 λ  ruff check --select=ALL utils/__init__.py --fix
utils/__init__.py:9:10: S106 Possible hardcoded password assigned to argument: "password"
   |
 7 |         self.password = password
 8 | 
 9 | Whatever(password="test_password")
   |          ^^^^^^^^^^^^^^^^^^^^^^^^ S106
10 | Whatever(password="test_password")  # noqa: S106
11 | Whatever(password="test_password")  # noqa: S106 hardcoded password
   |

Found 1 error.

(Note: this also happens with other noqa statements, not only with S106)

 λ  ruff --version
ruff 0.7.3

(It didn't happen with older ruff versions, we just got a few renovate PRs which errors because of this upgrade)

@jankatins
Copy link
Contributor Author

Damn, didn't look int he closed section: this is #14228 and already fixed.

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

No branches or pull requests

1 participant