Place comments of left and right binary expression operands (#4751)

This commit is contained in:
Micha Reiser 2023-06-01 09:01:32 +02:00 committed by GitHub
parent 0945803427
commit 59148344be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 362 additions and 18 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: ExprConstant,
range: 11..12,
source: `5`,
}: {
"leading": [],
"dangling": [],
"trailing": [
SourceComment {
text: "# trailing left comment",
position: OwnLine,
formatted: false,
},
],
},
Node {
kind: ExprConstant,
range: 79..80,
source: `3`,
}: {
"leading": [
SourceComment {
text: "# leading right comment",
position: OwnLine,
formatted: false,
},
],
"dangling": [],
"trailing": [],
},
}

View file

@ -0,0 +1,51 @@
---
source: crates/ruff_python_formatter/src/comments/mod.rs
expression: comments.debug(test_case.source_code)
---
{
Node {
kind: ExprConstant,
range: 11..12,
source: `5`,
}: {
"leading": [],
"dangling": [],
"trailing": [
SourceComment {
text: "# trailing left comment",
position: EndOfLine,
formatted: false,
},
],
},
Node {
kind: ExprBinOp,
range: 11..104,
source: `5 # trailing left comment⏎`,
}: {
"leading": [],
"dangling": [
SourceComment {
text: "# trailing operator comment",
position: EndOfLine,
formatted: false,
},
],
"trailing": [],
},
Node {
kind: ExprConstant,
range: 103..104,
source: `3`,
}: {
"leading": [
SourceComment {
text: "# leading right comment",
position: OwnLine,
formatted: false,
},
],
"dangling": [],
"trailing": [],
},
}

View file

@ -0,0 +1,51 @@
---
source: crates/ruff_python_formatter/src/comments/mod.rs
expression: comments.debug(test_case.source_code)
---
{
Node {
kind: ExprBinOp,
range: 11..126,
source: `(5 # trailing left comment⏎`,
}: {
"leading": [],
"dangling": [
SourceComment {
text: "# trailing operator comment",
position: EndOfLine,
formatted: false,
},
],
"trailing": [],
},
Node {
kind: ExprConstant,
range: 12..13,
source: `5`,
}: {
"leading": [],
"dangling": [],
"trailing": [
SourceComment {
text: "# trailing left comment",
position: EndOfLine,
formatted: false,
},
],
},
Node {
kind: ExprConstant,
range: 125..126,
source: `3`,
}: {
"leading": [
SourceComment {
text: "# leading right comment",
position: OwnLine,
formatted: false,
},
],
"dangling": [],
"trailing": [],
},
}