Credence.Syntax.FixPythonModulo (credence v0.6.0)

Copy Markdown

Replaces Python's % modulo operator with Elixir's rem/2.

LLMs translating from Python carry over the % infix operator for modulo arithmetic. In Elixir, % is used for maps and structs, not arithmetic — the modulo function is rem/2 (or Integer.mod/2 for floor-division semantics).

This is a Syntax rule because a % b won't parse in Elixir.

Detected patterns

year % 4          n % 2 == 0
n % divisor       100 % 7

Any word % word where % is used as an infix operator between two identifiers or integers.

Not flagged

Legitimate Elixir % usage is not affected:

%{key: value}            map literal
%MyStruct{field: val}    struct literal
%{map | key: new}        map update

Float operands (n % 2.0) are skipped because rem/2 only accepts integers. Comment lines are also skipped.

Bad

def leap_year?(year) when year % 4 != 0, do: false
def even?(n), do: n % 2 == 0

Good

def leap_year?(year) when rem(year, 4) != 0, do: false
def even?(n), do: rem(n, 2) == 0