Skip to content

inert-directives ​

inert-directives reports a skip or ignore directive that holds nothing out of the run checking it, so a reader of the source can tell which directives still do their job. A directive goes on holding nothing once the code it covered changes or a rule it names is renamed, and one written in the family that does not reach its rule, such as a skip meant to silence a lint, never held anything. Each report names the directive and the reason it holds nothing, covering:

  • A skip whose removal leaves every rule it names making the same edits, reading # fmt: skip as a bare skip. A skip on one row of an alignment run still holds something where its own row would stay as written, as long as removing it moves the column an aligning rule pads the other rows to
  • An ignore whose line carries no finding of a rule it names
  • A bracketed id naming no registered rule, such as a misspelled or retired slug, once per id

A listed id naming a rule the run leaves out, through --select, --ignore, or the configuration, spares its directive, since a run that selects the rule may need it. A bare skip or ignore names no rule, so it is judged against the rules the run carries, and a run narrowed by --select to the lints reports every bare skip.

A bare # prose: ignore silences every lint on its line, including any rule a later release adds, so the rule reports one that does silence findings too, naming the slugs it silences and the bracketed form that holds out the same findings. A report on an ignore stands outside that directive's reach, so a bare ignore never silences the report on itself, whereas a # prose: ignore[inert-directives] on a line carrying a skip silences the report on that skip and counts as holding it out.

A directive inside a # fmt: off region is not reported, since the region silences every lint on its lines. The lint never rewrites, so the diagnostic is reported and the source stays as written.

Configuration ​

KeyTypeDefaultMeaning
enabledbooltrueTurns the rule on or off.

The Canonical Case ​

With signature-annotations beside it, the rule reads four directives. The # fmt: skip on fetch holds out no rewrite, since no rule in the run rewrites that line, and the ignore[signature-annotations] on the fully annotated render holds out no finding. The bare ignore on parse is reported too, because it silences every lint on its line, so the report names the signature-annotations findings it holds out and the bracketed form holding out the same ones. signature-annotation, missing its final s, names no rule, so the directive on store is reported for that id.

def fetch(url: str) -> bytes:  # fmt: skip
    return download(url)


def parse(payload):  # prose: ignore
    return payload.decode()


def render(page: str) -> str:  # prose: ignore[signature-annotations]
    return page.strip()


def store(record: dict) -> None:  # prose: ignore[signature-annotation]
    archive(record)
python

More Examples ​

The run carries align-equals alone. skip[strip-trailing-commas] and ignore[reassigned-constants] each name a rule the run leaves out, and skip[align-equals, strip-trailing-commas] on the first connect call names one beside a rule the run carries, so all three are spared, since a run that selects those rules may need them. The skip[align-equals] on the second connect call names only align-equals, which never rewrites a call, so it is reported.

No other rule runs, so each # fmt: skip holds nothing out. On limit, the ignore[inert-directives] beside the skip silences the report on it and so holds something out, leaving that line quiet. On width, the same ignore stands alone and holds nothing, and its own report stays, since a report on an ignore sits outside that directive's reach. On count, the bare ignore silences the report on its skip and is reported naming inert-directives, whereas the bare ignore on depth silences nothing and is reported as holding nothing out.

align-equals leaves the skipped timeout_seconds row as written either way, yet its skip still holds something out, since align-equals leaves host as written beside the held row and would pad it to timeout_seconds's column once the skip is gone. The skip on the connect call holds nothing, because align-equals never rewrites a call, so that one is reported.

The Suppression Directives reference gives the syntax of every skip and ignore form, and the Suppression chapter covers which family reaches a rewrite and which a lint.