Credence.Semantic.NoNonNegatedInteger (credence v0.8.0)

Copy Markdown

Fixes compiler errors about the undefined type non_negated_integer/0.

LLMs commonly produce non_negated_integer() in typespecs when they mean non_neg_integer(). The Elixir compiler emits:

type non_negated_integer/0 undefined (no such type in Module)

The fix is the textual substitution non_negated_integernon_neg_integer — both types describe the same set of values — but it is applied only on the line the compiler flagged. That line is a type-only context (@spec/@type/@callback/…), so the rename touches a type reference and nothing else; a blanket replace across the whole source would also rewrite an unrelated string literal, comment, atom or identifier named non_negated_integer elsewhere in the file, which changes the program's answer.

The rule runs at a lower priority than NoBareNamesInSpec: that rule's type _/0 undefined matcher also matches this diagnostic but cannot fix the parenthesised type call (non_negated_integer()), so this rule must be tried first or it would never fire.