xpd rules
Use xpd rules to see which rules a project runs, or to read a rule's text without a browser.
It lists every rule and package check of every pack, whatever the project's Python has installed,
and the project's own rules unless you pass --builtin. The rules pages show the
same text.
xpd rules [OPTIONS] xpd rules <COMMAND>Subcommands
Section titled “Subcommands”| Subcommand | What it does |
|---|---|
xpd rules new |
Create a rule project, or a rule, test case or utility in one |
xpd rules test |
Check rule examples and review diagnostic and fix snapshots |
xpd rules run |
Search code by syntax, in any language ast-grep parses, and preview or apply a rewrite |
xpd rules outline |
Map the files of a project: imports, definitions and their members, with line numbers |
xpd rules verify-fixes |
Verify that rule fixes produce valid code and converge in memory |
Options
Section titled “Options”| Option | Default | What it does |
|---|---|---|
--builtin |
List only the rules that ship with xpd, without the project's own rules. Conflicts with --config. |
|
-c, --config <CONFIG> |
The project file to read instead of the nearest sgconfig.yml. | |
--rule <NAME> |
List only this package or rule, as pandas, chained-assignment or pandas/chained-assignment. Repeat it to name several. Repeatable. |
|
--severity <SEVERITY> |
List only the rules of this severity and above: error, warning, info or hint. | |
--category <CATEGORY> |
List only rules in this category, and show their categories. Values: data, numerics, statistics, features, models, evaluation, optimization, visualization, workflow. |
|
--categories |
Show the categories of each rule. | |
--format <FORMAT> |
Output format. Default: text on a terminal, json otherwise. Values: text, json. |
Examples
Section titled “Examples”$ xpd rules --format text --rule pandas/chained-assignment --rule pandas/no-inplaceerror [pandas/chained-assignment] (unsafe fix) Chained assignment writes to a copy under copy-on-write, so the frame keeps its old values. Assign to $DF.loc[$ROW, $COL] instead.info [pandas/no-inplace] (unsafe fix) inplace=True gives no speedup and blocks chaining. Reassign instead.Each text line gives the severity, the rule, its fix, the first library version it applies to
when there is one, and the message. A name that starts with $ stands for code from the checked
file, which xpd check fills in.
The JSON is a list with one object per rule, with package, rule, severity, style,
severities, message, fix, since, url and doc. fix is safe, unsafe or null.
since is the first library version the rule applies to, or null. doc is the Markdown that
explains the rule.
$ xpd rules --builtin --format json | jq -c '.[] | select(.rule == "no-inplace") | {package, rule, severity, style, severities, fix, since}'{"package":"pandas","rule":"no-inplace","severity":"info","style":"house","severities":{"default":"info","strict":"warning"},"fix":"unsafe","since":null}style is house for a rule of the house style, and null for every
other rule. severities holds the severity without a style setting and the one with
style = "strict". severity is the one that the project in the current folder gets, and
--builtin lists the rules without reading a settings file.
A rule file may hold several YAML documents, one for each form that the rule matches. rules
lists them as one rule, with the highest severity of the documents, the message of the first and
the least safe fix.
Exit status
Section titled “Exit status”| Exit code | Meaning |
|---|---|
| 0 | The rules were listed |
| 2 | xpd could not read the rules, or --rule named no rule |