-
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.
Support
fmt: skip
on statement and decorator level
- Loading branch information
1 parent
2d86e78
commit 142d47b
Showing
40 changed files
with
540 additions
and
304 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/decorators.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,19 @@ | ||
|
||
@FormattedDecorator(a =b) | ||
# leading comment | ||
@MyDecorator( # dangling comment | ||
list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12], x = some_other_function_call({ "test": "value", "more": "other"})) # fmt: skip | ||
# leading class comment | ||
class Test: | ||
pass | ||
|
||
|
||
|
||
@FormattedDecorator(a =b) | ||
# leading comment | ||
@MyDecorator( # dangling comment | ||
list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12], x = some_other_function_call({ "test": "value", "more": "other"})) # fmt: skip | ||
# leading class comment | ||
def test(): | ||
pass | ||
|
13 changes: 13 additions & 0 deletions
13
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_skip/docstrings.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,13 @@ | ||
def test(): | ||
# leading comment | ||
""" This docstring does not | ||
get formatted | ||
""" # fmt: skip | ||
# trailing comment | ||
|
||
def test(): | ||
# leading comment | ||
""" This docstring gets formatted | ||
""" # trailing comment | ||
|
||
and_this + gets + formatted + too |
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
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
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
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
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
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
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
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
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
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
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,13 +1,22 @@ | ||
use crate::{FormatNodeRule, PyFormatter}; | ||
use ruff_formatter::prelude::text; | ||
use ruff_formatter::{Format, FormatResult}; | ||
use ruff_python_ast::StmtBreak; | ||
|
||
use crate::comments::{SourceComment, SuppressionKind}; | ||
use crate::prelude::*; | ||
use crate::FormatNodeRule; | ||
|
||
#[derive(Default)] | ||
pub struct FormatStmtBreak; | ||
|
||
impl FormatNodeRule<StmtBreak> for FormatStmtBreak { | ||
fn fmt_fields(&self, _item: &StmtBreak, f: &mut PyFormatter) -> FormatResult<()> { | ||
text("break").fmt(f) | ||
} | ||
|
||
fn is_suppressed( | ||
&self, | ||
trailing_comments: &[SourceComment], | ||
context: &PyFormatContext, | ||
) -> bool { | ||
SuppressionKind::has_skip_comment(trailing_comments, context.source()) | ||
} | ||
} |
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
15 changes: 12 additions & 3 deletions
15
crates/ruff_python_formatter/src/statement/stmt_continue.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,13 +1,22 @@ | ||
use crate::{FormatNodeRule, PyFormatter}; | ||
use ruff_formatter::prelude::text; | ||
use ruff_formatter::{Format, FormatResult}; | ||
use crate::comments::{SourceComment, SuppressionKind}; | ||
use ruff_python_ast::StmtContinue; | ||
|
||
use crate::prelude::*; | ||
use crate::FormatNodeRule; | ||
|
||
#[derive(Default)] | ||
pub struct FormatStmtContinue; | ||
|
||
impl FormatNodeRule<StmtContinue> for FormatStmtContinue { | ||
fn fmt_fields(&self, _item: &StmtContinue, f: &mut PyFormatter) -> FormatResult<()> { | ||
text("continue").fmt(f) | ||
} | ||
|
||
fn is_suppressed( | ||
&self, | ||
trailing_comments: &[SourceComment], | ||
context: &PyFormatContext, | ||
) -> bool { | ||
SuppressionKind::has_skip_comment(trailing_comments, context.source()) | ||
} | ||
} |
Oops, something went wrong.