Skip to content

Commit

Permalink
Use correct start location for class/function clause header
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Oct 4, 2023
1 parent 37d21c0 commit 4bed0d5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/ruff_python_formatter/src/statement/clause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,23 @@ impl<'a> ClauseHeader<'a> {
fn first_keyword_range(self, source: &str) -> FormatResult<TextRange> {
match self {
ClauseHeader::Class(header) => {
find_keyword(header.start(), SimpleTokenKind::Class, source)
let start_position = header
.decorator_list
.last()
.map_or_else(|| header.start(), Ranged::end);
find_keyword(start_position, SimpleTokenKind::Class, source)
}
ClauseHeader::Function(header) => {
let start_position = header
.decorator_list
.last()
.map_or_else(|| header.start(), Ranged::end);
let keyword = if header.is_async {
SimpleTokenKind::Async
} else {
SimpleTokenKind::Def
};
find_keyword(header.start(), keyword, source)
find_keyword(start_position, keyword, source)
}
ClauseHeader::If(header) => find_keyword(header.start(), SimpleTokenKind::If, source),
ClauseHeader::ElifElse(ElifElseClause {
Expand Down

0 comments on commit 4bed0d5

Please sign in to comment.