astral-sh/ruff · error

Selection of deprecated rule

Error message

Selection of deprecated rule `{prefix}{code}` is not allowed when preview is enabled.

What it means

An anyhow error raised when preview mode is enabled and the configuration still selects a deprecated rule. Under preview, deprecated rule selection is a hard error (it would silently change behavior once the rule is removed), so configuration loading aborts naming the code.

Solutions

  1. Remove the deprecated rule code from the configuration
  2. Disable preview mode if the deprecated rule must still be used
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/ruff_workspace/src/configuration.rs:1189 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/6782ed46d186ef1a. Report an issue: GitHub.

Appendix: source

Thrown at crates/ruff_workspace/src/configuration.rs:1189

            let (prefix, code) = target.prefix_and_code();
            // TODO(martin): This belongs into the ruff crate.
            warn_user_once_by_id!(from, "`{from}` has been remapped to `{prefix}{code}`.");
        }

        if preview.mode.is_disabled() {
            for selection in deprecated_selectors.iter().sorted() {
                let (prefix, code) = selection.prefix_and_code();
                warn_user_once_by_message!(
                    "Rule `{prefix}{code}` is deprecated and will be removed in a future release."
                );
            }
        } else {
            let deprecated_selectors = deprecated_selectors.iter().sorted().collect::<Vec<_>>();
            match deprecated_selectors.as_slice() {
                [] => (),
                [selection] => {
                    let (prefix, code) = selection.prefix_and_code();
                    return Err(anyhow!(
                        "Selection of deprecated rule `{prefix}{code}` is not allowed when \
                         preview is enabled."
                    ));
                }
                [..] => {
                    let mut message = "\
                        Selection of deprecated rules is not allowed \
                            when preview is enabled. Remove selection of:"
                        .to_string();
                    for selection in deprecated_selectors {
                        let (prefix, code) = selection.prefix_and_code();
                        message.push_str("\n\t- ");
                        message.push_str(prefix);
                        message.push_str(code);
                    }
                    message.push('\n');
                    return Err(anyhow!(message));
                }

View on GitHub (pinned to 26f38c119c)