mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:21 +00:00
[eradicate
] ignore # language=
in commented-out-code rule (ERA001) (#14069)
## Summary The `commented-out-code` rule (ERA001) from `eradicate` is currently flagging a very common idiom that marks Python strings as another language, to help with syntax highlighting:  This PR adds this idiom to the list of allowed exceptions to the rule. ## Test Plan I've added some additional test cases.
This commit is contained in:
parent
2b0cdd2338
commit
2b73a1c039
1 changed files with 18 additions and 1 deletions
|
@ -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-zA-Z](?: ?[-_.a-zA-Z0-9]+)+(?:\s+prefix=\S+)?(?:\s+suffix=\S+)?|(?:en)?coding[:=][ \t]*([-_.a-zA-Z0-9]+))",
|
||||
).unwrap()
|
||||
});
|
||||
|
||||
|
@ -297,6 +297,23 @@ 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=HTML prefix=<body> suffix=</body>",
|
||||
&[]
|
||||
));
|
||||
assert!(!comment_contains_code(
|
||||
"# language=ecma script level 4",
|
||||
&[]
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comment_contains_todo() {
|
||||
let task_tags = TASK_TAGS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue