Skip to content

Commit

Permalink
[eradicate] ignore # language= in commented-out-code rule (ERA001)
Browse files Browse the repository at this point in the history
Fixes one common case cited on #6019
  • Loading branch information
fabiob committed Nov 3, 2024
1 parent 2b0cdd2 commit 0d9abfe
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/ruff_linter/src/rules/eradicate/detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static CODE_INDICATORS: LazyLock<AhoCorasick> = LazyLock::new(|| {

static ALLOWLIST_REGEX: LazyLock<Regex> = LazyLock::new(|| {
Regex::new(
r"^(?i)(?:pylint|pyright|noqa|nosec|region|endregion|type:\s*ignore|fmt:\s*(on|off)|isort:\s*(on|off|skip|skip_file|split|dont-add-imports(:\s*\[.*?])?)|mypy:|SPDX-License-Identifier:|(?:en)?coding[:=][ \t]*([-_.a-zA-Z0-9]+))",
r"^(?i)(?:pylint|pyright|noqa|nosec|region|endregion|type:\s*ignore|fmt:\s*(on|off)|isort:\s*(on|off|skip|skip_file|split|dont-add-imports(:\s*\[.*?])?)|mypy:|SPDX-License-Identifier:|language=[a-z](?: ?[-_.a-z0-9]+)+|(?:en)?coding[:=][ \t]*([-_.a-zA-Z0-9]+))",
).unwrap()
});

Expand Down Expand Up @@ -297,6 +297,19 @@ mod tests {
));
}

#[test]
fn comment_contains_language_injection() {
assert!(comment_contains_code("# language=123", &[]));
assert!(comment_contains_code("# language=\"pt\"", &[]));
assert!(comment_contains_code("# language='en'", &[]));

assert!(!comment_contains_code("# language=xml", &[]));
assert!(!comment_contains_code(
"# language=ecma script level 4",
&[]
));
}

#[test]
fn comment_contains_todo() {
let task_tags = TASK_TAGS
Expand Down

0 comments on commit 0d9abfe

Please sign in to comment.