Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

semgrep: Treat ugettext_lazy like ugettext.

Anders Kaseorg0be17b6b0044
diff --git a/tools/semgrep.yml b/tools/semgrep.yml
index 8acd6b89fd3..a3b69d557be 100644
--- a/tools/semgrep.yml
+++ b/tools/semgrep.yml
@@ -72,9 +72,17 @@ rules:
pattern-either:
- pattern: django.utils.translation.ugettext(... .format(...))
- pattern: django.utils.translation.ugettext(f"...")
+ - pattern: django.utils.translation.ugettext_lazy(... .format(...))
+ - pattern: django.utils.translation.ugettext_lazy(f"...")
severity: ERROR
message: "Format strings after translation, not before"
+ - id: translated-format-lazy
+ languages: [python]
+ pattern: django.utils.translation.ugettext_lazy(...).format(...)
+ severity: ERROR
+ message: "Immediately formatting a lazily translated string destroys its laziness"
+
- id: mutable-default-type
languages: [python]
pattern-either:
@@ -116,6 +124,7 @@ rules:
pattern-either:
- pattern: '"..." % ...'
- pattern: django.utils.translation.ugettext(...) % ...
+ - pattern: django.utils.translation.ugettext_lazy(...) % ...
severity: ERROR
message: "Prefer f-strings or .format for string formatting"