mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:10:09 +00:00
parent
4ddcdd02d6
commit
cecd4b166c
4 changed files with 150 additions and 138 deletions
|
@ -632,7 +632,7 @@ For more, see [pydocstyle](https://pypi.org/project/pydocstyle/6.1.1/) on PyPI.
|
|||
| D202 | NoBlankLineAfterFunction | No blank lines allowed after function docstring (found 1) | 🛠 |
|
||||
| D203 | OneBlankLineBeforeClass | 1 blank line required before class docstring | 🛠 |
|
||||
| D204 | OneBlankLineAfterClass | 1 blank line required after class docstring | 🛠 |
|
||||
| D205 | BlankLineAfterSummary | 1 blank line required between summary line and description | 🛠 |
|
||||
| D205 | BlankLineAfterSummary | 1 blank line required between summary line and description (found 2) | 🛠 |
|
||||
| D206 | IndentWithSpaces | Docstring should be indented with spaces, not tabs | |
|
||||
| D207 | NoUnderIndentation | Docstring is under-indented | 🛠 |
|
||||
| D208 | NoOverIndentation | Docstring is over-indented | 🛠 |
|
||||
|
|
|
@ -336,10 +336,11 @@ pub fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) {
|
|||
}
|
||||
if lines_count > 1 && blanks_count != 1 {
|
||||
let mut check = Check::new(
|
||||
CheckKind::BlankLineAfterSummary,
|
||||
CheckKind::BlankLineAfterSummary(blanks_count),
|
||||
Range::from_located(docstring.expr),
|
||||
);
|
||||
if checker.patch(check.kind.code()) {
|
||||
if blanks_count > 1 {
|
||||
// Find the "summary" line (defined as the first non-blank line).
|
||||
let mut summary_line = 0;
|
||||
for line in body.lines() {
|
||||
|
@ -350,7 +351,6 @@ pub fn blank_after_summary(checker: &mut Checker, docstring: &Docstring) {
|
|||
}
|
||||
}
|
||||
|
||||
if blanks_count > 1 {
|
||||
// Insert one blank line after the summary (replacing any existing lines).
|
||||
check.amend(Fix::replacement(
|
||||
"\n".to_string(),
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
source: src/pydocstyle/mod.rs
|
||||
expression: checks
|
||||
---
|
||||
- kind: BlankLineAfterSummary
|
||||
- kind:
|
||||
BlankLineAfterSummary: 0
|
||||
location:
|
||||
row: 200
|
||||
column: 4
|
||||
|
@ -11,7 +12,8 @@ expression: checks
|
|||
column: 7
|
||||
fix: ~
|
||||
parent: ~
|
||||
- kind: BlankLineAfterSummary
|
||||
- kind:
|
||||
BlankLineAfterSummary: 2
|
||||
location:
|
||||
row: 210
|
||||
column: 4
|
||||
|
|
|
@ -1005,7 +1005,7 @@ pub enum CheckKind {
|
|||
// pydocstyle
|
||||
BlankLineAfterLastSection(String),
|
||||
BlankLineAfterSection(String),
|
||||
BlankLineAfterSummary,
|
||||
BlankLineAfterSummary(usize),
|
||||
BlankLineBeforeSection(String),
|
||||
CapitalizeSectionName(String),
|
||||
DashedUnderlineAfterSection(String),
|
||||
|
@ -1465,7 +1465,7 @@ impl CheckCode {
|
|||
CheckCode::D202 => CheckKind::NoBlankLineAfterFunction(1),
|
||||
CheckCode::D203 => CheckKind::OneBlankLineBeforeClass(0),
|
||||
CheckCode::D204 => CheckKind::OneBlankLineAfterClass(0),
|
||||
CheckCode::D205 => CheckKind::BlankLineAfterSummary,
|
||||
CheckCode::D205 => CheckKind::BlankLineAfterSummary(2),
|
||||
CheckCode::D206 => CheckKind::IndentWithSpaces,
|
||||
CheckCode::D207 => CheckKind::NoUnderIndentation,
|
||||
CheckCode::D208 => CheckKind::NoOverIndentation,
|
||||
|
@ -2268,7 +2268,7 @@ impl CheckKind {
|
|||
CheckKind::NewLineAfterLastParagraph => &CheckCode::D209,
|
||||
CheckKind::NewLineAfterSectionName(..) => &CheckCode::D406,
|
||||
CheckKind::NoBlankLineAfterFunction(..) => &CheckCode::D202,
|
||||
CheckKind::BlankLineAfterSummary => &CheckCode::D205,
|
||||
CheckKind::BlankLineAfterSummary(..) => &CheckCode::D205,
|
||||
CheckKind::NoBlankLineBeforeClass(..) => &CheckCode::D211,
|
||||
CheckKind::NoBlankLineBeforeFunction(..) => &CheckCode::D201,
|
||||
CheckKind::NoBlankLinesBetweenHeaderAndContent(..) => &CheckCode::D412,
|
||||
|
@ -3093,8 +3093,15 @@ impl CheckKind {
|
|||
}
|
||||
// pydocstyle
|
||||
CheckKind::FitsOnOneLine => "One-line docstring should fit on one line".to_string(),
|
||||
CheckKind::BlankLineAfterSummary => {
|
||||
CheckKind::BlankLineAfterSummary(num_lines) => {
|
||||
if *num_lines == 0 {
|
||||
"1 blank line required between summary line and description".to_string()
|
||||
} else {
|
||||
format!(
|
||||
"1 blank line required between summary line and description (found \
|
||||
{num_lines})"
|
||||
)
|
||||
}
|
||||
}
|
||||
CheckKind::NewLineAfterLastParagraph => {
|
||||
"Multi-line docstring closing quotes should be on a separate line".to_string()
|
||||
|
@ -3624,8 +3631,8 @@ impl CheckKind {
|
|||
|
||||
/// Whether the check kind is (potentially) fixable.
|
||||
pub fn fixable(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
match self {
|
||||
// Always-fixable checks.
|
||||
CheckKind::AAndNotA(..)
|
||||
| CheckKind::AOrNotA(..)
|
||||
| CheckKind::AmbiguousUnicodeCharacterComment(..)
|
||||
|
@ -3634,7 +3641,6 @@ impl CheckKind {
|
|||
| CheckKind::AndFalse
|
||||
| CheckKind::BlankLineAfterLastSection(..)
|
||||
| CheckKind::BlankLineAfterSection(..)
|
||||
| CheckKind::BlankLineAfterSummary
|
||||
| CheckKind::BlankLineBeforeSection(..)
|
||||
| CheckKind::CapitalizeSectionName(..)
|
||||
| CheckKind::CommentedOutCode
|
||||
|
@ -3730,7 +3736,6 @@ impl CheckKind {
|
|||
| CheckKind::UnnecessaryLiteralWithinTupleCall(..)
|
||||
| CheckKind::UnnecessaryReturnNone
|
||||
| CheckKind::UnsortedImports
|
||||
| CheckKind::UnusedImport(_, false, _)
|
||||
| CheckKind::UnusedLoopControlVariable(..)
|
||||
| CheckKind::UnusedNOQA(..)
|
||||
| CheckKind::UseFixturesWithoutParameters
|
||||
|
@ -3741,8 +3746,13 @@ impl CheckKind {
|
|||
| CheckKind::UselessMetaclassType
|
||||
| CheckKind::UselessObjectInheritance(..)
|
||||
| CheckKind::UselessYieldFixture(..)
|
||||
| CheckKind::YodaConditions(..)
|
||||
)
|
||||
| CheckKind::YodaConditions(..) => true,
|
||||
// Conditionally-fixable checks.
|
||||
CheckKind::UnusedImport(_, false, _) => true,
|
||||
CheckKind::BlankLineAfterSummary(num_lines) if *num_lines > 0 => true,
|
||||
// Non-fixable checks.
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// The message used to describe the fix action for a given `CheckKind`.
|
||||
|
@ -3762,7 +3772,7 @@ impl CheckKind {
|
|||
CheckKind::BlankLineAfterSection(name) => {
|
||||
Some(format!("Add blank line after \"{name}\""))
|
||||
}
|
||||
CheckKind::BlankLineAfterSummary => Some("Insert single blank line".to_string()),
|
||||
CheckKind::BlankLineAfterSummary(..) => Some("Insert single blank line".to_string()),
|
||||
CheckKind::BlankLineBeforeSection(name) => {
|
||||
Some(format!("Add blank line before \"{name}\""))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue