semgrep: Add rule to specify tick kwarg on time_machine.travel() calls.

Letting the clock tick without a reason introduces the
possibility of nondeterministic test failures depending on the execution
time. The default value when not specified is tick=True, which makes it
easy to miss.
The rule doesn't prohibit setting tick=True, as perhaps there will be
tests wanting to use that feature on purpose, but such a test should
explicitly set it to make the intent clear.
This commit is contained in:
Mateusz Mandera 2023-09-29 17:03:18 +02:00 committed by Tim Abbott
parent 11390b70be
commit 0e4532f8e7
1 changed files with 9 additions and 0 deletions

View File

@ -17,6 +17,15 @@ rules:
include: include:
- zerver/views/ - zerver/views/
- id: time-machine-travel-specify-tick
patterns:
- pattern: time_machine.travel(...)
- pattern-not: time_machine.travel(..., tick=..., ...)
message: |
Specify tick kwarg value for time_machine.travel(). Most cases will want to use False.
languages: [python]
severity: ERROR
- id: limit-message-filter - id: limit-message-filter
patterns: patterns:
- pattern: Message.objects.filter(...) - pattern: Message.objects.filter(...)