{"record":{"id":"a49906989199927b","repo":"astral-sh/ruff","slug":"expected","errorCode":null,"errorMessage":"Expected {}","messagePattern":"Expected (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/settings/types.rs","lineNumber":400,"sourceCode":"\n#[derive(Clone, Debug, PartialEq, Eq)]\npub struct PatternPrefixPair {\n    pub pattern: String,\n    pub prefix: UnresolvedRuleSelector,\n}\n\nimpl PatternPrefixPair {\n    const EXPECTED_PATTERN: &'static str = \"<FilePattern>:<RuleCode> pattern\";\n}\n\nimpl FromStr for PatternPrefixPair {\n    type Err = anyhow::Error;\n\n    fn from_str(s: &str) -> Result<Self, Self::Err> {\n        let (pattern_str, code_string) = {\n            let tokens = s.split(':').collect::<Vec<_>>();\n            if tokens.len() != 2 {\n                bail!(\"Expected {}\", Self::EXPECTED_PATTERN);\n            }\n            (tokens[0].trim(), tokens[1].trim())\n        };\n        let pattern = pattern_str.into();\n        let prefix = UnresolvedRuleSelector::cli(code_string);\n        Ok(Self { pattern, prefix })\n    }\n}\n\n#[derive(\n    Clone,\n    Copy,\n    Debug,\n    PartialOrd,\n    Ord,\n    PartialEq,\n    Eq,\n    Default,","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/settings/types.rs#L382-L418","documentation":"`PatternPrefixPair::from_str` parses CLI/config strings of the form `<FilePattern>:<RuleCode>` (used for per-file rule overrides). It throws `Expected <FilePattern>:<RuleCode> pattern` via anyhow when the string does not contain exactly one `:` producing exactly two tokens.","triggerScenarios":"Passing a value like `\"foo.py\"`, `\"foo.py:E501:extra\"`, or a value with no colon to settings that expect a pattern-prefix pair (e.g. `lint.per-file-ignores` style entries or `--per-file-target-version`-like options parsed into `PatternPrefixPair`).","commonSituations":"Typos in pyproject.toml/ruff.toml configuration; forgetting the `:E501` suffix on a glob; quoting issues that split the value; on Windows, drive letters (`C:...`) can distort the colon count.","solutions":["Write the value as `<glob>:<rule-code>`, e.g. `\"tests/*:S101\"`","Ensure exactly one colon separates pattern and rule code; avoid extra colons","Quote the value in TOML/CLI so shell expansion does not split it"],"exampleFix":"# before\n[tool.ruff.lint.per-file-ignores]\n\"tests/*\" = \"S101\"\n# after\n[tool.ruff.lint.per-file-ignores]\n\"tests/*\" = \"S101\"  # correct form used by this pair type: \"<FilePattern>:<RuleCode>\"","handlingStrategy":"validation","validationCode":"def validate_pattern_prefix_pair(value: str) -> bool:\n    tokens = value.split(':')\n    return len(tokens) == 2 and all(t.strip() for t in tokens)\n\nassert validate_pattern_prefix_pair(\"tests/*:S101\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always format such settings as \"<glob>:<rule-code>\" with exactly one colon","Quote values in TOML to avoid shell/parser mangling","Validate config by running `ruff check` on a tiny file after edits"],"tags":["ruff","configuration","cli","parsing"],"backgroundTag":"invalid-config-format","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}