Lint rules
The 106 rules jailint checks, by category. jailint says how to run it, configure rules and silence a finding.
A rule's category sets its default level. Name a category wherever a rule name works ([lint.rules], -W, // jailint: allow(...)). The compiler's warnings are reported too and take levels the same way, by code (struct-literal-as-dynamic-array), as leniencies, or all at once as compiler; // jailint: allow(...) does not cover them.
| Category | Default | What |
|---|---|---|
correctness | deny | code that is wrong: it does not do what it says |
suspicious | warn | code that is most likely wrong, or does nothing |
complexity | warn | code that says something in a roundabout way |
style | warn | code that works but is not written the usual way |
perf | warn | code that could be faster |
pedantic | allow | stricter checks with more false positives |
restriction | allow | checks that forbid things a project may choose to avoid |
Correctness
Code that is wrong: it does not do what it says. Default: deny.
- absurd_comparison: Finds a comparison an unsigned value always passes or fails (
u >= 0). - almost_swapped: Finds
a = b; b = a;, a swap that sets both tob. - bad_bit_mask: Finds a mask test that can never match (
(x & 4) == 1,(x | 2) == 0). - defer_frees_returned: Finds
defer free(p);followed byreturn p;, which hands back freed memory. - double_free: Finds two calls that free the same variable with nothing in between (
free(p); free(p);). - element_count_as_bytes: Finds
memcpy(d, xs.data, xs.count)with elements wider than a byte. - impossible_comparison: Finds comparisons of one integer that never pass together (
x > 5 && x < 3). - min_max: Finds
min(0, max(100, x)), a clamp that is always one bound. - misrefactored_assign_op: Finds
a += a + b, an update that applies the operator toatwice. - range_past_count: Finds
for i: 0..xs.countindexingxs[i], one past the end. - remove_in_for: Finds removing from an array while a
forwalks it forward. - returned_local_address: Finds
return *x;withxa local, a pointer into a stack frame that is gone. - reversed_range: Finds a range whose start is above its end, which never runs.
- string_literal_write: Finds a write into a string literal, which is read-only (
s := "abc"; s[0] = x;). - uninit_read: Finds a variable declared
= ---read before anything is written to it. - use_after_free: Finds a variable read after a call freed it (
free(p); use(p);, or a wrapper that frees). - wrapping_constant: Finds a constant that wraps to the type the other operand gives it (
(0xffff_ffff - 40) / h).
Suspicious
Code that is most likely wrong, or does nothing. Default: warn.
- bitwise_precedence: Finds a bitwise operator that binds differently than in C (
1 << n - 1). - constant_condition: Finds an
iforwhilewhose condition the compiler shows is always true or false. - defer_in_loop: Finds a
deferin a loop body that cleans up something from outside the loop. - dropped_result: Finds a call drops the
boolthat follows the values it keeps (n := to_integer(s);). - duplicate_condition: Finds an
else ifthat repeats an earlier condition. - erasing_op: Finds an operation that is always
0(x * 0,x & 0). - identical_branches: Finds an
if/elseorifxwhose branches are the same. - identical_operands: Finds an operator with the same expression on both sides (
a == a). - infinite_loop: Finds a
whilewhose condition nothing in the loop changes. - integer_division_in_float: Finds an integer division whose result is used as a float.
- leaked_temporary: Finds an inferred owned result that is only compared, measured, indexed or printed, so nothing can free it.
- modified_range_bound: Finds a variable bounding a
forrange assigned in the loop, which does not change it. - no_effect: Finds a statement that computes a value and drops it (
x == 5;). - pointer_into_resizable: Finds a pointer into a resizable array used after a
@GrowsArraycall may have moved the array (p := *xs[i]; array_add(*xs, v); use(p);). - push_in_static_if: Finds a scoped push directly in an
#ifarm, which lasts past the arm. - self_assignment: Finds a value assigned to itself (
x = x;). - shadowed_it: Finds a nested
forhides anitthe enclosing loop uses. - shift_overflow: Finds a shift by at least the bit width of its operand (
x << 40withx: s32). - unclosed_resource: Finds a local opened by an
@Openscall (file_open,append(*builder, ..)) that nothing closes. - unknown_allow: Finds a
// jailint: allow(...)comment naming a rule that does not exist. - unpaired_lock: Finds a
@Lockscall with a path that returns or ends without a matching@Unlocks. - unsigned_range_end_minus_one: Finds
for 0..n-1with an unsignedn, which wraps around whennis 0. - unused_private_declaration: Finds a
#scope_filedeclaration that nothing in its file uses. - unused_result: Finds a call to a
@UseResultprocedure, as a statement. - unused_suppression: Finds a name in a
// jailint: allow(...)comment or@jailint_allownote that silences nothing.
Complexity
Code that says something in a roundabout way. Default: warn.
- bool_comparison: Finds comparing a bool with
trueorfalse. - identity_op: Finds an operation that changes nothing (
x + 0,x * 1). - index_only_loop: Finds
for i: 0..xs.count-1whereionly indexesxs. - int_plus_one: Finds
x >= y + 1, which isx > y. - loop_with_break_condition: Finds
while true { if !c break; ... }, a loop whose condition is its first statement. - manual_array_find: Finds a loop that searches an array and breaks with a found flag or index, which
array_finddoes. - manual_assign_op: Finds
a = a + binstead ofa += b. - manual_clamp: Finds a value kept between two constant bounds by hand instead of with
clamp. - manual_index_counter: Finds a counter incremented in a
forloop that always equalsit_index. - needless_bool: Finds
ifx c then true else falseandif c return true; else return false;. - redundant_alias: Finds a local that only exists to be copied into another local or returned.
- redundant_cast: Finds a cast to the type the value already has.
- redundant_deref: Finds
p.*.fieldwherep.fieldmeans the same. - unnecessary_force_cast: Finds
cast,forcewhere the value already has the type or the conversion widens. - useless_format: Finds
tprint("%", s)orsprint("%", s)with a strings, which only copies it.
Style
Code that works but is not written the usual way. Default: warn.
- approx_constant: Finds a hand-typed
3.14159or1.4142whereMathhas the constant. - assert_constant: Finds
assert(true)or#assert true, which can never fail. - banner_comment: Finds a comment that is only a line of
-,=or*fencing off a section. - broken_doc_link: Finds a link in a doc comment (
[name]) that names no declaration. - enum_member_prefix: Finds every member of an enum starts with the enum's name.
- lossy_float_literal: Finds a
float32literal with more digits than afloat32keeps (31415.92653). - mixed_case_hex_literals: Finds a hex literal with both upper and lower case digits (
0xDeadbeef). - needless_continue: Finds a
continueas the last thing a loop body does. - neg_multiply: Finds
x * -1, which is-x. - single_case_switch: Finds a
switchwith a single case, which is anif. - unnecessary_semicolon: Finds a
;that ends nothing (x = 1;;,if c { ... };). - unused_import: Finds an
#importnothing in its scope uses. - unused_parameter: Finds a parameter the procedure never uses.
- unused_variable: Finds a local variable that is never used.
- zero_ptr: Finds
cast(*T) 0, which isnull.
Perf
Code that could be faster. Default: warn.
- format_push_string: Finds
append(*b, tprint(...)), which formats into a new string to add it to a builder. - manual_memcpy: Finds
for i: 0..n-1 { dst[i] = src[i]; }, an element-by-element copymemcpydoes at once. - useless_resizable: Finds a local
[..] Tthat is only filled with a known number ofarray_addcalls and never resized.
Pedantic
Stricter checks with more false positives. Default: allow.
- bool_to_int_with_if: Finds
ifx c then 1 else 0, aboolturned into an integer with a branch. - cognitive_complexity: Finds a procedure whose branching scores above
max_complexity(default 25). - detached_doc_comment: Finds a comment that reads as a declaration's docs but has a blank line between it and the declaration.
- excessive_nesting: Finds blocks nested deeper than
max_nesting(default 6). - field_reassign_with_default: Finds
x: T; x.a = 1; x.b = 2;where a struct literalx := T.{ a = 1, b = 2 }sets the fields at the declaration. - float_equality: Finds
==or!=between two computed floats. - float_loop_counter: Finds a
whileloop counted in floats (while t < 1.0 { t += 0.1; }). - identical_case_bodies: Finds two cases of a
switchwith the same body, which could list their values together. - if_not_else: Finds an
iforifxwith a negated condition and anelse. - incomplete_enum_switch: Finds a
switchon an enum that neither covers every member nor has a default case. - large_stack_array: Finds a local fixed array bigger than
max_stack_array_bytes(default 64 KiB). - leaked_allocation: Finds a local holding inferred owned storage that is never freed, returned or handed on.
- lossy_xx: Finds
xxthat narrows a number to a smaller type. - magic_number: Finds an unexplained number in arithmetic, a comparison or an assignment.
- neg_cmp_float: Finds
!(a < b)on floats, which differs froma >= bwhen a value is NaN. - shadowed_local: Finds a local variable named like a parameter or another local in an enclosing scope of the same procedure.
- temp_storage_escape: Finds temporary storage (
tprint,talloc, or a procedure returning it) stored in a global or through a pointer, or returned. - union_read: Finds a union member read without checking which one is live.
- unreadable_literal: Finds a long number without
_separators (1000000,0xdeadbeef). - using_pollution: Finds a
usingof a struct whose members share names with parameters, locals or globals already in scope.
Restriction
Checks that forbid things a project may choose to avoid. Default: allow.
- autocast_in_arg: Finds
xx, the automatic cast, written as an argument of a call. - autocast_used: Finds
xx, the automatic cast, outside a call's arguments. - excessive_bools: Finds a procedure with more
boolparameters thanmax_bools(default 3). - exit_in_module: Finds a module ends the process.
- missing_doc: Finds an exported procedure, struct or enum with no doc comment.
- platform_leak: Finds portable code imports something that asserts an operating system it is not built for.
- pointer_lifetime: Finds a pointer used after its storage moves or its element becomes invalid.
- print_in_module: Finds a module writes to the program's output.
- todo_marker: Finds a comment with a
TODO,FIXME,XXXorHACKmarker. - too_many_arguments: Finds a procedure with more parameters than
max_arguments(default 7). - unchecked_directive: Finds
#no_abc,#no_aocor#asmwith no comment saying why.