Esc

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.

CategoryDefaultWhat
correctnessdenycode that is wrong: it does not do what it says
suspiciouswarncode that is most likely wrong, or does nothing
complexitywarncode that says something in a roundabout way
stylewarncode that works but is not written the usual way
perfwarncode that could be faster
pedanticallowstricter checks with more false positives
restrictionallowchecks 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 to b.
  • 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 by return 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 to a twice.
  • range_past_count: Finds for i: 0..xs.count indexing xs[i], one past the end.
  • remove_in_for: Finds removing from an array while a for walks it forward.
  • returned_local_address: Finds return *x; with x a 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 if or while whose condition the compiler shows is always true or false.
  • defer_in_loop: Finds a defer in a loop body that cleans up something from outside the loop.
  • dropped_result: Finds a call drops the bool that follows the values it keeps (n := to_integer(s);).
  • duplicate_condition: Finds an else if that repeats an earlier condition.
  • erasing_op: Finds an operation that is always 0 (x * 0, x & 0).
  • identical_branches: Finds an if/else or ifx whose branches are the same.
  • identical_operands: Finds an operator with the same expression on both sides (a == a).
  • infinite_loop: Finds a while whose 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 for range 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 @GrowsArray call 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 #if arm, which lasts past the arm.
  • self_assignment: Finds a value assigned to itself (x = x;).
  • shadowed_it: Finds a nested for hides an it the enclosing loop uses.
  • shift_overflow: Finds a shift by at least the bit width of its operand (x << 40 with x: s32).
  • unclosed_resource: Finds a local opened by an @Opens call (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 @Locks call with a path that returns or ends without a matching @Unlocks.
  • unsigned_range_end_minus_one: Finds for 0..n-1 with an unsigned n, which wraps around when n is 0.
  • unused_private_declaration: Finds a #scope_file declaration that nothing in its file uses.
  • unused_result: Finds a call to a @UseResult procedure, as a statement.
  • unused_suppression: Finds a name in a // jailint: allow(...) comment or @jailint_allow note that silences nothing.

Complexity

Code that says something in a roundabout way. Default: warn.

  • bool_comparison: Finds comparing a bool with true or false.
  • identity_op: Finds an operation that changes nothing (x + 0, x * 1).
  • index_only_loop: Finds for i: 0..xs.count-1 where i only indexes xs.
  • int_plus_one: Finds x >= y + 1, which is x > 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_find does.
  • manual_assign_op: Finds a = a + b instead of a += 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 for loop that always equals it_index.
  • needless_bool: Finds ifx c then true else false and if 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.*.field where p.field means the same.
  • unnecessary_force_cast: Finds cast,force where the value already has the type or the conversion widens.
  • useless_format: Finds tprint("%", s) or sprint("%", s) with a string s, which only copies it.

Style

Code that works but is not written the usual way. Default: warn.

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 copy memcpy does at once.
  • useless_resizable: Finds a local [..] T that is only filled with a known number of array_add calls and never resized.

Pedantic

Stricter checks with more false positives. Default: allow.

  • bool_to_int_with_if: Finds ifx c then 1 else 0, a bool turned 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 literal x := T.{ a = 1, b = 2 } sets the fields at the declaration.
  • float_equality: Finds == or != between two computed floats.
  • float_loop_counter: Finds a while loop counted in floats (while t < 1.0 { t += 0.1; }).
  • identical_case_bodies: Finds two cases of a switch with the same body, which could list their values together.
  • if_not_else: Finds an if or ifx with a negated condition and an else.
  • incomplete_enum_switch: Finds a switch on 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 xx that 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 from a >= b when 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 using of 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 bool parameters than max_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, XXX or HACK marker.
  • too_many_arguments: Finds a procedure with more parameters than max_arguments (default 7).
  • unchecked_directive: Finds #no_abc, #no_aoc or #asm with no comment saying why.