Lint rules
fatou lint reports problems using the rule IDs listed below. Use these IDs to select rules, set their severity, or suppress a finding with # fatou-ignore <id>.
Most rules are enabled by default. Workspace package files enable additional rules that need project context; declared script programs also enable undefined-name. Exceptions are noted in each rule's description. Use select to replace the defaults, extend-select to add rules, and ignore to disable them. See Configuration for details.
fatou lint --fix applies safe fixes. Add --unsafe-fixes to apply fixes that may change behavior. Editors also offer fixes as code actions. The examples show the result of safe fixes.
Rules that recommend Base functions generally check that the original name resolves to Base. Fixes may be withheld if a replacement name is shadowed or the edit would discard comments.
The diagnostics and fixed code below are generated from the examples.
unused-binding
Report a local variable that is assigned but never read. Names beginning with _ are exempt, as are parameters, loop and catch variables, struct fields, type parameters, and top-level definitions.
tmp is assigned inside f but never used:
function f(x)
tmp = x + 1
return x
endwarning: unused-binding
--> example.jl:2:5
|
2 | tmp = x + 1
| ^^^ local variable `tmp` is assigned but never usedunused-import
Report an explicitly imported name that is never used. Qualified references, re-exports, and uses in the same module's included files count as uses.
The rule skips whole-module using X statements and withholds findings when an incomplete include chain could hide a use.
sortperm is imported but never referenced:
using Base: sortperm, sum
println(sum([1, 2, 3]))warning: unused-import
--> example.jl:1:13
|
1 | using Base: sortperm, sum
| ^^^^^^^^ `sortperm` is imported but never usedduplicate-argument
Report a repeated parameter name in a function signature. Positional and keyword parameters share the same namespace, and Julia rejects duplicates.
x appears twice in the parameter list:
function dist(x, y, x)
hypot(x, y)
enderror: duplicate-argument
--> example.jl:1:21
|
1 | function dist(x, y, x)
| ^ argument name `x` is used more than onceduplicate-keyword-argument
Report a keyword argument passed more than once in a call. Julia rejects duplicate keywords, including those on opposite sides of ;. The shorthand f(; x) counts as passing x. Keyword splats are not checked.
label is supplied twice in one call:
plot(xs, ys, label = "before", label = "after")error: duplicate-keyword-argument
--> example.jl:1:32
|
1 | plot(xs, ys, label = "before", label = "after")
| ^^^^^ keyword argument `label` is passed more than onceunused-argument
Report a function parameter that is never read. Names consisting only of underscores and stub methods with a literal, nothing, error(...), or throw(...) body are exempt.
Disabled by default because methods often use a parameter's type for dispatch without reading its value. Enable it with --select unused-argument.
factor is accepted but never used:
function scale(x, factor)
2 * x
endwarning: unused-argument
--> example.jl:1:19
|
1 | function scale(x, factor)
| ^^^^^^ function argument `factor` is never usedundefined-name
Report a name that cannot be found in local bindings, the workspace package, imports, or Base and Core.
Enabled by default for workspace package files and programs declared with [project] entry-points = ["main.jl"]. Entry points let Fatou follow static includes and resolve global assignments. Each entry point and enclosing module is checked separately; diagnostics identify the contexts where a name is missing.
Dynamic definitions, unresolved imports, or incomplete include chains suppress findings for the affected entry point. Standalone files without entry points can enable the rule with [lint] extend-select = ["undefined-name"], but files containing includes are then skipped.
A misspelled variable name:
function area(radius)
return pi * raduis^2
endwarning: undefined-name
--> example.jl:2:17
|
2 | return pi * raduis^2
| ^^^^^^ `raduis` is not definedbreak-outside-loop
Report break or continue outside a for or while loop. Julia rejects these statements, including inside a closure, do block, or comprehension nested in a loop: they cannot jump across a function boundary.
break outside a loop:
function process(x)
if x < 0
break
end
x
enderror: break-outside-loop
--> example.jl:3:9
|
3 | break
| ^^^^^ `break` outside of a `for` or `while` loopA do block cannot continue its enclosing loop:
for i in 1:3
foreach(1:2) do x
continue
end
enderror: break-outside-loop
--> example.jl:3:9
|
3 | continue
| ^^^^^^^^ `continue` outside of a `for` or `while` loopconst-local
Report const in a local scope, such as a function, let, or loop body. Julia allows constant bindings only at global scope: the file's top level or a module body. A const field in a mutable struct is allowed.
const inside a function body:
function scale(x)
const factor = 2
factor * x
enderror: const-local
--> example.jl:2:5
|
2 | const factor = 2
| ^^^^^^^^^^^^^^^^ `const` declaration on a local variableconst inside a let block:
let
const limit = 10
limit
enderror: const-local
--> example.jl:2:5
|
2 | const limit = 10
| ^^^^^^^^^^^^^^^^ `const` declaration on a local variableglobal-const-in-function
Report global const inside a function, macro, closure, do block, or comprehension. Julia rejects these declarations even inside a nested let or loop. Move the declaration outside the function.
global const inside a function body:
function setup()
global const LIMIT = 10
enderror: global-const-in-function
--> example.jl:2:5
|
2 | global const LIMIT = 10
| ^^^^^^^^^^^^^^^^^^^^^^^ `global const` declaration inside a functionglobal const inside a loop within a function:
function setup()
for i in 1:3
global const LIMIT = i
end
enderror: global-const-in-function
--> example.jl:3:9
|
3 | global const LIMIT = i
| ^^^^^^^^^^^^^^^^^^^^^^ `global const` declaration inside a functionlocal-const
Report local const or const local, which Julia rejects in every scope. Use local x = 1 for a local binding or const x = 1 for a global constant.
local and const cannot be combined:
local const LIMIT = 10error: local-const
--> example.jl:1:1
|
1 | local const LIMIT = 10
| ^^^^^^^^^^^^^^^^^^^^^^ `local const` declaration is not supportedconst local inside a function:
function scale(x)
const local factor = 2
factor * x
enderror: local-const
--> example.jl:2:5
|
2 | const local factor = 2
| ^^^^^^^^^^^^^^^^^^^^^^ `local const` declaration is not supportednoteq-definition
Report a method definition for != or ≠. Define == instead: Julia derives != by negating ==.
Overloading != directly:
!=(a::Grade, b::Grade) = a.score != b.scorewarning: noteq-definition
--> example.jl:1:1
|
1 | !=(a::Grade, b::Grade) = a.score != b.score
| ^^ `!=` is defined as `!(==)` and should not be overloaded; define `==` insteadunused-type-parameter
Report a where type parameter that is never used in the signature or body. This often indicates a missing type annotation or a leftover parameter.
Struct type parameters and names consisting only of underscores are exempt.
T is bound but never referenced:
function f(x) where {T}
x + 1
endwarning: unused-type-parameter
--> example.jl:1:22
|
1 | function f(x) where {T}
| ^ type parameter `T` is never usedmissing-include-file
Report an include("path") whose target is missing or unreadable. Relative paths resolve from the including file's directory.
The rule checks only static paths. It skips computed or interpolated paths, qualified calls such as M.include(...), and two-argument forms.
Including a file that does not exist:
include("missing.jl")error: missing-include-file
--> example.jl:1:9
|
1 | include("missing.jl")
| ^^^^^^^^^^^^ included file "missing.jl" does not existinclude-cycle
Report an include that leads back to the current file, directly or through other files. Running it causes unbounded recursion. Each linted file in the cycle gets a diagnostic at its own include call.
A file (here example.jl) that includes itself:
include("example.jl")warning: include-cycle
--> example.jl:1:9
|
1 | include("example.jl")
| ^^^^^^^^^^^^ include cycle: "example.jl" transitively includes this fileduplicate-include
Report a file included more than once from the same file and module. Each include evaluates the target again, repeating its top-level code and redefining its methods. Paths such as "a.jl" and "./a.jl" count as the same file.
Includes in separate modules and files reached through different include chains are allowed.
Including the same file twice:
include("util.jl")
include("util.jl")warning: duplicate-include
--> example.jl:2:9
|
2 | include("util.jl")
| ^^^^^^^^^ duplicate include: "util.jl" is already included earlier in this fileduplicate-method
Report a method definition that replaces an earlier method in the same file. Julia dispatches on positional argument types and where constraints. Changing only parameter names, defaults, keyword arguments, or the return type does not create a separate method.
Definitions inside macro calls or conditional branches are not checked.
A method replacing an earlier definition:
f(x::Int) = 1
f(y::Int) = 2warning: duplicate-method
--> example.jl:2:1
|
2 | f(y::Int) = 2
| ^ this definition of `f` replaces an earlier method with the same signaturejulia-version-compat
Report syntax unavailable in a Julia version the project supports. public requires Julia 1.11, and import ... as requires 1.6. Julia 1.14 adds typegroup, wrapping arithmetic and assignment operators (including broadcasts), labeled break and continue, primitive types with non-byte-multiple literal widths, parenthesized multiline macro arguments, and return forms that inherit index markers or a ternary branch's closing colon. Width expressions are not evaluated.
The runtime target comes from --julia-version, [julia] version, or the project's Project.toml or Manifest.toml. The rule checks the oldest supported runtime, independently of the selected syntax edition, and does nothing when no target is known.
Targeting Julia 1.0, but public needs 1.11 and as needs 1.6:
module M
public foo
import A as B
enderror: julia-version-compat
--> example.jl:2:1
|
2 | public foo
| ^^^^^^^^^^ the `public` keyword requires Julia 1.11.0, but the project supports 1.0.0 and up
error: julia-version-compat
--> example.jl:3:8
|
3 | import A as B
| ^^^^^^ renaming with `as` in `import`/`using` requires Julia 1.6.0, but the project supports 1.0.0 and upThese constructs require a Julia 1.14 runtime:
typegroup
struct A end
end
x +%= 1
@label outer for i in xs
continue outer
end
primitive type Bits 7 end
(@info "message"
x=1)
a[return end]
x ? return : yerror: julia-version-compat
--> example.jl:1:1
|
1 | typegroup
| ^^^^^^^^^ `typegroup` requires Julia 1.14.0, but the project supports 1.0.0 and up
error: julia-version-compat
--> example.jl:4:3
|
4 | x +%= 1
| ^^^ wrapping arithmetic syntax requires Julia 1.14.0, but the project supports 1.0.0 and up
error: julia-version-compat
--> example.jl:6:5
|
6 | continue outer
| ^^^^^^^^^^^^^^ labeled `continue` requires Julia 1.14.0, but the project supports 1.0.0 and up
error: julia-version-compat
--> example.jl:8:21
|
8 | primitive type Bits 7 end
| ^ a primitive type with a non-byte-multiple width requires Julia 1.14.0, but the project supports 1.0.0 and up
error: julia-version-compat
--> example.jl:9:2
|
9 | (@info "message"
| ^^^^^ parenthesized multiline macro argument syntax requires Julia 1.14.0, but the project supports 1.0.0 and up
error: julia-version-compat
--> example.jl:11:3
|
11 | a[return end]
| ^^^^^^ `return` with inherited index or ternary context requires Julia 1.14.0, but the project supports 1.0.0 and up
error: julia-version-compat
--> example.jl:12:5
|
12 | x ? return : y
| ^^^^^^ `return` with inherited index or ternary context requires Julia 1.14.0, but the project supports 1.0.0 and upcall-arity
Report a call when no known method accepts its number of positional arguments or its keyword names. Such calls raise MethodError.
Fatou checks methods in the file, workspace package, and indexed libraries. It skips calls when the available methods or arguments are uncertain, including splatted calls, do blocks, constructors, and callable values.
Enabled by default for workspace package files. Other files require explicit selection because methods may be defined in sibling files.
half has no two-argument method:
half(x) = x / 2
half(3, 4)warning: call-arity
--> example.jl:3:1
|
3 | half(3, 4)
| ^^^^^^^^^^ no method of `half` takes 2 positional arguments (methods accept 1)function-has-no-methods
Report a call to a function declared with function f end but given no methods. The call raises MethodError regardless of its arguments.
Fatou checks functions defined in the file or workspace package. Exported and public declarations are exempt because other packages may implement them. The rule skips files whose definitions cannot be resolved reliably.
Enabled by default for workspace package files. Other files require explicit selection because sibling files may add methods.
normalize is declared but never given a method:
function normalize end
normalize("data")warning: function-has-no-methods
--> example.jl:3:1
|
3 | normalize("data")
| ^^^^^^^^^ `normalize` is declared with `function normalize end` but has no methodsredefined-constant
Report conflicting definitions of a name: reassigning a constant, assigning to a function, type, or module name, defining a function over a value, or declaring an existing variable const.
Definitions in separate branches of the same if are allowed, as are new methods and outer constructors.
Reassigning a constant:
const threshold = 1.0
threshold = 2.0warning: redefined-constant
--> example.jl:2:1
|
2 | threshold = 2.0
| ^^^^^^^^^ reassignment of constant `threshold`count already holds a value, so the method definition fails:
count = 0
count(xs) = length(xs)warning: redefined-constant
--> example.jl:2:1
|
2 | count(xs) = length(xs)
| ^^^^^ cannot define function `count`: it already has a valuetype-piracy
Report a method that extends another module's function using only types defined elsewhere. This is type piracy: loading the method can change behavior for unrelated code that uses the same function and types. Define the function or at least one argument type in your module.
Disabled by default. Fatou reports only cases where ownership is known. Without indexed libraries, it checks ownership against the built-in Base and Core snapshot.
Extending Base.show for only Base types is piracy:
Base.show(io::IO, x::Int) = print(io, x)warning: type-piracy
--> example.jl:1:6
|
1 | Base.show(io::IO, x::Int) = print(io, x)
| ^^^^ type piracy: this module defines neither `Base.show` nor any of its argument typesunreachable-code
Report statements that can never run, such as code after an unconditional return, throw, error, or rethrow. The rule also catches code after an if whose branches all exit, or a while true loop with no break.
Check whether the unreachable statement should be removed or the preceding control flow should change.
Nothing after an unconditional return can run:
function f(x)
return x + 1
println("never")
endwarning: unreachable-code
--> example.jl:3:5
|
3 | println("never")
| ^^^^^^^^^^^^^^^^ unreachable code: no path of execution reaches this statementAn unreachable statement after two branches that return:
function classify(x)
if x > 0
return :pos
else
throw(DomainError(x))
end
return :unknown
endwarning: unreachable-code
--> example.jl:7:5
|
7 | return :unknown
| ^^^^^^^^^^^^^^^ unreachable code: no path of execution reaches this statementunresolved-import
Report a using or import of a package absent from both the project's [deps] and the indexed environment. Julia may fail to load the package.
Relative imports such as using .Sub are allowed. Packages found in the environment, including standard libraries and transitive dependencies, are also accepted.
Enabled by default for workspace package files, where project dependencies are known.
The project declares LinearAlgebra in [deps], but not Frobnicate:
using LinearAlgebra
using Frobnicatewarning: unresolved-import
--> example.jl:2:7
|
2 | using Frobnicate
| ^^^^^^^^^^ `Frobnicate` is not a dependency of this projectkwarg-default-mismatch
Report a keyword parameter whose default has the wrong type, such as f(; x::Int = 1.0). Julia does not convert keyword defaults to the declared type, so calling f() raises MethodError. Defaults such as x::Int8 = 1 also fail because 1 has type Int.
The rule checks concrete built-in types and literals with known types. It skips abstract or parametric types and computed defaults.
y is declared Int, so the Float64 default never matches it:
function scale(xs; y::Int = 1.0)
xs .* y
enderror: kwarg-default-mismatch
--> example.jl:1:20
|
1 | function scale(xs; y::Int = 1.0)
| ^^^^^^^^^^^^ keyword argument `y` is declared `::Int`, but its default `1.0` has type `Float64`
= help: use a default of the declared type; Julia does not convert keyword defaultsAn Int default for an Int8 parameter:
counter(; start::Int8 = 0) = starterror: kwarg-default-mismatch
--> example.jl:1:11
|
1 | counter(; start::Int8 = 0) = start
| ^^^^^^^^^^^^^^^ keyword argument `start` is declared `::Int8`, but its default `0` has type `Int`
= help: use a default of the declared type; Julia does not convert keyword defaultsinvalid-type-declaration
Report a function name used as a type in ::, such as f(x::g) when g is a function. Julia raises TypeError when it evaluates the declaration.
Fatou checks functions defined in the file or workspace package. It skips names that might refer to types and files whose definitions cannot be resolved reliably.
Enabled by default for workspace package files. Other files require explicit selection and a resolution context.
scale is a function, so declaring y::scale is a TypeError:
scale(x) = 2x
apply(y::scale) = ywarning: invalid-type-declaration
--> example.jl:3:10
|
3 | apply(y::scale) = y
| ^^^^^ `scale` is a function and cannot be used as a type in `::scale`invalid-docstring-code
Report syntax errors in Julia code blocks within docstrings. The rule checks julia blocks and Documenter directives. For julia-repl and jldoctest transcripts, it checks the input and skips expected output.
Other languages, dynamically constructed docstrings, and docstrings with malformed Markdown are not checked.
An incomplete Julia code block:
"""
~~~julia
f(
~~~
"""
f() = 1warning: invalid-docstring-code
--> example.jl:3:2
|
3 | f(
| ^ invalid Julia in documentation fence: unterminated argument listdocstring-argument-mismatch
Report a - `name`: ... entry under # Arguments in a docstring when the attached function or macro has no parameter with that name. This catches misspelled or outdated entries. The rule does not require every parameter to be documented.
A misspelled argument name:
"""
# Arguments
- `raduis`: The radius.
"""
area(radius) = pi * radius^2warning: docstring-argument-mismatch
--> example.jl:3:3
|
3 | - `raduis`: The radius.
| ^^^^^^^^ documented argument `raduis` is not in the attached signatureunresolved-docstring-reference
Report a Documenter link such as [`Foo.bar`](@ref Foo.bar) when the target Julia symbol cannot be found. Local Markdown anchors are accepted. Inferred references, prose labels, and targets that cannot be resolved reliably are not checked.
Enabled by default for workspace package files. Other files require explicit selection and a resolution context.
A misspelled reference target:
"""
See [`Base.raduis`](@ref Base.raduis).
"""
area(radius) = pi * radius^2warning: unresolved-docstring-reference
--> example.jl:2:26
|
2 | See [`Base.raduis`](@ref Base.raduis).
| ^^^^^^^^^^^ documentation reference `Base.raduis` does not resolveassignment-in-condition
Report a bare assignment used as an if, elseif, or while condition. This is usually a typo for ==. The safe fix replaces = with ==.
= where == was meant:
if x = 5
println(x)
endwarning: assignment-in-condition
--> example.jl:1:4
|
1 | if x = 5
| ^^^^^ assignment used as a condition; did you mean `==`?
= help: Replace `=` with `==` (safe fix)After applying the fix:
if x == 5
println(x)
endnothing-comparison
Prefer ===, !==, or isnothing when comparing with nothing. Identity tests express the intent directly and cannot be overloaded.
The safe fix replaces == with === and != with !==. Inside Test.@test, it prefers isnothing(x) or !isnothing(x) when that name resolves to Base.
Comparing against nothing by value:
if x == nothing
1
endwarning: nothing-comparison
--> example.jl:1:4
|
1 | if x == nothing
| ^^^^^^^^^^^^ comparison against `nothing` by value; use `===` or `isnothing`
= help: Replace `==` with `===` (safe fix)After applying the fix:
if x === nothing
1
endmissing-comparison
Report == or != comparisons with missing. These return missing, and using the result as a condition raises TypeError. Use ismissing, ===, or !== instead.
The fix replaces the value comparison with an identity test. It requires --unsafe-fixes because it changes the result to a Bool.
Comparing against missing by value:
if x == missing
1
endwarning: missing-comparison
--> example.jl:1:4
|
1 | if x == missing
| ^^^^^^^^^^^^ comparison against `missing` by value is always `missing`; use `ismissing` or `===`
= help: Replace `==` with `===` (unsafe fix, requires `--unsafe-fixes`)constant-condition
Report true or false used as a condition or as an operand of && or ||. These constants often come from debugging code or a mistyped name. The rule allows while true, the usual way to write an infinite loop.
An if condition that is always true:
if true
println("always")
endwarning: constant-condition
--> example.jl:1:4
|
1 | if true
| ^^^^ this condition is always `true`A constant that prevents check(x) from running:
ok = false && check(x)warning: constant-condition
--> example.jl:1:6
|
1 | ok = false && check(x)
| ^^^^^ `&&` has a constant `false` operandmodule-shadows-parent
Report a nested module with the same name as its parent. The child hides the parent's reference to itself, so qualified names such as A.x may resolve against the wrong module. This often happens when a file is included inside the module it already defines.
A submodule shadowing the module that contains it:
module A
module A
end
endwarning: module-shadows-parent
--> example.jl:3:8
|
3 | module A
| ^ module `A` has the same name as its parent moduleloop-variable-shadow
Report an inner for loop that reuses an enclosing loop's index name. The inner loop creates a new binding and hides the outer index, often because a copied loop was not renamed.
Assignments to loop variables are allowed. Comprehensions, generators, and reuse across function boundaries are not checked.
A nested loop reusing the enclosing loop's index:
for i in 1:3
for i in 1:2
println(i)
end
endwarning: loop-variable-shadow
--> example.jl:2:9
|
2 | for i in 1:2
| ^ loop variable `i` shadows the enclosing loop's variableindex-from-length
Prefer eachindex(x) to 1:length(x) when a loop variable indexes x, or axes(x, d) to 1:size(x, d). These handle collections whose indices do not start at one. The fix requires --unsafe-fixes because changing the indices can change behavior.
The rule also reports iteration over a numeric literal, such as for i in 3.5. Julia runs that loop once, which usually indicates a missing range.
1:length(x) used to index x:
for i in 1:length(x)
println(x[i])
endwarning: index-from-length
--> example.jl:1:10
|
1 | for i in 1:length(x)
| ^^^^^^^^^^^ iterate `eachindex(x)` instead of `1:length(x)`
= help: Replace `1:length` with `eachindex` (unsafe fix, requires `--unsafe-fixes`)Iterating a bare number loops once:
for i in 3.5
println(i)
endwarning: index-from-length
--> example.jl:1:10
|
1 | for i in 3.5
| ^^^ iterating a numeric literal runs the loop body once; did you mean a range?discouraged-function
Report calls to functions with process-wide or unsafe effects. Defaults include exit, cd, stream redirection, and unsafe memory operations. Each diagnostic suggests an alternative. Callback forms of cd and stream redirection are allowed because they restore the previous state.
Configure [lint.rules.discouraged-function] with tables mapping function names to suggestions. functions replaces the defaults, extend-functions adds or overrides entries, and functions = {} clears the list. Qualified calls such as Base.exit are not checked.
cd changes the working directory, and exit ends the process:
function cleanup()
cd("/tmp")
exit(1)
endwarning: discouraged-function
--> example.jl:2:5
|
2 | cd("/tmp")
| ^^ `cd` is discouraged: use the `cd(f, dir)` do-block form so the working directory is restored
warning: discouraged-function
--> example.jl:3:5
|
3 | exit(1)
| ^^^^ `exit` is discouraged: let the caller decide when the process endstypeof-comparison
Prefer x isa T to typeof(x) == T when testing whether a value belongs to a type. Exact comparisons exclude subtypes: typeof(1) == Integer is false, but 1 isa Integer is true.
The rule skips identity comparisons, broadcast comparisons, chains, and comparisons between two typeof calls. The fix requires --unsafe-fixes because accepting subtypes changes behavior.
typeof(x) == Integer is false for every integer:
if typeof(x) == Integer
1
endwarning: typeof-comparison
--> example.jl:1:4
|
1 | if typeof(x) == Integer
| ^^^^^^^^^^^^^^^^^^^^ `typeof(x) == T` matches only the exact type; use `x isa T`, which includes subtypes
= help: Rewrite as an `isa` test (unsafe fix, requires `--unsafe-fixes`)shadowed-base-name
Report a call to a Base or Core function whose name has been hidden by a value binding. For example, after length = 3, a call to length(xs) tries to call the integer.
The rule requires both a binding and a call. Parameters, imports, function and type definitions, and assignments of visibly callable values are exempt.
The assignment masks Base's length, so the call fails:
length = 3
n = length(xs)warning: shadowed-base-name
--> example.jl:2:5
|
2 | n = length(xs)
| ^^^^^^ `length` here is this file's own binding, not Base's `length`A catch variable hiding error:
try
risky()
catch error
error("failed")
endwarning: shadowed-base-name
--> example.jl:4:5
|
4 | error("failed")
| ^^^^^ `error` here is this file's own binding, not Base's `error`non-public-access
Report access to a module member that is neither exported nor declared public. Internal names may change without notice. The rule follows these declarations even when a package documents an unexported name as part of its API.
The workspace package's own internals are allowed. Modules with no declared public API and modules using Reexport.jl are exempt.
Enabled by default for workspace package files. Other files require explicit selection and indexed libraries.
summarysize is part of Base's public API; unwrap_unionall is not:
Base.summarysize(x)
Base.unwrap_unionall(T)warning: non-public-access
--> example.jl:2:1
|
2 | Base.unwrap_unionall(T)
| ^^^^^^^^^^^^^^^^^^^^ `Base` does not export `unwrap_unionall` or declare it `public`Macros are checked in their own namespace:
Base.@_inline_metawarning: non-public-access
--> example.jl:1:1
|
1 | Base.@_inline_meta
| ^^^^^^^^^^^^^^^^^^ `Base` does not export `@_inline_meta` or declare it `public`test-bare-expression
Report a bare Test.@test argument with no comparison, Boolean operator, or predicate call, such as @test result. Calls and nested macros are allowed because they may return a Bool. The rule requires a visible Test import.
Disabled by default because bare Boolean values are valid assertions. No automatic fix is offered.
A test with a bare value:
using Test
@test resultwarning: test-bare-expression
--> example.jl:2:7
|
2 | @test result
| ^^^^^^ this assertion has no comparison or predicateeager-broadcast
Prefer sum(f, xs) to sum(f.(xs)) to avoid building an intermediate array. The rule also checks all, any, count, maximum, minimum, and prod. It matches a single broadcast argument with no keywords or splats.
The fix requires --unsafe-fixes: scalar inputs can behave differently, and any and all may stop early, changing how often f runs.
Summing without an intermediate array:
total = sum(abs.(residuals))warning: eager-broadcast
--> example.jl:1:9
|
1 | total = sum(abs.(residuals))
| ^^^^^^^^^^^^^^^^^^^^ use `sum(abs, residuals)` to avoid allocating the broadcast result
= help: Pass the function as `sum`'s first argument (unsafe fix, requires `--unsafe-fixes`)any need not test every element:
if any(isnan.(xs))
error("bad data")
endwarning: eager-broadcast
--> example.jl:1:4
|
1 | if any(isnan.(xs))
| ^^^^^^^^^^^^^^^ use `any(isnan, xs)` to avoid allocating the broadcast result
= help: Pass the function as `any`'s first argument (unsafe fix, requires `--unsafe-fixes`)sorted-extremum
Prefer minimum(xs) to sort(xs)[1] or sort(xs)[begin], and maximum(xs) to sort(xs)[end]. Finding an extreme takes one pass and avoids sorting the collection. Calls with sorting options such as rev, by, or lt are not checked.
The fix requires --unsafe-fixes: sorting places NaN last, while minimum and maximum propagate it.
Sorting to read the smallest element:
lowest = sort(scores)[1]warning: sorted-extremum
--> example.jl:1:10
|
1 | lowest = sort(scores)[1]
| ^^^^^^^^^^^^^^^ call `minimum(scores)` instead of `sort(scores)[1]`, which sorts the whole collection
= help: Replace the sorted indexing with `minimum` (unsafe fix, requires `--unsafe-fixes`)Sorting to read the largest element:
highest = sort(scores)[end]warning: sorted-extremum
--> example.jl:1:11
|
1 | highest = sort(scores)[end]
| ^^^^^^^^^^^^^^^^^ call `maximum(scores)` instead of `sort(scores)[end]`, which sorts the whole collection
= help: Replace the sorted indexing with `maximum` (unsafe fix, requires `--unsafe-fixes`)length-findall
Prefer count(p, xs) to length(findall(p, xs)) to avoid allocating a vector of matching indices. The one-argument form, length(findall(mask)), can use count(mask).
The fix requires --unsafe-fixes: findall tests dictionary values, while count tests key-value pairs.
Counting matching elements:
n = length(findall(isodd, xs))warning: length-findall
--> example.jl:1:5
|
1 | n = length(findall(isodd, xs))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ call `count(isodd, xs)` instead of `length(findall(isodd, xs))`, which builds an index vector just to count it
= help: Count the matches directly with `count` (unsafe fix, requires `--unsafe-fixes`)The one-argument form counts a mask:
hits = length(findall(mask))warning: length-findall
--> example.jl:1:8
|
1 | hits = length(findall(mask))
| ^^^^^^^^^^^^^^^^^^^^^ call `count(mask)` instead of `length(findall(mask))`, which builds an index vector just to count it
= help: Count the matches directly with `count` (unsafe fix, requires `--unsafe-fixes`)fixed-regex
Prefer a plain string to a regex that matches a fixed substring. For example, use occursin("abc", s) instead of occursin(r"abc", s).
The rule checks pattern arguments to occursin, contains, startswith, endswith, split, eachsplit, and replace, including curried forms. Patterns with flags, escapes, or regex metacharacters are excluded. The safe fix removes the r prefix.
Searching for a fixed substring:
if occursin(r"error", line)
push!(failures, line)
endwarning: fixed-regex
--> example.jl:1:13
|
1 | if occursin(r"error", line)
| ^^^^^^^^ use the string `"error"` for this literal pattern
= help: Drop the `r` prefix and match the substring (safe fix)After applying the fix:
if occursin("error", line)
push!(failures, line)
endSearching with a curried contains:
failures = filter(contains(r"error"), lines)warning: fixed-regex
--> example.jl:1:28
|
1 | failures = filter(contains(r"error"), lines)
| ^^^^^^^^ use the string `"error"` for this literal pattern
= help: Drop the `r` prefix and match the substring (safe fix)After applying the fix:
failures = filter(contains("error"), lines)Splitting on a fixed string:
fields = split(line, r"::")warning: fixed-regex
--> example.jl:1:22
|
1 | fields = split(line, r"::")
| ^^^^^ use the string `"::"` for this literal pattern
= help: Drop the `r` prefix and match the substring (safe fix)After applying the fix:
fields = split(line, "::")comparison-negation
Simplify negated equality tests: !(a == b) becomes a != b, and !(a === b) becomes a !== b. The reverse and Unicode forms are also checked.
Ordering comparisons are excluded because negating < is not equivalent to >= for values such as NaN. The safe fix preserves comments between operands and is withheld if it would discard a comment or change operator precedence.
Negating an equality comparison:
if !(status == :ok)
retry()
endwarning: comparison-negation
--> example.jl:1:4
|
1 | if !(status == :ok)
| ^^^^^^^^^^^^^^^^ write the comparison directly: `!(a == b)` is `a != b`
= help: Rewrite as `!=` (safe fix)After applying the fix:
if status != :ok
retry()
endNegating an identity comparison:
found = !(lookup(key) === nothing)warning: comparison-negation
--> example.jl:1:9
|
1 | found = !(lookup(key) === nothing)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ write the comparison directly: `!(a === b)` is `a !== b`
= help: Rewrite as `!==` (safe fix)After applying the fix:
found = lookup(key) !== nothinglength-zero
Prefer isempty(x) or !isempty(x) when a length comparison tests whether a collection is empty. This includes length(x) == 0, length(x) < 1, and their reversed forms.
The safe fix preserves the argument and is withheld if isempty is shadowed or a comment would be lost.
Testing whether a collection is empty:
if length(xs) == 0
println("nothing to do")
endwarning: length-zero
--> example.jl:1:4
|
1 | if length(xs) == 0
| ^^^^^^^^^^^^^^^ test `isempty(xs)` instead of comparing `length(xs)` to `0`
= help: Rewrite as an `isempty` test (safe fix)After applying the fix:
if isempty(xs)
println("nothing to do")
endTesting whether a collection is nonempty:
while 0 < length(queue)
pop!(queue)
endwarning: length-zero
--> example.jl:1:7
|
1 | while 0 < length(queue)
| ^^^^^^^^^^^^^^^^^ test `!isempty(queue)` instead of comparing `length(queue)` to `0`
= help: Rewrite as an `isempty` test (safe fix)After applying the fix:
while !isempty(queue)
pop!(queue)
endredundant-boolean
Simplify comparisons to Boolean literals and conditionals that return them. For example, x == true becomes x, and c ? false : true becomes !c.
The conditional fix is safe. The comparison fix requires --unsafe-fixes because the operand may have a type other than Bool: for example, 1 == true returns true, while 1 remains an integer.
Returning the condition directly:
ready = queue_started(q) ? true : falsewarning: redundant-boolean
--> example.jl:1:9
|
1 | ready = queue_started(q) ? true : false
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this conditional just yields `queue_started(q)`
= help: Replace the conditional with its test (safe fix)After applying the fix:
ready = queue_started(q)Comparing a value to false:
if x.valid == false
reject(x)
endwarning: redundant-boolean
--> example.jl:1:4
|
1 | if x.valid == false
| ^^^^^^^^^^^^^^^^ comparing to `false` is redundant: write `!x.valid`
= help: Drop the comparison to `false` (unsafe fix, requires `--unsafe-fixes`)string-boundary
Prefer startswith or endswith to a regex that tests a literal prefix or suffix. For example, occursin(r"^abc", s) becomes startswith(s, "abc"). The rule also checks contains, including its curried form. Patterns with flags or additional regex syntax are excluded.
The prefix fix is safe. The suffix fix requires --unsafe-fixes because regex $ also matches before a final newline, while endswith requires the suffix at the very end.
A leading anchor is a prefix test:
if occursin(r"^Test", name)
run(name)
endwarning: string-boundary
--> example.jl:1:4
|
1 | if occursin(r"^Test", name)
| ^^^^^^^^^^^^^^^^^^^^^^^^ test `startswith(name, "Test")` instead of matching the anchored regex `r"^Test"`
= help: Test the prefix with `startswith` (safe fix)After applying the fix:
if startswith(name, "Test")
run(name)
endA trailing anchor is a suffix test:
sources = filter(f -> occursin(r"_test$", f), files)warning: string-boundary
--> example.jl:1:23
|
1 | sources = filter(f -> occursin(r"_test$", f), files)
| ^^^^^^^^^^^^^^^^^^^^^^ test `endswith(f, "_test")` instead of matching the anchored regex `r"_test$"`
= help: Test the suffix with `endswith`, which does not match before a trailing newline (unsafe fix, requires `--unsafe-fixes`)Using a prefix test with filter:
sources = filter(contains(r"^src"), files)warning: string-boundary
--> example.jl:1:18
|
1 | sources = filter(contains(r"^src"), files)
| ^^^^^^^^^^^^^^^^^ test `startswith("src")` instead of matching the anchored regex `r"^src"`
= help: Test the prefix with `startswith` (safe fix)After applying the fix:
sources = filter(startswith("src"), files)unnecessary-nesting
Combine an if whose only statement is another if into one condition with &&. Neither if may have an elseif or else branch.
The safe fix preserves the inner body and adds parentheses where needed. It is withheld if a comment would be lost. Run the formatter afterward to adjust indentation.
Combining nested conditions:
if isopen(io)
if !eof(io)
read(io)
end
endwarning: unnecessary-nesting
--> example.jl:1:1
|
1 | if isopen(io)
| ^^^^^^^^^^^^^ this `if` only guards another `if`: write `if isopen(io) && !eof(io)`
= help: Merge the nested `if` into its parent with `&&` (safe fix)After applying the fix:
if isopen(io) && !eof(io)
read(io)
endtest-isa-call
Prefer @test value isa Type to @test isa(value, Type). The rule requires a visible Test import and offers a safe fix that preserves the operands and their precedence.
Using isa as an operator in a test:
using Test
@test isa(result, AbstractVector)warning: test-isa-call
--> example.jl:2:7
|
2 | @test isa(result, AbstractVector)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ write `result isa AbstractVector` instead of calling `isa`
= help: Rewrite as an `isa` comparison (safe fix)After applying the fix:
using Test
@test result isa AbstractVectormisnamed-suppression
Report a suppression comment that names an unknown rule. Rule IDs must match exactly, so a misspelled ID suppresses nothing. When there is a single close match, the safe fix corrects the ID and keeps the reason.
A directive naming a rule that does not exist:
# fatou-ignore unused-bindings: set up by the C library
function f()
handle = open_device()
1
endwarning: misnamed-suppression
--> example.jl:1:16
|
1 | # fatou-ignore unused-bindings: set up by the C library
| ^^^^^^^^^^^^^^^ `unused-bindings` is not a fatou rule; this suppresses nothing
= help: Replace with `unused-binding` (safe fix)After applying the fix:
# fatou-ignore unused-binding: set up by the C library
function f()
handle = open_device()
1
endblanket-suppression
Report a suppression comment with no rule ID. A bare # fatou-ignore-file disables every rule, including rules added later. A bare # fatou-ignore suppresses nothing. Name the specific rules to suppress.
A file suppression without a rule ID:
# fatou-ignore-file: generated code
struct Point
x::Float64
endwarning: blanket-suppression
--> example.jl:1:1
|
1 | # fatou-ignore-file: generated code
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ suppression names no rule; it silences every rule in this file
= help: name the rule: `# fatou-ignore <rule>: <reason>`unexplained-suppression
Require a reason in suppression comments: # fatou-ignore <rule>: <reason>.
Disabled by default because reasons are optional. Enable it to require an explanation for each suppression.
A suppression without a reason:
# fatou-ignore unused-binding
function f()
handle = open_device()
1
endwarning: unexplained-suppression
--> example.jl:1:1
|
1 | # fatou-ignore unused-binding
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ suppression states no reason
= help: add one: `# fatou-ignore <rule>: <reason>`outdated-suppression
Report a suppression comment that no longer suppresses a finding or has no code after it. Disabled rules and files whose names cannot be resolved reliably are not checked. The safe fix deletes the comment.
A directive at the end of a file, with nothing left to suppress:
function f(x)
x + 1
end
# fatou-ignore unused-binding: the scratch value belowwarning: outdated-suppression
--> example.jl:4:1
|
4 | # fatou-ignore unused-binding: the scratch value below
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ suppression has nothing after it to apply to
= help: delete the directive
= help: Delete the suppression (safe fix)After applying the fix:
function f(x)
x + 1
end
