From f40c578ffbbe124ac61e45aaf3bcbdfd9dd6d84c Mon Sep 17 00:00:00 2001 From: Jason K Hall <106277735+Jkhall81@users.noreply.github.com> Date: Fri, 9 Jan 2026 10:01:09 -0700 Subject: [PATCH] [`ruff`] document `RUF100` trailing comment fix behavior (#22479) ## Summary Ruff's `--fix` for `RUF100` can inadvertently remove trailing comments (e.g., `pylint` or `mypy` suppressions) by interpreting them as descriptions. This PR adds a "Conflict with other linters" section to the rule documentation to clarify this behavior and provide the double-hash (`# noqa # pylint`) workaround. ## Fixes Fixes #20762 --- .../src/rules/ruff/rules/unused_noqa.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs index d6e4ce94d9..8b8f59d7ba 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs @@ -52,6 +52,25 @@ impl UnusedNOQAKind { /// foo.bar() /// ``` /// +/// ## Conflict with other linters +/// When using `RUF100` with the `--fix` option, Ruff may remove trailing comments +/// that follow a `# noqa` directive on the same line, as it interprets the +/// remainder of the line as a description for the suppression. +/// +/// To prevent Ruff from removing suppressions for other tools (like `pylint` +/// or `mypy`), separate them with a second `#` character: +/// +/// ```python +/// # Bad: Ruff --fix will remove the pylint comment +/// def visit_ImportFrom(self, node): # noqa: N802, pylint: disable=invalid-name +/// pass +/// +/// +/// # Good: Ruff will preserve the pylint comment +/// def visit_ImportFrom(self, node): # noqa: N802 # pylint: disable=invalid-name +/// pass +/// ``` +/// /// ## Options /// - `lint.external` ///