Skip to content

feat(tests): Update S015 rule to prevent hardcoding future years#110738

Merged
armenzg merged 2 commits intomasterfrom
extend_pre_commit_check
Mar 16, 2026
Merged

feat(tests): Update S015 rule to prevent hardcoding future years#110738
armenzg merged 2 commits intomasterfrom
extend_pre_commit_check

Conversation

@armenzg
Copy link
Member

@armenzg armenzg commented Mar 16, 2026

Modified the S015 linting rule to flag any hardcoded datetime values with the current or future UTC year at module/class scope and in freeze_time(...). Updated related tests to reflect this change, ensuring that only older years are allowed in specific contexts. This enhances the accuracy of date-stable tests and prevents potential issues with Snuba retention.

…UTC year in tests

Modified the S015 linting rule to flag any hardcoded datetime values with the current or future UTC year at module/class scope and in `freeze_time(...)`. Updated related tests to reflect this change, ensuring that only older years are allowed in specific contexts. This enhances the accuracy of date-stable tests and prevents potential issues with Snuba retention.
@armenzg armenzg self-assigned this Mar 16, 2026
@armenzg armenzg marked this pull request as ready for review March 16, 2026 14:50
@armenzg armenzg requested a review from a team as a code owner March 16, 2026 14:50
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Mar 16, 2026
Copy link
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Unused year parameter in _s015_msg function
    • Removed the unused year parameter from _s015_msg function definition and updated all call sites to not pass the argument.

Create PR

Or push these changes by commenting:

@cursor push 73cd4e3565
Preview (73cd4e3565)
diff --git a/tests/tools/test_flake8_plugin.py b/tests/tools/test_flake8_plugin.py
--- a/tests/tools/test_flake8_plugin.py
+++ b/tests/tools/test_flake8_plugin.py
@@ -245,7 +245,7 @@
 
 def test_S015_current_or_future_year() -> None:
     cy = datetime.now(timezone.utc).year
-    msg = _s015_msg(cy)
+    msg = _s015_msg()
     # Current year at module scope is flagged
     assert _run(
         f"from datetime import datetime, timezone\n\n"

diff --git a/tools/flake8_plugin.py b/tools/flake8_plugin.py
--- a/tools/flake8_plugin.py
+++ b/tools/flake8_plugin.py
@@ -44,7 +44,7 @@
 
 # --- S015: do not hardcode current or future UTC year as test "now" ---
 # Flag year >= current UTC year at lint time. Module/class scope + freeze_time(datetime(...)).
-def _s015_msg(year: int) -> str:
+def _s015_msg() -> str:
     return (
         "S015 Do not hardcode datetime with current or future UTC year at module/class "
         "scope or in freeze_time(...); use before_now(...), now-timedelta, or an older fixed year"
@@ -248,7 +248,7 @@
 
     def run(self) -> Generator[tuple[int, int, str, type[Any]]]:
         cy = datetime.now(timezone.utc).year
-        visitor = SentryVisitor(self.filename, cy, _s015_msg(cy))
+        visitor = SentryVisitor(self.filename, cy, _s015_msg())
         visitor.visit(self.tree)
 
         for e in visitor.errors:

@armenzg
Copy link
Member Author

armenzg commented Mar 16, 2026

@cursor push 73cd4e3

The _s015_msg function no longer uses the year parameter in its
message string, so the parameter has been removed from both the
function definition and all call sites.

Applied via @cursor push command
@armenzg armenzg merged commit d38e4d5 into master Mar 16, 2026
77 checks passed
@armenzg armenzg deleted the extend_pre_commit_check branch March 16, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants