Repository navigation
Future Rules
Date: 2025-10-30 Current Status: 430+ rules implemented Source: Extracted from ROADMAP_325.md
This document catalogs 300+ specific rule ideas for future implementation. These are organized by category and include "What", "Why", and "Example" for each rule.
Type: Code Smell
What: Detect f[x_] := ... without type restriction when type checking would help
Why: Runtime errors from wrong types
Example: f[x_] := x^2 should be f[x_?NumericQ] := x^2
Type: Bug
What: Detect incorrect use of ? vs /;
Why: Different evaluation semantics
Example: f[x_?IntegerQ] := x (correct) vs f[x_ /; IntegerQ[x]] := x (works but inefficient)
Type: Performance
What: Detect f[x__] := ... that could be f[x__Integer] := ...
Why: Performance and correctness
Type: Bug
What: Detect f[x_:1, y_:x] := ... (y default depends on x)
Why: Evaluation order issues
Type: Bug
What: Detect same pattern name used with different restrictions
Example: f[x_Integer, x_Real] := ... (impossible to match)
Type: Code Smell
What: Detect f[x_Integer | x_Real] := ... (redundant pattern name)
Why: Should be f[x:(_Integer | _Real)] := ...
Type: Performance
What: Detect x_?(# > 0 &) in hot code
Why: Creates closure on each match
Type: Bug
What: Detect optional arguments without sensible defaults
Example: f[x_, opts___] := ... (should validate opts)
Type: Bug
What: Detect when specific patterns defined after general ones
Example: f[x_] := ...; f[0] := ... (second never matches)
Type: Bug
What: Detect incorrect use of Verbatim
Why: Tricky semantics
Type: Code Smell
What: Detect HoldPattern where not needed
Why: Clutter
Type: Bug
What: Detect Longest[x__] without proper context
Why: May not work as expected
Type: Bug
What: Detect f[{x_, x_}] := ... expecting same value twice
Why: Should use f[{x_, y_} /; x == y] := ...
Type: Performance
What: Detect x:(a|b|c|d|e|f|g|h|...) with many alternatives
Why: Backtracking explosion
Type: Performance What: Detect pattern matching on lists with thousands of elements Why: Use other approaches (Select, Pick)
Type: Bug
What: Detect list[[1]] without checking Length[list] > 0
Why: Runtime error
Type: Bug
What: Detect list[[-n]] without checking n <= Length[list]
Why: Runtime error
Type: Bug
What: Detect list[[i]] = x where list isn't a variable
Why: Doesn't modify original
Type: Performance
What: Detect Join[list, {x}] in loop
Why: Quadratic complexity
Example: Use AppendTo or pre-allocate
Type: Performance
What: Detect Flatten[{a, b, c}] where already flat
Why: Wasted computation
Type: Performance
What: Detect Do[..., {i, 1, Length[list]}] recalculating length
Why: Cache length value
Type: Code Smell
What: Detect Reverse[Reverse[x]]
Why: No-op
Type: Performance
What: Detect Sort[list, Greater] when could use Reverse[Sort[list]]
Why: Built-in sort is optimized
Type: Performance
What: Detect Extract[list, Position[list, pattern]] → use Select
Why: Cleaner and faster
Type: Code Smell
What: Detect list[[i]][[j]] → use list[[i, j]]
Why: Cleaner syntax
Type: Bug
What: Detect assoc["key"] without checking KeyExistsQ
Why: Returns Missing["KeyAbsent", "key"]
Type: Bug
What: Detect list operations on associations
Example: Length[assoc] (correct) vs assoc[[1]] (wrong)
Type: Performance
What: Detect Select[Keys[assoc], pred] → use KeySelect
Why: Built-in is optimized
Type: Bug
What: Detect Query[...] on regular list
Why: Needs Dataset wrapper
Type: Code Smell
What: Detect assoc["key"] = value → use AssociateTo or Append
Why: Cleaner semantics
Type: Bug
What: Detect Merge[{a1, a2}] without specifying merge function
Why: Default may not be what you want
Type: Bug
What: Detect AssociateTo[expr, ...] where expr isn't a symbol
Why: Won't modify original
Type: Performance
What: Detect KeyDrop[KeyDrop[assoc, "a"], "b"] → KeyDrop[assoc, {"a", "b"}]
Why: Single pass
Type: Code Smell
What: Detect Lookup[assoc, key, Missing[]] (redundant)
Why: Missing is default
Type: Code Smell
What: Detect GroupBy where GatherBy more appropriate
Why: Semantic clarity
Type: Code Smell What: Detect private functions never called Why: Dead code
Type: Code Smell
What: Detect Module[{x, y}, ...] where y never used
Why: Clutter
Type: Code Smell What: Similar to Module but for With Why: With variables are constants, unused is clearer mistake
Type: Code Smell
What: Detect f[x_, y_] := x (y not used)
Why: Should be f[x_, _] := x
Type: Code Smell What: Detect optional param never used even when provided Why: Confusing API
Type: Bug
What: Detect code after Return[] in same scope
Why: Never executes
Severity: Major
Type: Bug
What: Detect code after Abort[] or Throw[]
Why: Never executes
Type: Code Smell
What: Detect x = value where x never read before next assignment
Why: Useless work
Type: Code Smell What: Global-scope function never called Why: Dead code (may be API)
Type: Bug
What: Detect x = 1; x = 2 where first value never used
Why: Logic error
Type: Code Smell
What: Detect Do[..., {i, 1, 10}] where i never used in body
Why: Use Do[..., 10] form
Type: Code Smell
What: Detect Catch[...] where no Throw in body
Why: Unnecessary
Type: Bug
What: Detect If[False, ...] or pattern /; False
Why: Dead code or logic error
Type: Bug
What: Detect code after Return[] that can never execute
Why: Dead code
Type: Bug
What: Detect If[True, a, b] where b is unreachable
Why: Dead code or logic error
Type: Code Smell
What: Detect Module[{x}, ...] when x is global variable
Why: Confusing, may be unintended
Type: Bug
What: Detect f[List_] := ... (shadows built-in)
Why: Won't work as expected
Severity: Major
Type: Bug
What: Detect f[x_] := Module[{x}, ...]
Why: Confusing, probably error
Type: Code Smell What: Detect function redefined multiple times Why: May be intentional (patterns) or error
Type: Code Smell What: Detect single-letter variable names in large functions Why: Readability
Type: Code Smell What: Detect variables longer than 50 characters Why: Readability
Type: Code Smell What: Detect mix of camelCase, snake_case, PascalCase Why: Consistency
Type: Code Smell
What: Detect Module[{Map, Apply}, ...] (shadowing built-ins)
Why: Confusing
Type: Bug What: Detect symbol defined in multiple contexts Why: Ambiguity
Type: Bug What: Detect use of $SystemID, $Version, etc. as variable names Why: Can cause issues
Type: Code Smell
What: Detect symbols in Private context used outside package
Why: Breaks encapsulation
Type: Bug
What: Detect BeginPackage without matching EndPackage
Why: Context corruption
Severity: Critical
Type: Bug
What: Detect definitions after EndPackage[]
Why: Wrong context
Type: Code Smell
What: Detect use of Global context in package code
Why: Should use package context
Type: Code Smell
What: Detect variables named temp, tmp used multiple times
Why: Should have better names
Type: Bug
What: Detect "hello" + 1 or "hello"^2
Why: Runtime error or unexpected result
Severity: Major
Type: Bug
What: Detect StringJoin[123, "abc"] (wrong arg type)
Why: Runtime error
Type: Bug
What: Detect Map[f, 123] (expects list)
Why: Runtime error
Type: Bug What: Detect function declared to return Integer but returns String Why: Contract violation
Type: Bug
What: Detect "hello" < 5 (doesn't error but meaningless)
Why: Logic error
Type: Code Smell What: Detect mix of exact and approximate in same calculation Why: Precision loss
Type: Bug
What: Detect 1/2 in numeric context (evaluates symbolically)
Why: Use 1./2 for numeric
Type: Bug
What: Detect Append[assoc, elem] (should use AssociateTo)
Why: Different semantics
Type: Bug
What: Detect f[x_Integer] := ...; f["hello"] call
Why: Won't match, returns unevaluated
Type: Bug
What: Detect f[x_Integer:1.5] := ... (default wrong type)
Why: Default should match pattern type
Type: Code Smell What: Detect function that sometimes returns Integer, sometimes String Why: Confusing API
Type: Bug
What: Detect x = Null where x expected to be Integer
Why: Type violation
Type: Bug
What: Detect use of ToExpression[str] without checking StringQ
Why: May fail
Type: Code Smell
What: Detect ToString[x] <> y where x already String
Why: Redundant
Type: Bug
What: Detect Plot[...] + 1
Why: Doesn't make sense
Type: Bug
What: Detect x + 1 where x is symbolic and expected numeric
Why: Won't evaluate
Type: Bug
What: Detect ImageData[list] (expects Image object)
Why: Runtime error
Type: Bug
What: Detect AudioData[list] (expects Audio object)
Why: Runtime error
Type: Bug What: Detect Dataset operations on regular lists Why: Needs Dataset wrapper
Type: Bug
What: Detect VertexList[list] (expects Graph)
Why: Runtime error
Type: Bug What: Detect variable used before any definition (data flow based) Why: Runtime error or wrong value Severity: Critical
Type: Bug What: Detect variable initialized in some branches but not all Why: Logic error
Type: Code Smell
What: Detect x = value where value never read
Why: Useless computation
Type: Code Smell
What: Detect x = 1; x = 2 where first value never used
Why: First assignment wasted
Type: Bug What: Detect when two variables point to same mutable structure Why: Unexpected modifications
Type: Bug
What: Detect Do[...; i = i+1; ..., {i, 1, 10}] (modifying iterator)
Why: Confusing, may not work as expected
Type: Bug What: Detect use of loop iterator after loop ends (value undefined) Why: Iterator value after loop is implementation detail
Type: Bug
What: Detect read of variable after Unset[x] or Clear[x]
Why: Returns Symbol, not value
Type: Code Smell
What: Detect x = 5; ...; x = 5 (same value)
Why: Redundant
Type: Bug What: Detect mutation of outer variable in pure function Why: Side effect, confusing
Type: Bug What: Detect global mutable state accessed from multiple functions Why: Hard to reason about
Type: Bug
What: Detect Module[{x}, x] returning local variable
Why: Variable leaks (as Symbol)
Type: Bug What: Detect pure function capturing variable that changes Why: May not capture expected value
Type: Bug
What: Detect If[x = 5, ...] (should be x == 5)
Why: Always true, side effect
Severity: Critical
Type: Code Smell
What: Detect f[x_] := (y = x; y) (unnecessary variable)
Why: Could be f[x_] := x
Type: Code Smell
What: Detect Module[{x = 1}, ...; Return[x]] where x never modified
Why: Could use With for immutability
Type: Bug What: Detect loop with no exit condition (CFG-based) Why: Hangs Severity: Critical
Type: Bug
What: Detect While[False, ...] or Do[..., {i, 10, 1}]
Why: Dead code
Type: Bug
What: Detect code after Abort[]
Why: Never executes
Type: Code Smell What: Detect early returns leaving later code unreachable Why: Dead code
Type: Vulnerability
What: Detect tainted data flowing to SQLExecute[]
Why: Database compromise
Severity: Critical
Type: Vulnerability
What: Detect tainted data flowing to RunProcess[], Run[]
Why: System compromise
Severity: Critical
Type: Vulnerability
What: Detect tainted data flowing to ToExpression[]
Why: Arbitrary code execution
Severity: Critical
Type: Vulnerability
What: Detect tainted data in file paths: Import[untrusted]
Why: Unauthorized file access
Severity: Critical
Type: Vulnerability
What: Detect tainted data in XMLElement[], ExportString[..., "HTML"]
Why: Client-side code injection
Severity: Critical
Type: Vulnerability What: Detect tainted data in LDAP queries Why: Authentication bypass Severity: Critical
Type: Vulnerability What: Detect unsafe XML parsing with external entities enabled Why: Information disclosure Severity: Critical
Type: Vulnerability
What: Detect Import[untrusted, "MX"] or Get[untrusted]
Why: Arbitrary code execution
Severity: Critical
Type: Vulnerability
What: Detect tainted URLs in URLFetch[], URLExecute[]
Why: Internal network access
Severity: Critical
Type: Vulnerability
What: Detect RandomInteger[] used for security-sensitive values
Why: Predictable
Severity: Major
Type: Vulnerability What: Detect use of MD5, SHA1 for security purposes Why: Broken algorithms Severity: Major
Type: Vulnerability What: Detect string literals flowing to authentication Why: Credential leak Severity: Critical
Type: Vulnerability
What: Detect tainted data from authentication flowing to Print[], logging
Why: Information disclosure
Severity: Major
Type: Vulnerability What: Detect tainted association directly used in database update Why: Privilege escalation Severity: Critical
Type: Vulnerability What: Detect tainted data in regex patterns (catastrophic backtracking) Why: Denial of service Severity: Major
Type: Bug
What: Detect Switch without default case
Why: May return unevaluated
Type: Code Smell
What: Detect If[cond, , else] (empty true branch)
Why: Confusing, use If[!cond, else]
Type: Code Smell What: Detect deeply nested If statements (>4 levels) Why: Complexity
Type: Code Smell What: Detect function with >5 return statements Why: Hard to reason about
Type: Code Smell
What: Detect If[cond, action] that should have else
Why: Unclear intent
Type: Bug What: Detect A.m needs B.m needs A.m Why: Load order issues Severity: Critical
Type: Code Smell
What: Detect Needs["Package"]` where no symbols from Package used
Why: Unnecessary dependency
Type: Bug What: Detect use of symbol from package without Needs Why: May fail in fresh kernel Severity: Major
Type: Code Smell What: Detect reliance on transitive import Why: Fragile
Type: Code Smell What: Detect A depends on B and C, both depend on D Why: Version conflicts
Type: Code Smell What: Detect package that depends on >10 other packages Why: High coupling
Type: Bug What: Detect library package depending on application-specific code Why: Wrong dependency direction
Type: Code Smell What: Detect PackageA calls PackageB calls PackageA Why: Tight coupling
Type: Code Smell What: Detect lower layer depending on higher layer Why: Architectural violation
Type: Code Smell What: Detect stable package depending on unstable package Why: Ripple effects
Type: Code Smell What: Detect package with >3000 lines Why: Should be split
Type: Code Smell What: Detect package with <50 lines Why: Over-modularization
Type: Code Smell What: Detect package names not following convention Why: Consistency
Type: Code Smell What: Detect package with >50 public symbols Why: Poor cohesion
Type: Code Smell What: Detect package with 0-1 public symbols Why: Questionable design
Type: Code Smell What: Detect public function relying on private function Why: Breaks encapsulation
Type: Bug What: Detect symbol in Private` context used from another package Why: Breaks encapsulation
Type: Code Smell What: Detect "Internal`" symbols used from outside Why: Unstable API
Type: Code Smell What: Detect package without top-level usage message Why: Discoverability
Type: Code Smell What: Detect breaking changes to public symbols Why: Semantic versioning
Type: Bug What: Detect operations on potentially null values Why: Runtime error Severity: Major
Type: Bug What: Detect function result used without checking for $Failed Why: Error propagation
Type: Code Smell What: Detect function that can return Null without documenting it Why: API surprise
Type: Bug
What: Detect x == Null (should use x === Null)
Why: Semantic difference
Type: Bug What: Detect chain where null propagates through multiple operations Why: Error cascade
Type: Bug
What: Detect Check[expr, fallback] missing some error cases
Why: Incomplete error handling
Type: Bug
What: Detect Quiet[...] suppressing critical messages
Why: Masks real errors
Type: Bug
What: Detect Off[General::...] for important warnings
Why: Masks problems
Type: Bug
What: Detect Catch[expr] catching all tags
Why: Too broad
Type: Bug
What: Detect Catch[expr, _, Null &] (silently ignoring errors)
Why: Error information lost
Type: Bug
What: Detect Throw[...] with no surrounding Catch
Why: Will abort evaluation
Type: Bug
What: Detect Abort[] in public library function
Why: Too aggressive, should return error
Type: Bug
What: Detect message issued but not defined: Message[f::undefined]
Why: Generic message shown
Type: Code Smell What: Detect function issuing messages without defining them first Why: Unclear error messages
Type: Bug
What: Detect Break[] outside loop context
Why: Runtime error
Severity: Critical
Type: Bug
What: Detect If[True, ...] from constant propagation
Why: Dead branch or logic error
Type: Bug
What: Detect If[False, ...] from constant propagation
Why: Dead branch or logic error
Type: Code Smell
What: Detect Do[..., {i, 1, x}] where x is constant
Why: Use literal value
Type: Performance What: Detect same expression computed multiple times with same inputs Why: Could cache result
Type: Performance What: Detect pure (side-effect-free) expression computed in every iteration Why: Hoist outside loop
Type: Code Smell
What: Detect x + 0, x * 1, x^1
Why: Simplify to x
Type: Code Smell
What: Detect Reverse[Reverse[x]], Transpose[Transpose[x]]
Why: No-op
Type: Bug
What: Detect x == x (always true)
Why: Logic error or typo
Type: Bug
What: Detect x || !x (tautology)
Why: Logic error
Type: Bug
What: Detect x && !x (contradiction)
Why: Logic error
Type: Code Smell
What: Detect If[cond, True, False] (should just be cond)
Why: Redundant
Type: Code Smell
What: Detect !!x or Not[Not[x]]
Why: Simplify to x
Type: Code Smell What: Detect boolean expression with >5 operators Why: Hard to understand
Type: Code Smell
What: Detect !(a && b) (could be !a || !b)
Why: Clarity
Type: Bug
What: Detect list[[100]] where list has <100 elements
Why: Runtime error
Severity: Critical
Type: Bug What: Detect function manipulating unevaluated expressions without Hold attribute Why: Arguments will evaluate
Type: Bug What: Detect function with HoldFirst that evaluates second arg first Why: Unexpected evaluation order
Type: Bug What: Detect passing expression to held parameter without Unevaluated Why: Premature evaluation
Type: Code Smell
What: Detect Hold[literal] where literal doesn't evaluate
Why: Redundant
Type: Code Smell
What: Detect ReleaseHold[Hold[x]]
Why: Redundant
Type: Bug
What: Detect Hold[..., Evaluate[x], ...] (evaluation leak)
Why: May not be intended
Type: Bug
What: Detect pattern test with side effects: x_?(Print[#]; True &)
Why: Evaluated multiple times
Type: Bug What: Detect replacement rules where order affects result Why: Non-deterministic behavior
Type: Bug
What: Detect /. list where Replace[..., list, {1}] intended
Why: Different semantics
Type: Bug What: Detect rule that won't match due to evaluation timing Why: Subtle bug
Type: Bug
What: Detect list[[10;;1]] (backwards span)
Why: Empty result
Type: Performance
What: Detect list[[All]] (redundant, just use list)
Why: Unnecessary operation
Type: Bug What: Detect function with Listable attribute called on non-list Why: Unexpected result
Type: Code Smell What: Detect function that should have Listable but doesn't Why: Performance opportunity
Type: Bug What: Detect OneIdentity on function where it causes issues Why: Subtle semantic change
Type: Bug What: Detect Orderless on non-commutative operation Why: Wrong semantics Severity: Critical
Type: Bug What: Detect Flat on non-associative operation Why: Wrong semantics Severity: Critical
Type: Bug
What: Detect Sequence[...] flattening where not intended
Why: Lost structure
Type: Bug
What: Detect place where Sequence[] should be used but isn't
Why: Extra nesting
Type: Bug What: Detect pattern that can never match Why: Dead code
Type: Performance
What: Suggest Compile[] for suitable functions
Why: 10-100x speedup potential
Type: Performance
What: Detect Compile[..., CompilationTarget -> "MVM"] (should be "C")
Why: C compilation much faster
Type: Bug
What: Detect use of non-compilable functions in Compile[]
Why: Falls back to slow evaluation
Type: Performance What: Detect operations that unpack packed arrays Why: 10-100x slower Severity: Major
Type: Performance What: Detect complex patterns in hot loops Why: Pattern matching is slow
Type: Performance
What: Detect symbolic computation followed by N[]
Why: Do numeric from start
Type: Performance What: Detect recursive function without memoization Why: Exponential time complexity
Type: Performance
What: Detect repeated <> in loop
Why: Quadratic complexity
Type: Performance
What: Detect Join[list, {x}] in loop
Why: Quadratic complexity
Type: Bug What: Detect call to function not defined or imported Why: Runtime error Severity: Critical
Total Rule Ideas: 300+
By Category:
- Pattern System: 15 rules
- List/Array: 10 rules
- Association: 10 rules
- Unused Code: 15 rules
- Shadowing & Naming: 15 rules
- Type Mismatch: 20 rules
- Data Flow: 20 rules
- Security: 20 rules
- Cross-File/Architecture: 20 rules
- Null Safety: 15 rules
- Constant/Expression: 15 rules
- Mathematica-Specific: 20 rules
- Performance: 10 rules
- Additional semantic rules: 95+
By Severity:
- Critical: ~50 rules
- Major: ~100 rules
- Minor/Code Smell: ~150 rules
Implementation Notes:
- Many of these rules require the infrastructure that's already in place (AST, Symbol Table, Type System, Data Flow, CFG)
- Rules should be prioritized based on:
- User impact (how many bugs will this catch?)
- False positive rate (will users trust this rule?)
- Implementation complexity
- Performance impact on scan time
Next Steps: See ROADMAP.md for implementation priorities and phases.