Handle positional-only-arguments separator comments (#4748)

This commit is contained in:
Micha Reiser 2023-06-01 08:22:49 +02:00 committed by GitHub
parent be31d71849
commit b7294b48e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 442 additions and 0 deletions

View file

@ -0,0 +1,36 @@
---
source: crates/ruff_python_formatter/src/comments/mod.rs
expression: comments.debug(test_case.source_code)
---
{
Node {
kind: Arguments,
range: 10..94,
source: `a=10,/, # trailing position...t comment.⏎`,
}: {
"leading": [],
"dangling": [
SourceComment {
text: "# trailing positional argument comment.",
position: EndOfLine,
formatted: false,
},
],
"trailing": [],
},
Node {
kind: Arg,
range: 90..91,
source: `b`,
}: {
"leading": [
SourceComment {
text: "# leading comment for b",
position: OwnLine,
formatted: false,
},
],
"dangling": [],
"trailing": [],
},
}

View file

@ -0,0 +1,56 @@
---
source: crates/ruff_python_formatter/src/comments/mod.rs
expression: comments.debug(test_case.source_code)
---
{
Node {
kind: Arguments,
range: 15..177,
source: `a=10 # trailing positional comment⏎`,
}: {
"leading": [],
"dangling": [
SourceComment {
text: "# Positional arguments only after here",
position: OwnLine,
formatted: false,
},
SourceComment {
text: "# trailing positional argument comment.",
position: EndOfLine,
formatted: false,
},
],
"trailing": [],
},
Node {
kind: ExprConstant,
range: 17..19,
source: `10`,
}: {
"leading": [],
"dangling": [],
"trailing": [
SourceComment {
text: "# trailing positional comment",
position: EndOfLine,
formatted: false,
},
],
},
Node {
kind: Arg,
range: 173..174,
source: `b`,
}: {
"leading": [
SourceComment {
text: "# leading comment for b",
position: OwnLine,
formatted: false,
},
],
"dangling": [],
"trailing": [],
},
}

View file

@ -0,0 +1,56 @@
---
source: crates/ruff_python_formatter/src/comments/mod.rs
expression: comments.debug(test_case.source_code)
---
{
Node {
kind: Arg,
range: 15..16,
source: `a`,
}: {
"leading": [],
"dangling": [],
"trailing": [
SourceComment {
text: "# trailing positional comment",
position: EndOfLine,
formatted: false,
},
],
},
Node {
kind: Arguments,
range: 15..168,
source: `a, # trailing positional comment⏎`,
}: {
"leading": [],
"dangling": [
SourceComment {
text: "# Positional arguments only after here",
position: OwnLine,
formatted: false,
},
SourceComment {
text: "# trailing positional argument comment.",
position: EndOfLine,
formatted: false,
},
],
"trailing": [],
},
Node {
kind: Arg,
range: 166..167,
source: `b`,
}: {
"leading": [
SourceComment {
text: "# leading b comment",
position: OwnLine,
formatted: false,
},
],
"dangling": [],
"trailing": [],
},
}

View file

@ -0,0 +1,57 @@
---
source: crates/ruff_python_formatter/src/comments/mod.rs
expression: comments.debug(test_case.source_code)
---
{
Node {
kind: Arg,
range: 15..16,
source: `a`,
}: {
"leading": [],
"dangling": [],
"trailing": [
SourceComment {
text: "# trailing positional comment",
position: EndOfLine,
formatted: false,
},
],
},
Node {
kind: Arguments,
range: 15..97,
source: `a, # trailing positional comment⏎`,
}: {
"leading": [],
"dangling": [
SourceComment {
text: "# Positional arguments only after here",
position: OwnLine,
formatted: false,
},
],
"trailing": [
SourceComment {
text: "# trailing positional argument comment.",
position: EndOfLine,
formatted: false,
},
],
},
Node {
kind: StmtPass,
range: 168..172,
source: `pass`,
}: {
"leading": [
SourceComment {
text: "# Trailing on new line",
position: OwnLine,
formatted: false,
},
],
"dangling": [],
"trailing": [],
},
}

View file

@ -0,0 +1,56 @@
---
source: crates/ruff_python_formatter/src/comments/mod.rs
expression: comments.debug(test_case.source_code)
---
{
Node {
kind: Arg,
range: 15..16,
source: `a`,
}: {
"leading": [],
"dangling": [],
"trailing": [
SourceComment {
text: "# trailing positional comment",
position: EndOfLine,
formatted: false,
},
],
},
Node {
kind: Arguments,
range: 15..168,
source: `a # trailing positional comment⏎`,
}: {
"leading": [],
"dangling": [
SourceComment {
text: "# Positional arguments only after here",
position: OwnLine,
formatted: false,
},
SourceComment {
text: "# trailing positional argument comment.",
position: EndOfLine,
formatted: false,
},
],
"trailing": [],
},
Node {
kind: Arg,
range: 166..167,
source: `b`,
}: {
"leading": [
SourceComment {
text: "# leading b comment",
position: OwnLine,
formatted: false,
},
],
"dangling": [],
"trailing": [],
},
}