mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Include soft keywords for is_keyword
check (#11445)
## Summary This PR updates the `TokenKind::is_keyword` check to include soft keywords. To account for this change, it adds a new `is_non_soft_keyword` method. The usage in logical line rules were updated to use the `is_non_soft_keyword` method but it'll be updated to use `is_keyword` in a follow-up PR (#11446). While, the parser usages were kept as is. And because of that, the snapshots for two test cases were updated in a better direction. ## Test Plan `cargo insta test`
This commit is contained in:
parent
43e8147eaf
commit
83152fff92
7 changed files with 94 additions and 133 deletions
|
@ -52,7 +52,7 @@ pub(crate) fn missing_whitespace_after_keyword(
|
|||
let tok0_kind = tok0.kind();
|
||||
let tok1_kind = tok1.kind();
|
||||
|
||||
if tok0_kind.is_keyword()
|
||||
if tok0_kind.is_non_soft_keyword()
|
||||
&& !(tok0_kind.is_singleton()
|
||||
|| matches!(tok0_kind, TokenKind::Async | TokenKind::Await)
|
||||
|| tok0_kind == TokenKind::Except && tok1_kind == TokenKind::Star
|
||||
|
|
|
@ -198,9 +198,7 @@ pub(crate) fn missing_whitespace_around_operator(
|
|||
matches!(
|
||||
prev_kind,
|
||||
TokenKind::Rpar | TokenKind::Rsqb | TokenKind::Rbrace
|
||||
) || !(prev_kind.is_operator()
|
||||
|| prev_kind.is_keyword()
|
||||
|| prev_kind.is_soft_keyword())
|
||||
) || !(prev_kind.is_operator() || prev_kind.is_keyword())
|
||||
};
|
||||
|
||||
if is_binary {
|
||||
|
|
|
@ -445,7 +445,7 @@ impl LogicalLinesBuilder {
|
|||
|
||||
if matches!(kind, TokenKind::Comma | TokenKind::Semi | TokenKind::Colon) {
|
||||
line.flags.insert(TokenFlags::PUNCTUATION);
|
||||
} else if kind.is_keyword() {
|
||||
} else if kind.is_non_soft_keyword() {
|
||||
line.flags.insert(TokenFlags::KEYWORD);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,8 +127,8 @@ pub(crate) fn whitespace_around_keywords(line: &LogicalLine, context: &mut Logic
|
|||
let mut after_keyword = false;
|
||||
|
||||
for token in line.tokens() {
|
||||
let is_keyword = token.kind().is_keyword();
|
||||
if is_keyword {
|
||||
let is_non_soft_keyword = token.kind().is_non_soft_keyword();
|
||||
if is_non_soft_keyword {
|
||||
if !after_keyword {
|
||||
match line.leading_whitespace(token) {
|
||||
(Whitespace::Tab, offset) => {
|
||||
|
@ -184,6 +184,6 @@ pub(crate) fn whitespace_around_keywords(line: &LogicalLine, context: &mut Logic
|
|||
}
|
||||
}
|
||||
|
||||
after_keyword = is_keyword;
|
||||
after_keyword = is_non_soft_keyword;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue