Skip to content

xpd rules

List every rule and package check, with its severity, fix and documentation 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.

Terminal window
xpd rules [OPTIONS]

xpd rules --help ends with these lines.

Examples:
xpd rules
xpd rules --format json | jq '.[] | select(.package == "numpy")'

--builtin

List only the rules that ship with xpd, without the project's own rules.

Cannot be combined 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.

Give it more than once to pass several values.

--severity <SEVERITY>

List only the rules of this severity and above: error, warning, info or hint.

--format <FORMAT>

Output format. Default: text on a terminal, json otherwise.

Values: text, json.

Terminal window
$ xpd rules --format text --rule pandas/chained-assignment --rule pandas/no-inplace
error [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.

Terminal window
$ 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 code Meaning
0 The rules were listed
2 xpd could not read the rules, or --rule named no rule