mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
Allow @Author
format for "Missing Author" rule in flake8-todos
(#4903)
## Summary The TD-002 rule "Missing Author" was updated to allow another format using "@". This reflects the current 0.3.0 version of flake8-todos.
This commit is contained in:
parent
38e618cd18
commit
4a81cfc51a
3 changed files with 52 additions and 38 deletions
|
@ -1,6 +1,12 @@
|
||||||
# T002 - accepted
|
# T002 - accepted
|
||||||
# TODO (evanrittenhouse): this has an author
|
# TODO (evanrittenhouse): this has an author
|
||||||
# TODO(evanrittenhouse): this also has an author
|
# TODO(evanrittenhouse): this has an author
|
||||||
|
# TODO (evanrittenhouse) and more: this has an author
|
||||||
|
# TODO(evanrittenhouse) and more: this has an author
|
||||||
|
# TODO@mayrholu: this has an author
|
||||||
|
# TODO @mayrholu: this has an author
|
||||||
|
# TODO@mayrholu and more: this has an author
|
||||||
|
# TODO @mayrholu and more: this has an author
|
||||||
# T002 - errors
|
# T002 - errors
|
||||||
# TODO: this has no author
|
# TODO: this has no author
|
||||||
# FIXME: neither does this
|
# FIXME: neither does this
|
||||||
|
|
|
@ -67,7 +67,7 @@ pub struct MissingTodoAuthor;
|
||||||
impl Violation for MissingTodoAuthor {
|
impl Violation for MissingTodoAuthor {
|
||||||
#[derive_message_formats]
|
#[derive_message_formats]
|
||||||
fn message(&self) -> String {
|
fn message(&self) -> String {
|
||||||
format!("Missing author in TODO; try: `# TODO(<author_name>): ...`")
|
format!("Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...`")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ static ISSUE_LINK_REGEX_SET: Lazy<RegexSet> = Lazy::new(|| {
|
||||||
RegexSet::new([
|
RegexSet::new([
|
||||||
r#"^#\s*(http|https)://.*"#, // issue link
|
r#"^#\s*(http|https)://.*"#, // issue link
|
||||||
r#"^#\s*\d+$"#, // issue code - like "003"
|
r#"^#\s*\d+$"#, // issue code - like "003"
|
||||||
r#"^#\s*[A-Z]{1,6}\-?\d+$"#, // issue code - like "TD003" or "TD-003"
|
r#"^#\s*[A-Z]{1,6}\-?\d+$"#, // issue code - like "TD003"
|
||||||
])
|
])
|
||||||
.unwrap()
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
@ -339,8 +339,7 @@ fn directive_errors(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks for "static" errors in the comment: missing colon, missing author, etc. This function
|
/// Checks for "static" errors in the comment: missing colon, missing author, etc.
|
||||||
/// modifies `diagnostics` in-place.
|
|
||||||
fn static_errors(
|
fn static_errors(
|
||||||
diagnostics: &mut Vec<Diagnostic>,
|
diagnostics: &mut Vec<Diagnostic>,
|
||||||
comment: &str,
|
comment: &str,
|
||||||
|
@ -358,6 +357,15 @@ fn static_errors(
|
||||||
} else {
|
} else {
|
||||||
trimmed.text_len()
|
trimmed.text_len()
|
||||||
}
|
}
|
||||||
|
} else if trimmed.starts_with('@') {
|
||||||
|
if let Some(end_index) = trimmed.find(|c: char| c.is_whitespace() || c == ':') {
|
||||||
|
TextSize::try_from(end_index).unwrap()
|
||||||
|
} else {
|
||||||
|
// TD002
|
||||||
|
diagnostics.push(Diagnostic::new(MissingTodoAuthor, directive.range));
|
||||||
|
|
||||||
|
TextSize::new(0)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// TD002
|
// TD002
|
||||||
diagnostics.push(Diagnostic::new(MissingTodoAuthor, directive.range));
|
diagnostics.push(Diagnostic::new(MissingTodoAuthor, directive.range));
|
||||||
|
|
|
@ -1,41 +1,41 @@
|
||||||
---
|
---
|
||||||
source: crates/ruff/src/rules/flake8_todos/mod.rs
|
source: crates/ruff/src/rules/flake8_todos/mod.rs
|
||||||
---
|
---
|
||||||
TD002.py:5:3: TD002 Missing author in TODO; try: `# TODO(<author_name>): ...`
|
TD002.py:11:3: TD002 Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...`
|
||||||
|
|
|
|
||||||
3 | # TODO(evanrittenhouse): this also has an author
|
9 | # TODO @mayrholu and more: this has an author
|
||||||
4 | # T002 - errors
|
10 | # T002 - errors
|
||||||
5 | # TODO: this has no author
|
11 | # TODO: this has no author
|
||||||
| ^^^^ TD002
|
| ^^^^ TD002
|
||||||
6 | # FIXME: neither does this
|
12 | # FIXME: neither does this
|
||||||
7 | # TODO : and neither does this
|
13 | # TODO : and neither does this
|
||||||
|
|
|
|
||||||
|
|
||||||
TD002.py:6:3: TD002 Missing author in TODO; try: `# TODO(<author_name>): ...`
|
TD002.py:12:3: TD002 Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...`
|
||||||
|
|
|
|
||||||
4 | # T002 - errors
|
10 | # T002 - errors
|
||||||
5 | # TODO: this has no author
|
11 | # TODO: this has no author
|
||||||
6 | # FIXME: neither does this
|
12 | # FIXME: neither does this
|
||||||
| ^^^^^ TD002
|
| ^^^^^ TD002
|
||||||
7 | # TODO : and neither does this
|
13 | # TODO : and neither does this
|
||||||
8 | # foo # TODO: this doesn't either
|
14 | # foo # TODO: this doesn't either
|
||||||
|
|
|
|
||||||
|
|
||||||
TD002.py:7:3: TD002 Missing author in TODO; try: `# TODO(<author_name>): ...`
|
TD002.py:13:3: TD002 Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...`
|
||||||
|
|
|
|
||||||
5 | # TODO: this has no author
|
11 | # TODO: this has no author
|
||||||
6 | # FIXME: neither does this
|
12 | # FIXME: neither does this
|
||||||
7 | # TODO : and neither does this
|
13 | # TODO : and neither does this
|
||||||
| ^^^^ TD002
|
| ^^^^ TD002
|
||||||
8 | # foo # TODO: this doesn't either
|
14 | # foo # TODO: this doesn't either
|
||||||
|
|
|
|
||||||
|
|
||||||
TD002.py:8:9: TD002 Missing author in TODO; try: `# TODO(<author_name>): ...`
|
TD002.py:14:9: TD002 Missing author in TODO; try: `# TODO(<author_name>): ...` or `# TODO @<author_name>: ...`
|
||||||
|
|
|
|
||||||
6 | # FIXME: neither does this
|
12 | # FIXME: neither does this
|
||||||
7 | # TODO : and neither does this
|
13 | # TODO : and neither does this
|
||||||
8 | # foo # TODO: this doesn't either
|
14 | # foo # TODO: this doesn't either
|
||||||
| ^^^^ TD002
|
| ^^^^ TD002
|
||||||
|
|
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue