Alpha. Vary is under active development and not ready for production use. Syntax, APIs, performance, and behaviour may change between releases.
Check rules: idioms
Idioms
VCI001 none-comparison
Use 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.
VCI002 bool-return
Avoid 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)
}
VCI003 exit-in-logic
Avoid 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)
}
VCI004 shallow-observe
Avoid 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
VCI005 string-enum-smell
Data 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
}
VCI017 stale-workaround-comment
Comments 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.
VCI018 nested-none-guards
Three 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
VCI019 guard-then-unwrap
A 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
VCI020 optional-if-map
if 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)
VCI021 never-candidate
A 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)
VCI022 sentinel-for-missing
A 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)