The same string literal is written several times in one file
What it finds
A message, key or path written out in several places has to be changed in all of them, and a typo in one copy goes unnoticed; a constant gives it one place. Counted are plain string literals of at least min-length characters, compared as written, except docstrings, keys of dict displays and subscripts; the finding is placed on the first occurrence once a string appears min-count times.
From the rule's source, duplicate_string_literal.rs.
def report(log): log("connection failed")tx0 reports: is written 4 times in this file log("connection failed") log("connection failed") log("connection failed") log("short") log("short") log("short") log("short") log("only three times") log("only three times") log("only three times") Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:duplicate-string-literal" = "note"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:duplicate-string-literal] reason="..."tx0 explain tx0/python:duplicate-string-literal shows the same in the terminal. Found a false positive? Report it.