use std::collections::HashMap;
use super::rule_registry::RuleMetadata;
use super::shell_compatibility::ShellCompatibility;
const RULES: &[(&str, &str, ShellCompatibility)] = &[
("SC1007", "Remove space after = in variable assignment", ShellCompatibility::Universal),
("SC1009", "Comment detected where command was expected", ShellCompatibility::Universal),
("SC1017", "Literal carriage return in source", ShellCompatibility::Universal),
("SC1018", "Unicode non-breaking space used", ShellCompatibility::Universal),
("SC1020", "Missing space before closing ]", ShellCompatibility::Universal),
("SC1035", "Missing space after keyword", ShellCompatibility::Universal),
("SC1068", "Don't put spaces around = in assignments", ShellCompatibility::Universal),
("SC1069", "Missing space before [ in test", ShellCompatibility::Universal),
("SC1082", "UTF-8 BOM detected", ShellCompatibility::Universal),
("SC1095", "Space between function name and () with function keyword", ShellCompatibility::NotSh),
("SC1099", "Missing space before # comment", ShellCompatibility::Universal),
("SC1100", "Unicode dash used instead of minus", ShellCompatibility::Universal),
("SC1101", "Trailing spaces after \\ line continuation", ShellCompatibility::Universal),
("SC1109", "Unquoted HTML entity in script", ShellCompatibility::Universal),
("SC1129", "Missing space before ! in negation", ShellCompatibility::Universal),
("SEC001", "Command injection vulnerability", ShellCompatibility::Universal),
("SEC002", "Unsafe eval usage", ShellCompatibility::Universal),
("SEC003", "Unquoted variables (injection risk)", ShellCompatibility::Universal),
("SEC004", "User input in commands", ShellCompatibility::Universal),
("SEC005", "Unsafe PATH modification", ShellCompatibility::Universal),
("SEC006", "Dangerous rm patterns", ShellCompatibility::Universal),
("SEC007", "Insecure temp file creation", ShellCompatibility::Universal),
("SEC008", "Source untrusted files", ShellCompatibility::Universal),
("DET001", "$RANDOM usage (non-deterministic)", ShellCompatibility::Universal),
("DET002", "Timestamp usage (non-deterministic)", ShellCompatibility::Universal),
("DET003", "Wildcard ordering (non-deterministic)", ShellCompatibility::Universal),
("IDEM001", "mkdir without -p (non-idempotent)", ShellCompatibility::Universal),
("IDEM002", "rm without -f (non-idempotent)", ShellCompatibility::Universal),
("IDEM003", "ln without -sf (non-idempotent)", ShellCompatibility::Universal),
("SC2039", "Bash features undefined in POSIX sh", ShellCompatibility::NotSh),
("SC2198", "Array syntax (bash-specific)", ShellCompatibility::NotSh),
("SC2199", "Array expansion (bash-specific)", ShellCompatibility::NotSh),
("SC2200", "Array iteration (bash-specific)", ShellCompatibility::NotSh),
("SC2201", "Array assignment (bash-specific)", ShellCompatibility::NotSh),
("SC2002", "Useless cat (can use process substitution in bash/zsh)", ShellCompatibility::NotSh),
("SC2108", "In [[ ]], use && instead of -a", ShellCompatibility::NotSh),
("SC2109", "In [[ ]], use || instead of -o", ShellCompatibility::NotSh),
("SC2110", "Don't mix && and || with -a and -o in [[ ]]", ShellCompatibility::NotSh),
("SC2111", "'function' keyword not supported in sh", ShellCompatibility::NotSh),
("SC2112", "'function' keyword is non-standard", ShellCompatibility::NotSh),
("SC2113", "'function' keyword with () is redundant", ShellCompatibility::NotSh),
("SC2003", "expr is antiquated. Use $((...))", ShellCompatibility::Universal),
("SC2004", "$/${} unnecessary on arithmetic variables", ShellCompatibility::Universal),
("SC2079", "Decimals not supported in (( ))", ShellCompatibility::Universal),
("SC2080", "Leading zero interpreted as octal", ShellCompatibility::Universal),
("SC2084", "Arithmetic expansion as command", ShellCompatibility::Universal),
("SC2085", "Local variable with arithmetic", ShellCompatibility::Universal),
("SC2133", "Unexpected tokens in arithmetic expansion", ShellCompatibility::Universal),
("SC2134", "Use (( )) for numeric tests", ShellCompatibility::Universal),
("SC2137", "Unnecessary braces in arithmetic", ShellCompatibility::Universal),
("SC2030", "Variable modified in subshell", ShellCompatibility::Universal),
("SC2031", "Variable was modified in subshell", ShellCompatibility::Universal),
("SC2032", "Variable in script with shebang", ShellCompatibility::Universal),
("SC2087", "Quote variables in sh -c", ShellCompatibility::Universal),
("SC2088", "Tilde expansion in quotes", ShellCompatibility::Universal),
("SC2089", "Quotes in assignment treated literally", ShellCompatibility::Universal),
("SC2090", "Quotes in expansion treated literally", ShellCompatibility::Universal),
("SC2091", "Remove $() to avoid executing output", ShellCompatibility::Universal),
("SC2092", "Remove backticks to avoid executing output", ShellCompatibility::Universal),
("SC2093", "Remove exec if script should continue", ShellCompatibility::Universal),
("SC2038", "Use -print0/-0 or find -exec instead of for loop over find", ShellCompatibility::Universal),
("SC2040", "Avoid passing -o to other commands (shell option confusion)", ShellCompatibility::Universal),
("SC2041", "Use while read, not read in for loop", ShellCompatibility::Universal),
("SC2042", "Use printf instead of echo with backslash escapes", ShellCompatibility::Universal),
("SC2043", "This loop will only run once (for x in y without wildcards)", ShellCompatibility::Universal),
("SC2044", "For loops over find: use find -exec or process substitution", ShellCompatibility::NotSh),
("SC2045", "Iterating over ls output is fragile", ShellCompatibility::Universal),
("SC2046", "Quote to prevent word splitting (CRITICAL)", ShellCompatibility::Universal),
("SC2047", "Quote variables in [ ] to prevent word splitting", ShellCompatibility::Universal),
("SC2048", "Use \"$@\" (with quotes) to prevent word splitting", ShellCompatibility::Universal),
("SC2049", "Use =~ for regex matching (not = in [ ])", ShellCompatibility::Universal),
("SC2050", "This expression is constant (forgot $ on variable?)", ShellCompatibility::Universal),
("SC2051", "Bash doesn't expand variables in brace ranges {$a..$b}", ShellCompatibility::Universal),
("SC2052", "Use [[ ]] instead of [ ] for glob patterns", ShellCompatibility::NotSh),
("SC2053", "Quote RHS of = in [ ] to prevent glob matching", ShellCompatibility::Universal),
("SC2054", "Comma is just literal in [[ ]]; use array or separate comparison", ShellCompatibility::Universal),
("SC2055", "Deprecated -a operator in test (use &&)", ShellCompatibility::Universal),
("SC2056", "Deprecated -o operator in test (use ||)", ShellCompatibility::Universal),
("SC2057", "Unknown binary operator (===, =!, <>)", ShellCompatibility::Universal),
("SC2058", "Unknown unary operator in test", ShellCompatibility::Universal),
("SC2059", "Printf format string injection (CRITICAL security)", ShellCompatibility::Universal),
("SC2060", "Unquoted tr parameters (glob expansion)", ShellCompatibility::Universal),
("SC2061", "Quote parameters to tr to prevent globbing", ShellCompatibility::Universal),
("SC2062", "Grep pattern glob expansion prevention", ShellCompatibility::Universal),
("SC2063", "Grep regex vs literal string matching", ShellCompatibility::Universal),
("SC2064", "Trap command quoting (P0 - timing issue)", ShellCompatibility::Universal),
("SC2065", "Shell redirection interpretation in strings", ShellCompatibility::Universal),
("SC2066", "Missing semicolon before done in for loop", ShellCompatibility::Universal),
("SC2067", "Missing $ on array lookup", ShellCompatibility::Universal),
("SC2068", "Quote $@ to prevent word splitting", ShellCompatibility::Universal),
("SC2069", "To redirect stdout+stderr, use &> or 2>&1, not 1>&2", ShellCompatibility::Universal),
("SC2070", "-n doesn't work with unquoted arguments", ShellCompatibility::Universal),
("SC2071", "Arithmetic operators don't work in [ ]. Use [[ ]] or (( ))", ShellCompatibility::Universal),
("SC2072", "Lexicographic comparison in [ ]. Use -lt/-gt for numbers", ShellCompatibility::Universal),
("SC2073", "Escape \\d in character class or use [[:digit:]]", ShellCompatibility::Universal),
("SC2074", "Can't use =~ in [ ]. Use [[ ]] instead", ShellCompatibility::Universal),
("SC2075", "Escaping quotes in single quotes doesn't work", ShellCompatibility::Universal),
("SC2076", "Don't quote RHS of =~ in [[ ]]", ShellCompatibility::Universal),
("SC2077", "Quote regex argument to prevent word splitting", ShellCompatibility::Universal),
("SC2078", "This expression is constant (forgot $ on variable?)", ShellCompatibility::Universal),
("SC2081", "Escape [ in globs or use [[ ]]", ShellCompatibility::Universal),
("SC2082", "Variable indirection with $$ (use ${!var})", ShellCompatibility::Universal),
("SC2083", "Don't add spaces after shebang", ShellCompatibility::Universal),
("SC2094", "Don't use same file for input and output (will truncate)", ShellCompatibility::Universal),
("SC2095", "ssh -t/-T in loops may consume stdin", ShellCompatibility::Universal),
("SC2096", "Use #! shebang, not just # comment", ShellCompatibility::Universal),
("SC2097", "Assign and use variable separately", ShellCompatibility::Universal),
("SC2098", "Variable assignment vs redirection confusion", ShellCompatibility::Universal),
("SC2103", "cd without error check (use cd ... || exit)", ShellCompatibility::Universal),
("SC2104", "In [[ ]], == is literal. Use = or [[ ]]", ShellCompatibility::Universal),
("SC2105", "Break outside loop", ShellCompatibility::Universal),
("SC2107", "Instead of [ a -o b ], use [ a ] || [ b ]", ShellCompatibility::Universal),
("SC2114", "Dangerous rm -rf without validation ($VAR might be empty)", ShellCompatibility::Universal),
("SC2115", "Use ${var:?} to ensure var is set before rm -rf", ShellCompatibility::Universal),
("SC2116", "Useless echo $(cmd) - just use cmd", ShellCompatibility::Universal),
("SC2128", "Expanding array without index in bash", ShellCompatibility::NotSh),
("SC2001", "Use ${var//pattern/replacement} instead of sed", ShellCompatibility::Universal),
("SC2005", "Useless echo instead of bare command", ShellCompatibility::Universal),
("SC2006", "Use $(...) instead of deprecated backticks", ShellCompatibility::Universal),
("SC2007", "Use $((..)) instead of deprecated expr", ShellCompatibility::Universal),
("SC2008", "echo doesn't read from stdin", ShellCompatibility::Universal),
("SC2009", "Consider using pgrep instead of grepping ps output", ShellCompatibility::Universal),
("SC2010", "Don't use ls | grep, use glob or find", ShellCompatibility::Universal),
("SC2011", "Use find -print0 | xargs -0 instead of ls | xargs", ShellCompatibility::Universal),
("SC2012", "Use find instead of ls for non-alphanumeric filenames", ShellCompatibility::Universal),
("SC2013", "To read lines, pipe/redirect to 'while read' loop", ShellCompatibility::Universal),
("SC2014", "Variables don't expand before brace expansion", ShellCompatibility::Universal),
("SC2015", "Note && and || precedence (use explicit grouping)", ShellCompatibility::Universal),
("SC2016", "Expressions don't expand in single quotes", ShellCompatibility::Universal),
("SC2017", "Increase precision by replacing bc/awk with arithmetic", ShellCompatibility::Universal),
("SC2018", "Use [:upper:] instead of [A-Z] for tr", ShellCompatibility::Universal),
("SC2019", "Use [:lower:] instead of [a-z] for tr", ShellCompatibility::Universal),
("SC2020", "tr replaces sets of chars, not strings", ShellCompatibility::Universal),
("SC2021", "Don't use [] around classes in tr", ShellCompatibility::Universal),
("SC2022", "Note: set -x only affects the current shell", ShellCompatibility::Universal),
("SC2023", "Brace expansion doesn't happen in [[ ]]", ShellCompatibility::Universal),
("SC2024", "sudo only affects the command, not the redirection", ShellCompatibility::Universal),
("SC2025", "Note: set -e only affects the current shell", ShellCompatibility::Universal),
("SC2026", "Word splitting occurs in the variable", ShellCompatibility::Universal),
("SC2027", "Quote or escape $ in double quotes", ShellCompatibility::Universal),
("SC2028", "echo may not expand \\n (use printf)", ShellCompatibility::Universal),
("SC2029", "Variables must be local in remote SSH command", ShellCompatibility::Universal),
("SC2086", "CRITICAL: Quote to prevent word splitting and globbing", ShellCompatibility::Universal),
("SC2033", "Shell functions can't be exported (use scripts or ENV)", ShellCompatibility::Universal),
("SC2034", "Variable appears unused (verify with shellcheck)", ShellCompatibility::Universal),
("SC2035", "Use ./*glob* or -- *glob* to match files starting with -", ShellCompatibility::Universal),
("SC2099", "Use $(...) instead of deprecated backticks", ShellCompatibility::Universal),
("SC2100", "Use $((..)) instead of deprecated expr", ShellCompatibility::Universal),
("SC2101", "Named POSIX class needs outer [] (e.g., [[:digit:]])", ShellCompatibility::Universal),
("SC2102", "Ranges only work with single chars (not regex +)", ShellCompatibility::Universal),
("SC2106", "Consider using pgrep instead of ps | grep", ShellCompatibility::Universal),
("SC2117", "Unreachable code after exit or return", ShellCompatibility::Universal),
("SC2118", "Ksh-specific set -A won't work in sh", ShellCompatibility::NotSh),
("SC2121", "Don't use $ on left side of assignment", ShellCompatibility::Universal),
("SC2122", ">= not valid in [ ]. Use -ge for numeric comparison", ShellCompatibility::Universal),
("SC2126", "Use grep -c instead of grep | wc -l (efficiency)", ShellCompatibility::Universal),
("SC2127", "Constant comparison in [ ] (always true/false)", ShellCompatibility::Universal),
("SC2129", "Use >> instead of repeated > redirects to same file", ShellCompatibility::Universal),
("SC2130", "-e flag usage clarification (valid file test)", ShellCompatibility::Universal),
("SC2131", "Backslashes in single quotes are literal (no escaping)", ShellCompatibility::Universal),
("SC2132", "Readonly variable used in for loop (will fail)", ShellCompatibility::Universal),
("SC2135", "Unexpected 'then' after condition (missing semicolon or wrong keyword)", ShellCompatibility::Universal),
("SC2136", "Unexpected 'do' in 'if' statement (should be 'then')", ShellCompatibility::Universal),
("SC2138", "Function defined in wrong context (if/loop) or reserved name", ShellCompatibility::Universal),
("SC2139", "Alias variable expands at definition time (not invocation)", ShellCompatibility::Universal),
("SC2140", "Malformed quote concatenation (unquoted words between quotes)", ShellCompatibility::Universal),
("SC2141", "Command receives stdin but ignores it (find, ls, echo, sudo)", ShellCompatibility::Universal),
("SC2142", "Aliases can't use positional parameters (use functions instead)", ShellCompatibility::Universal),
("SC2143", "Use grep -q for efficiency (exits on first match)", ShellCompatibility::Universal),
("SC2144", "-e test on glob that never matches (glob safety)", ShellCompatibility::Universal),
("SC2145", "Argument mixin in arrays ($@ or $* unquoted in quotes)", ShellCompatibility::Universal),
("SC2146", "find -o action grouping needs parentheses", ShellCompatibility::Universal),
("SC2147", "Literal tilde in PATH doesn't expand (use $HOME)", ShellCompatibility::Universal),
("SC2148", "Add shebang to indicate interpreter (portability)", ShellCompatibility::Universal),
("SC2149", "Remove quotes from unset variable names", ShellCompatibility::Universal),
("SC2150", "Use find -exec + instead of \\; for batch processing (efficiency)", ShellCompatibility::Universal),
("SC2151", "Return code should be 0-255 (POSIX requirement)", ShellCompatibility::Universal),
("SC2152", "Exit code should be 0-255 (POSIX requirement)", ShellCompatibility::Universal),
("SC2153", "Possible misspelling: var=$VAR1, but only $VAR2 is defined", ShellCompatibility::Universal),
("SC2154", "Variable is referenced but not assigned (may be external)", ShellCompatibility::Universal),
("SC2155", "Declare and assign separately to preserve exit code", ShellCompatibility::Universal),
("SC2156", "Injected filenames can cause command injection ($() in filenames)", ShellCompatibility::Universal),
("SC2157", "Argument to [ -z/-n ] is always false due to literal strings", ShellCompatibility::Universal),
("SC2158", "[ true ] evaluates as literal '[', not test command", ShellCompatibility::Universal),
("SC2159", "[ [ with space creates syntax error (double bracket mistake)", ShellCompatibility::Universal),
("SC2160", "Instead of 'if var; then', use 'if [ -n \"$var\" ]; then'", ShellCompatibility::Universal),
("SC2161", "Provide explicit error handling for cd commands", ShellCompatibility::Universal),
("SC2162", "read without -r will mangle backslashes", ShellCompatibility::Universal),
("SC2163", "export command with array syntax (non-portable)", ShellCompatibility::Universal),
("SC2164", "cd without error check (use ||, &&, or if)", ShellCompatibility::Universal),
("SC2165", "Subshells don't inherit traps - use functions instead", ShellCompatibility::Universal),
("SC2166", "Prefer [ p ] && [ q ] over [ p -a q ] (POSIX portability)", ShellCompatibility::Universal),
("SC2167", "Trap handler doesn't propagate to subshells", ShellCompatibility::Universal),
("SC2168", "'local' keyword is only valid in functions", ShellCompatibility::NotSh),
("SC2169", "In dash/sh, -eq is undefined for strings (use = instead)", ShellCompatibility::Universal),
("SC2170", "Numerical -eq comparison on non-numeric strings", ShellCompatibility::Universal),
("SC2171", "Found trailing ] on the line (syntax error)", ShellCompatibility::Universal),
("SC2172", "Trapping signals by number is deprecated (use names)", ShellCompatibility::Universal),
];
pub(super) fn build_registry() -> HashMap<&'static str, RuleMetadata> {
let mut registry = HashMap::with_capacity(396);
for &(id, name, compatibility) in RULES {
registry.insert(id, RuleMetadata { id, name, compatibility });
}
super::rule_registry_data_ext::extend_registry(&mut registry);
registry
}