none-comparisonUse is None / is not None instead of == None / != None.
Severity: suggestion | Auto-fix: yes
let x: Str? = None
# Before
if x == None {
print("missing")
}
# After (fixed)
if x is None {
print("missing")
}
is None expresses nil identity explicitly and avoids generic equality phrasing.
bool-returnAvoid bare Bool return types on non-trivial functions.
Severity: suggestion | Auto-fix: no
# Flagged
def check_site(pages: List[Str]) -> Bool {
for p in pages {
if not fs.exists(fs.path(p)) {
return False
}
}
return True
}
A Bool hides what was checked, what failed, and what was skipped. Return a structured data type instead:
data CheckReport {
success: Bool
issues: List[Str]
checked_files: List[Str]
}
def check_site(pages: List[Str]) -> CheckReport {
mut issues: List[Str] = []
for p in pages {
if not fs.exists(fs.path(p)) {
issues = issues + ["missing: " + p]
}
}
return CheckReport(len(issues) == 0, issues, pages)
}
exit-in-logicAvoid calling exit() inside non-main functions.
Severity: warning | Auto-fix: no
import fs
import process
# Flagged
def validate(path: Str) {
if not fs.exists(fs.path(path)) {
process.exit(1)
}
}
Move process termination to the CLI layer and return structured errors from inner logic:
import fs
def validate(path: Str) -> Result[Str, Str] {
if not fs.exists(fs.path(path)) {
return Err("file not found: " + path)
}
return Ok(path)
}
shallow-observeAvoid shallow observe statements that are too weak to kill mutants.
Severity: suggestion | Auto-fix: no
Detected patterns:
observe result is not None # only checks existence
observe result == True # only checks a boolean
observe x # bare identifier
Replace with field-level assertions:
observe report.success == True
observe report.issues.len() == 0
observe report.checked_files.len() == 5
string-enum-smellData class Str fields named kind, mode, type, status, strategy, category, level, state, severity, stage, phase, role, action, or variant suggest a finite set of values that should be an enum.
Severity: suggestion | Auto-fix: no
# Flagged
data Issue {
kind: Str
message: Str
}
# Better
enum IssueKind {
BrokenLink
MissingFile
InvalidConfig
}
data Issue2 {
kind: IssueKind
message: Str
}
stale-workaround-commentComments containing workaround language (workaround, hack, temporary, fixme) may reference code that has already been fixed. The rule warns on every such comment so you can verify the workaround is still needed.
Severity: warning | Auto-fix: no
# Flagged
# workaround: retry once because the upstream service 500s intermittently
for _ in 0..2 {
let result = fetch()
if result.is_ok() { return result }
}
Either delete the comment (and simplify the code) if the upstream bug is fixed, or rewrite the comment to explain the lasting reason.
nested-none-guardsThree or more nested is not None checks. Use let ... else to unwrap the values on one level with one failure branch.
Severity: suggestion | Auto-fix: no
guard-then-unwrapA let followed by an if x is None { <exit> } guard on the next line. Join them with ?:.
Severity: suggestion | Auto-fix: yes (adjacent lines, one exit statement, no type annotation on the let)
# Before
let n = find(id)
if n is None {
return -1
}
# After (fixed)
let n = find(id) ?: return -1
optional-if-mapif x is not None { f(x) } else { None } is x.map(f), or x.and_then(f) when f returns an optional. if x is not None and p(x) { x } else { None } is x.filter(p).
Severity: suggestion | Auto-fix: yes (the one-line expression form with a plain function name)
# Before
return if x is not None { double(x) } else { None }
# After (fixed)
return x.map(double)
never-candidateA function whose every path raises or calls exit or another Never function, but whose return type is not Never. Declaring -> Never lets the checker treat a call to it as the end of the block.
Severity: suggestion | Auto-fix: yes (one-line signature, no out or post block)
sentinel-for-missingA lookup-shaped function (find_*, lookup_*, get_*, parse_* and similar) that returns -1 or "" for "not found" next to real values. Return Int? or Str? and None instead, so callers must handle the missing case.
Severity: suggestion | Auto-fix: no (the callers change too)