CLI Reference
sqlclean rules
List the built-in and custom Rules, or show one Rule's details.
sqlclean rules lists every Rule the configuration can select: the built-in Rules, then the custom
Rules under [rules] custom. With a code, it shows that Rule.
sqlclean rules [OPTIONS] [CODE]sqlclean rules # list every Rulesqlclean rules SQC001 # show one Rulesqlclean rules --json # every Rule as JSONsqlclean rules --json SQC001 # one Rule as JSON| Flag | Description |
|---|---|
CODE |
Show this Rule’s details; an exact code, not a prefix |
--json |
Print Rules as a JSON array |
--config <PATH> |
Use this configuration file instead of the nearest sqlclean.toml |
Listing Rules
Section titled “Listing Rules”SQC001 default Comparison with NULL is never trueSQC002 default Comma-separated sources create an implicit cartesian joinSQC003 default Non-cross join has no meaningful conditionSQC004 default Row selection is nondeterministic...SQC045 JSON payload is parsed more than once in one SELECTXSQCNAME001 default Query reads a temporary tableXSQCSTYLE001 default COUNT(1) should be COUNT(*)default marks the Rules that run when [rules] select is not set. See
Default Rules and the
Rule reference.
Showing one Rule
Section titled “Showing one Rule”sqlclean rules SQC001SQC001: Comparison with NULL is never trueSubject: statementEnabled by default: yesFixable: unsafeRemediation: Use IS NULL or IS NOT NULL when testing for NULL.A custom Rule also shows the Python module that defines it:
XSQCSTYLE001: COUNT(1) should be COUNT(*)Subject: statementEnabled by default: yesDefined in: sql_rules.namingFixable: safeRemediation: Write COUNT(*).Fixable is left out when the Rule has no fix.
JSON output
Section titled “JSON output”sqlclean rules --json XSQCNAME001[ { "code": "XSQCNAME001", "message": "Query reads a temporary table", "remediation": "Read from the published table instead.", "enabled_by_default": true, "custom": true, "subject": "statement", "module": "sql_rules.naming" }]| Field | Description |
|---|---|
code |
The Rule code |
message |
The finding message |
remediation |
What to do about a finding |
enabled_by_default |
Whether the Rule runs when [rules] select is not set |
custom |
true for custom Rules |
subject |
statement, file or repository |
fixable |
safe or unsafe; absent when the Rule has no fix |
module |
The Python module of a custom Rule; absent for built-in Rules |
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 |
The Rules were printed |
2 |
Unknown Rule code, or the configuration or a custom Rule module could not be loaded |