{"record":{"id":"5476548d8afb006c","repo":"astral-sh/ruff","slug":"expected-colon-after-test","errorCode":null,"errorMessage":"Expected colon after test","messagePattern":"Expected colon after test","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs","lineNumber":122,"sourceCode":"            )\n        });\n    }\n}\n\n/// Generate a [`Fix`] to merge two [`IfElifBranch`] branches.\nfn merge_branches(\n    stmt_if: &ast::StmtIf,\n    current_branch: &IfElifBranch,\n    following_branch: &IfElifBranch,\n    locator: &Locator,\n    tokens: &ruff_python_ast::token::Tokens,\n) -> Result<Fix> {\n    // Identify the colon (`:`) at the end of the current branch's test.\n    let Some(current_branch_colon) =\n        SimpleTokenizer::starts_at(current_branch.test.end(), locator.contents())\n            .find(|token| token.kind == SimpleTokenKind::Colon)\n    else {\n        return Err(anyhow::anyhow!(\"Expected colon after test\"));\n    };\n\n    let deletion_edit = Edit::deletion(\n        locator.full_line_end(current_branch.end()),\n        locator.full_line_end(following_branch.end()),\n    );\n\n    // If the following test isn't parenthesized, consider parenthesizing it.\n    let following_branch_test = if let Some(range) =\n        parenthesized_range(following_branch.test.into(), stmt_if.into(), tokens)\n    {\n        Cow::Borrowed(locator.slice(range))\n    } else if matches!(\n        following_branch.test,\n        Expr::Lambda(_) | Expr::Named(_) | Expr::If(_)\n    ) {\n        // If the following expressions binds more tightly than `or`, parenthesize it.\n        Cow::Owned(format!(\"({})\", locator.slice(following_branch.test)))","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/flake8_simplify/rules/if_with_same_arms.rs#L104-L140","documentation":"This error is raised while building the fix for SIM114 (combine `if` branches with identical arms) when the fixer cannot locate the colon after the `if` test of a branch. Without the colon's position, the fixer cannot compute the text range to splice when merging two identical branches, so it aborts the fix.","triggerScenarios":"`merge_branches` scans the locator's contents from the branch's test expression to find a colon token; if the token at the expected end position of the test is not a Colon (unexpected token layout in the parsed source), the fix returns Err('Expected colon after test').","commonSituations":"Autofixing `if/elif` chains with identical bodies where the source has irregular token layout; seen by users of `ruff --fix` as an unfixed diagnostic or by plugin/test developers consuming the fix API.","solutions":["Reformat the `if`/`elif` statements so the test expression ends with a normal `:` and rerun the fix","Manually merge the identical branches by replacing `elif` with `or` or deleting the duplicate branch","Report a reproducing snippet upstream so the fixer can be made robust"],"exampleFix":"# before (two identical branches)\nif x == 1:\n    do()\nelif x == 2:\n    do()\n# after (combined)\nif x in (1, 2):\n    do()","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let fix = merge_branches(...).unwrap_or_else(|_| {\n    // emit diagnostic without fix; log \"Expected colon after test\"\n    Fix::empty()\n});","preventionTips":["Format `if`/`elif` tests with a normal trailing `:`","Avoid exotic token layouts around branch headers","Treat SIM114 fixes as best-effort and always keep a no-fix fallback"],"tags":["ruff","autofix","flake8-simplify","parser"],"backgroundTag":"autofix-generation-failed","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}