Skip to content

IECQ007: ruff_rules_enabled

The ruff configuration enables the curated ruff rules.

Category: code_quality ยท Applies to: eval, helper

What it does

Warns for each rule in the curated set below that ruff, configured as it is for the package, would not report. The finding names the configuration file and how many violations ruff would report under the source root if the rule were on, so a maintainer can tell a one-line change from a cleanup.

The check asks ruff rather than reading its configuration. It lints a snippet the rule reports as though it were a file in the package, so select, extend-select, ignore, extend, per-file-ignores, preview and explicit-preview-rules all apply exactly as ruff applies them. A preview rule that a prefix such as PLW selects while preview is off counts as not enabled, because ruff never reports it. A repository with no ruff configuration gets ruff's defaults, which enable none of the curated rules.

It uses the ruff installed alongside the linter, else ruff on PATH, and skips when there is neither, or when ruff cannot load the configuration, with ruff's reason. That ruff may be a different version from the one the repository pins. Packages that share a configuration share one finding: a run reports it under the first of them, and the rest skip.

Why is this bad?

Each curated rule catches a defect that has reached an evaluation. Ruff reports it in the author's editor and pre-commit hook, before review, which a custom rule here could not. A preview rule selected only by a prefix is silently inert: ruff warns that a selection has no effect only when the code is named, so a reader of the configuration would believe it is on.

Curated rules

Rule Why Evidence
PLW1514 unspecified-encoding open() and Path.read_text() without encoding= decode with the host's locale, so a dataset or prompt file that loads on a UTF-8 machine fails or is misread elsewhere. A preview rule in ruff 0.15 and 0.16. Evaluations read YAML, JSON and prompt files with a bare open(); those loads break under a C or non-UTF-8 locale, as on some CI runners and Windows.

Example

[tool.ruff.lint]
select = ["E", "F", "PLW"]

Use instead:

[tool.ruff.lint]
select = ["E", "F", "PLW"]
extend-select = ["PLW1514"]
preview = true

Options

  • ruff_rules_enabled.declined: a table from curated rule code to the reason the repository does not enable it, e.g. declined = { PLW1514 = "every file is ASCII" }. A declined rule that is not enabled is reported as suppressed, with the reason.

Suppress on a line with # inspect-evals-lint: ignore[IECQ007] -- <reason> or ignore[ruff_rules_enabled] -- <reason>; select or ignore it in configuration by either, or by the prefix IECQ.