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:
Lukas Mayrhofer 2023-06-22 22:53:58 +02:00 committed by GitHub
parent 38e618cd18
commit 4a81cfc51a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 38 deletions

View file

@ -1,6 +1,12 @@
# T002 - accepted
# 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
# TODO: this has no author
# FIXME: neither does this

View file

@ -67,7 +67,7 @@ pub struct MissingTodoAuthor;
impl Violation for MissingTodoAuthor {
#[derive_message_formats]
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([
r#"^#\s*(http|https)://.*"#, // issue link
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()
});
@ -339,8 +339,7 @@ fn directive_errors(
}
}
/// Checks for "static" errors in the comment: missing colon, missing author, etc. This function
/// modifies `diagnostics` in-place.
/// Checks for "static" errors in the comment: missing colon, missing author, etc.
fn static_errors(
diagnostics: &mut Vec<Diagnostic>,
comment: &str,
@ -358,6 +357,15 @@ fn static_errors(
} else {
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 {
// TD002
diagnostics.push(Diagnostic::new(MissingTodoAuthor, directive.range));

View file

@ -1,40 +1,40 @@
---
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
4 | # T002 - errors
5 | # TODO: this has no author
9 | # TODO @mayrholu and more: this has an author
10 | # T002 - errors
11 | # TODO: this has no author
| ^^^^ TD002
6 | # FIXME: neither does this
7 | # TODO : and neither does this
12 | # FIXME: 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
5 | # TODO: this has no author
6 | # FIXME: neither does this
10 | # T002 - errors
11 | # TODO: this has no author
12 | # FIXME: neither does this
| ^^^^^ TD002
7 | # TODO : and neither does this
8 | # foo # TODO: this doesn't either
13 | # TODO : and neither does this
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
6 | # FIXME: neither does this
7 | # TODO : and neither does this
11 | # TODO: this has no author
12 | # FIXME: neither does this
13 | # TODO : and neither does this
| ^^^^ 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
7 | # TODO : and neither does this
8 | # foo # TODO: this doesn't either
12 | # FIXME: neither does this
13 | # TODO : and neither does this
14 | # foo # TODO: this doesn't either
| ^^^^ TD002
|