From 0991625f26cf0ac09219919bfbd70cf5517c5021 Mon Sep 17 00:00:00 2001 From: Mike Bernard Date: Sat, 28 Dec 2024 19:59:04 -0500 Subject: [PATCH 1/2] TD003: increase max issue code length to 12 characters --- .../test/fixtures/flake8_todos/TD003.py | 9 +++ .../src/rules/flake8_todos/rules/todos.rs | 6 +- ...os__tests__missing-todo-link_TD003.py.snap | 63 +++++++++++-------- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_todos/TD003.py b/crates/ruff_linter/resources/test/fixtures/flake8_todos/TD003.py index 2f6b5e73fdbea..212edb8d07ea8 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_todos/TD003.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_todos/TD003.py @@ -5,6 +5,12 @@ # TODO: this comment has an issue # TDO-3870 +# TODO: the link has an issue code of the minimum length +# T-001 + +# TODO: the link has an issue code of the maximum length +# ABCDEFGHIJKL-001 + # TDO003 - errors # TODO: this comment has no # link after it @@ -29,3 +35,6 @@ def foo(x): # foo # TODO: no link! # TODO: here's a TODO on the last line with no link + +# TODO: the link has an issue code beyond the maximum length +# ABCDEFGHIJKLM-001 diff --git a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs index d21b423d723ae..2932502b0fdab 100644 --- a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs +++ b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs @@ -226,9 +226,9 @@ impl Violation for MissingSpaceAfterTodoColon { static ISSUE_LINK_REGEX_SET: LazyLock = LazyLock::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" + r"^#\s*(http|https)://.*", // issue link + r"^#\s*\d+$", // issue code - like "003" + r"^#\s*[A-Z]{1,12}\-?\d+$", // issue code - like "TD003" ]) .unwrap() }); diff --git a/crates/ruff_linter/src/rules/flake8_todos/snapshots/ruff_linter__rules__flake8_todos__tests__missing-todo-link_TD003.py.snap b/crates/ruff_linter/src/rules/flake8_todos/snapshots/ruff_linter__rules__flake8_todos__tests__missing-todo-link_TD003.py.snap index fb2932b140245..95584464d66d5 100644 --- a/crates/ruff_linter/src/rules/flake8_todos/snapshots/ruff_linter__rules__flake8_todos__tests__missing-todo-link_TD003.py.snap +++ b/crates/ruff_linter/src/rules/flake8_todos/snapshots/ruff_linter__rules__flake8_todos__tests__missing-todo-link_TD003.py.snap @@ -2,48 +2,59 @@ source: crates/ruff_linter/src/rules/flake8_todos/mod.rs snapshot_kind: text --- -TD003.py:9:3: TD003 Missing issue link on the line following this TODO +TD003.py:15:3: TD003 Missing issue link on the line following this TODO | - 8 | # TDO003 - errors - 9 | # TODO: this comment has no +14 | # TDO003 - errors +15 | # TODO: this comment has no | ^^^^ TD003 -10 | # link after it +16 | # link after it | -TD003.py:12:3: TD003 Missing issue link on the line following this TODO +TD003.py:18:3: TD003 Missing issue link on the line following this TODO | -10 | # link after it -11 | -12 | # TODO: here's a TODO with no link after it +16 | # link after it +17 | +18 | # TODO: here's a TODO with no link after it | ^^^^ TD003 -13 | def foo(x): -14 | return x +19 | def foo(x): +20 | return x | -TD003.py:25:3: TD003 Missing issue link on the line following this TODO +TD003.py:31:3: TD003 Missing issue link on the line following this TODO | -23 | # TDO-3870 -24 | -25 | # TODO: here's a TODO without an issue link +29 | # TDO-3870 +30 | +31 | # TODO: here's a TODO without an issue link | ^^^^ TD003 -26 | # TODO: followed by a new TODO with an issue link -27 | # TDO-3870 +32 | # TODO: followed by a new TODO with an issue link +33 | # TDO-3870 | -TD003.py:29:9: TD003 Missing issue link on the line following this TODO +TD003.py:35:9: TD003 Missing issue link on the line following this TODO | -27 | # TDO-3870 -28 | -29 | # foo # TODO: no link! +33 | # TDO-3870 +34 | +35 | # foo # TODO: no link! | ^^^^ TD003 -30 | -31 | # TODO: here's a TODO on the last line with no link +36 | +37 | # TODO: here's a TODO on the last line with no link | -TD003.py:31:3: TD003 Missing issue link on the line following this TODO +TD003.py:37:3: TD003 Missing issue link on the line following this TODO | -29 | # foo # TODO: no link! -30 | -31 | # TODO: here's a TODO on the last line with no link +35 | # foo # TODO: no link! +36 | +37 | # TODO: here's a TODO on the last line with no link + | ^^^^ TD003 +38 | +39 | # TODO: the link has an issue code beyond the maximum length + | + +TD003.py:39:3: TD003 Missing issue link on the line following this TODO + | +37 | # TODO: here's a TODO on the last line with no link +38 | +39 | # TODO: the link has an issue code beyond the maximum length | ^^^^ TD003 +40 | # ABCDEFGHIJKLM-001 | From ee51b526ccef6ad72c51e1559f65cb79f8cbc7c2 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 3 Jan 2025 10:34:53 +0100 Subject: [PATCH 2/2] Remove issue code length restriction --- .../resources/test/fixtures/flake8_todos/TD003.py | 7 ++----- .../ruff_linter/src/rules/flake8_todos/rules/todos.rs | 8 ++++---- ...ake8_todos__tests__missing-todo-link_TD003.py.snap | 11 ----------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_todos/TD003.py b/crates/ruff_linter/resources/test/fixtures/flake8_todos/TD003.py index 212edb8d07ea8..9746c27a0570e 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_todos/TD003.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_todos/TD003.py @@ -8,8 +8,8 @@ # TODO: the link has an issue code of the minimum length # T-001 -# TODO: the link has an issue code of the maximum length -# ABCDEFGHIJKL-001 +# TODO: the issue code can be arbitrarily long +# ABCDEFGHIJKLMNOPQRSTUVWXYZ-001 # TDO003 - errors # TODO: this comment has no @@ -35,6 +35,3 @@ def foo(x): # foo # TODO: no link! # TODO: here's a TODO on the last line with no link - -# TODO: the link has an issue code beyond the maximum length -# ABCDEFGHIJKLM-001 diff --git a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs index 2932502b0fdab..1a04543fe3f1c 100644 --- a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs +++ b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs @@ -91,7 +91,7 @@ impl Violation for MissingTodoAuthor { /// # TODO(charlie): this comment has a 3-digit issue code /// # 003 /// -/// # TODO(charlie): this comment has an issue code of (up to) 6 characters, then digits +/// # TODO(charlie): this comment has an issue code (matches the regex `[A-Z]+\-?\d+`) /// # SIXCHR-003 /// ``` #[derive(ViolationMetadata)] @@ -226,9 +226,9 @@ impl Violation for MissingSpaceAfterTodoColon { static ISSUE_LINK_REGEX_SET: LazyLock = LazyLock::new(|| { RegexSet::new([ - r"^#\s*(http|https)://.*", // issue link - r"^#\s*\d+$", // issue code - like "003" - r"^#\s*[A-Z]{1,12}\-?\d+$", // issue code - like "TD003" + r"^#\s*(http|https)://.*", // issue link + r"^#\s*\d+$", // issue code - like "003" + r"^#\s*[A-Z]+\-?\d+$", // issue code - like "TD003" ]) .unwrap() }); diff --git a/crates/ruff_linter/src/rules/flake8_todos/snapshots/ruff_linter__rules__flake8_todos__tests__missing-todo-link_TD003.py.snap b/crates/ruff_linter/src/rules/flake8_todos/snapshots/ruff_linter__rules__flake8_todos__tests__missing-todo-link_TD003.py.snap index 95584464d66d5..1b6f46ce5cdff 100644 --- a/crates/ruff_linter/src/rules/flake8_todos/snapshots/ruff_linter__rules__flake8_todos__tests__missing-todo-link_TD003.py.snap +++ b/crates/ruff_linter/src/rules/flake8_todos/snapshots/ruff_linter__rules__flake8_todos__tests__missing-todo-link_TD003.py.snap @@ -46,15 +46,4 @@ TD003.py:37:3: TD003 Missing issue link on the line following this TODO 36 | 37 | # TODO: here's a TODO on the last line with no link | ^^^^ TD003 -38 | -39 | # TODO: the link has an issue code beyond the maximum length - | - -TD003.py:39:3: TD003 Missing issue link on the line following this TODO - | -37 | # TODO: here's a TODO on the last line with no link -38 | -39 | # TODO: the link has an issue code beyond the maximum length - | ^^^^ TD003 -40 | # ABCDEFGHIJKLM-001 |