feat(tests): Update S015 rule to prevent hardcoding future years#110738
Merged
feat(tests): Update S015 rule to prevent hardcoding future years#110738
Conversation
…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.
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Unused
yearparameter in_s015_msgfunction- Removed the unused year parameter from _s015_msg function definition and updated all call sites to not pass the argument.
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:
NicoHinderling
approved these changes
Mar 16, 2026
Member
Author
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.