{"record":{"id":"dc7eed269807ce1d","repo":"astral-sh/ruff","slug":"own-line-docstring-must-have-indentation","errorCode":null,"errorMessage":"Own line docstring must have indentation","messagePattern":"Own line docstring must have indentation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs","lineNumber":255,"sourceCode":"        // If the class is empty except for comments, we don't need to insert a newline between\n        // docstring and no content\n        let all_blank_after = lines.clone().all(|line| {\n            line.trim_whitespace().is_empty() || line.trim_whitespace_start().starts_with('#')\n        });\n        if all_blank_after {\n            return;\n        }\n\n        let first_line = lines.next();\n        let mut replacement_start = first_line.as_ref().map(Line::start).unwrap_or_default();\n\n        // Edge case: There is trailing end-of-line content after the docstring, either a statement\n        // separated by a semicolon or a comment.\n        if let Some(first_line) = &first_line {\n            let trailing = first_line.as_str().trim_whitespace_start();\n            if let Some(next_statement) = trailing.strip_prefix(';') {\n                let indentation = indentation_at_offset(docstring.start(), checker.source())\n                    .expect(\"Own line docstring must have indentation\");\n                let mut diagnostic =\n                    checker.report_diagnostic(IncorrectBlankLineAfterClass, docstring.range());\n                let line_ending = checker.stylist().line_ending().as_str();\n                // We have to trim the whitespace twice, once before the semicolon above and\n                // once after the semicolon here, or we get invalid indents:\n                // ```rust\n                // class Priority:\n                //     \"\"\"Has priorities\"\"\"   ;   priorities=1\n                // ```\n                let next_statement = next_statement.trim_whitespace_start();\n                diagnostic.set_fix(Fix::safe_edit(Edit::replacement(\n                    line_ending.to_string() + line_ending + indentation + next_statement,\n                    replacement_start,\n                    first_line.end(),\n                )));\n\n                return;\n            } else if trailing.starts_with('#') {","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs#L237-L273","documentation":"An internal expectation in the pydocstyle D-z blank-before/after-class fixer: while rebuilding the fix, a docstring that sits on its own line was found with no indentation to work with. The rule only fires on class docstrings that are indented, so this indicates the fixer's assumptions about the located line are broken.","triggerScenarios":"Thrown at crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs:255 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the line-location logic used to compute the docstring's indentation","Skip the autofix when the own-line docstring has no indentation"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}