-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
badbfb2
commit 161ed4a
Showing
6 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/global.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def f(): | ||
global x, y, z | ||
|
||
|
||
def f(): | ||
# leading comment | ||
global x, y, z # end-of-line comment | ||
# trailing comment | ||
|
||
|
||
def f(): | ||
global analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model |
12 changes: 12 additions & 0 deletions
12
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/nonlocal.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
def f(): | ||
nonlocal x, y, z | ||
|
||
|
||
def f(): | ||
# leading comment | ||
nonlocal x, y, z # end-of-line comment | ||
# trailing comment | ||
|
||
|
||
def f(): | ||
nonlocal analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; | ||
use ruff_formatter::{write, Buffer, FormatResult}; | ||
use ruff_formatter::{format_args, write, Buffer, FormatResult}; | ||
use ruff_python_ast::StmtGlobal; | ||
|
||
use crate::prelude::*; | ||
use crate::{FormatNodeRule, FormattedIterExt, PyFormatter}; | ||
|
||
#[derive(Default)] | ||
pub struct FormatStmtGlobal; | ||
|
||
impl FormatNodeRule<StmtGlobal> for FormatStmtGlobal { | ||
fn fmt_fields(&self, item: &StmtGlobal, f: &mut PyFormatter) -> FormatResult<()> { | ||
write!(f, [not_yet_implemented(item)]) | ||
write!(f, [text("global"), space()])?; | ||
|
||
f.join_with(format_args![text(","), space()]) | ||
.entries(item.names.iter().formatted()) | ||
.finish() | ||
} | ||
} |
12 changes: 9 additions & 3 deletions
12
crates/ruff_python_formatter/src/statement/stmt_nonlocal.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
use crate::{not_yet_implemented, FormatNodeRule, PyFormatter}; | ||
use ruff_formatter::{write, Buffer, FormatResult}; | ||
use ruff_formatter::{format_args, write, Buffer, FormatResult}; | ||
use ruff_python_ast::StmtNonlocal; | ||
|
||
use crate::prelude::*; | ||
use crate::{FormatNodeRule, FormattedIterExt, PyFormatter}; | ||
|
||
#[derive(Default)] | ||
pub struct FormatStmtNonlocal; | ||
|
||
impl FormatNodeRule<StmtNonlocal> for FormatStmtNonlocal { | ||
fn fmt_fields(&self, item: &StmtNonlocal, f: &mut PyFormatter) -> FormatResult<()> { | ||
write!(f, [not_yet_implemented(item)]) | ||
write!(f, [text("nonlocal"), space()])?; | ||
|
||
f.join_with(format_args![text(","), space()]) | ||
.entries(item.names.iter().formatted()) | ||
.finish() | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
crates/ruff_python_formatter/tests/snapshots/format@statement__global.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
source: crates/ruff_python_formatter/tests/fixtures.rs | ||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/global.py | ||
--- | ||
## Input | ||
```py | ||
def f(): | ||
global x, y, z | ||
def f(): | ||
# leading comment | ||
global x, y, z # end-of-line comment | ||
# trailing comment | ||
def f(): | ||
global analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model | ||
``` | ||
|
||
## Output | ||
```py | ||
def f(): | ||
global x, y, z | ||
def f(): | ||
# leading comment | ||
global x, y, z # end-of-line comment | ||
# trailing comment | ||
def f(): | ||
global analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model | ||
``` | ||
|
||
|
||
|
38 changes: 38 additions & 0 deletions
38
crates/ruff_python_formatter/tests/snapshots/format@statement__nonlocal.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
source: crates/ruff_python_formatter/tests/fixtures.rs | ||
input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/nonlocal.py | ||
--- | ||
## Input | ||
```py | ||
def f(): | ||
nonlocal x, y, z | ||
def f(): | ||
# leading comment | ||
nonlocal x, y, z # end-of-line comment | ||
# trailing comment | ||
def f(): | ||
nonlocal analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model | ||
``` | ||
|
||
## Output | ||
```py | ||
def f(): | ||
nonlocal x, y, z | ||
def f(): | ||
# leading comment | ||
nonlocal x, y, z # end-of-line comment | ||
# trailing comment | ||
def f(): | ||
nonlocal analyze_featuremap_layer, analyze_featuremapcompression_layer, analyze_latencies_post, analyze_motions_layer, analyze_size_model | ||
``` | ||
|
||
|
||
|