-
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.
Add most formatter options to
ruff.toml
/ pyproject.toml
- Loading branch information
1 parent
f8f1cd5
commit eb3bf39
Showing
22 changed files
with
651 additions
and
136 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#![cfg(not(target_family = "wasm"))] | ||
|
||
use std::fs; | ||
use std::process::Command; | ||
use std::str; | ||
|
||
use anyhow::Result; | ||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; | ||
use tempfile::TempDir; | ||
|
||
const BIN_NAME: &str = "ruff"; | ||
|
||
#[test] | ||
fn default_options() -> Result<()> { | ||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) | ||
.args(["format", "--isolated"]) | ||
.arg("-") | ||
.pass_stdin(r#" | ||
def foo(arg1, arg2,): | ||
print('Should\'t change quotes') | ||
if condition: | ||
print('Hy "Micha"') # Should not change quotes | ||
"#), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
def foo( | ||
arg1, | ||
arg2, | ||
): | ||
print("Should't change quotes") | ||
if condition: | ||
print('Hy "Micha"') # Should not change quotes | ||
----- stderr ----- | ||
warning: `ruff format` is a work-in-progress, subject to change at any time, and intended only for experimentation. | ||
"###); | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn format_options() -> Result<()> { | ||
let tempdir = TempDir::new()?; | ||
let ruff_toml = tempdir.path().join("ruff.toml"); | ||
fs::write( | ||
&ruff_toml, | ||
r#" | ||
[format] | ||
indent-style = "tab" | ||
quote-style = "single" | ||
skip-magic-trailing-comma = true | ||
line-ending = "cr-lf" | ||
"#, | ||
)?; | ||
|
||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) | ||
.args(["format", "--config"]) | ||
.arg(&ruff_toml) | ||
.arg("-") | ||
.pass_stdin(r#" | ||
def foo(arg1, arg2,): | ||
print("Shouldn't change quotes") | ||
if condition: | ||
print("Should change quotes") | ||
"#), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
def foo(arg1, arg2): | ||
print("Shouldn't change quotes") | ||
if condition: | ||
print('Should change quotes') | ||
----- stderr ----- | ||
warning: `ruff format` is a work-in-progress, subject to change at any time, and intended only for experimentation. | ||
"###); | ||
Ok(()) | ||
} |
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
8 changes: 4 additions & 4 deletions
8
crates/ruff_python_formatter/resources/test/fixtures/ruff/docstring.options.json
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,18 +1,18 @@ | ||
[ | ||
{ | ||
"indent_style": "Space", | ||
"indent_style": "space", | ||
"indent_width": 4 | ||
}, | ||
{ | ||
"indent_style": "Space", | ||
"indent_style": "space", | ||
"indent_width": 2 | ||
}, | ||
{ | ||
"indent_style": "Tab", | ||
"indent_style": "tab", | ||
"indent_width": 8 | ||
}, | ||
{ | ||
"indent_style": "Tab", | ||
"indent_style": "tab", | ||
"indent_width": 4 | ||
} | ||
] |
4 changes: 2 additions & 2 deletions
4
...f_python_formatter/resources/test/fixtures/ruff/fmt_on_off/fmt_off_docstring.options.json
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,10 +1,10 @@ | ||
[ | ||
{ | ||
"indent_style": "Space", | ||
"indent_style": "space", | ||
"indent_width": 4 | ||
}, | ||
{ | ||
"indent_style": "Space", | ||
"indent_style": "space", | ||
"indent_width": 2 | ||
} | ||
] |
6 changes: 3 additions & 3 deletions
6
crates/ruff_python_formatter/resources/test/fixtures/ruff/fmt_on_off/indent.options.json
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,13 @@ | ||
[ | ||
{ | ||
"indent_style": "Space", | ||
"indent_style": "space", | ||
"indent_width": 4 | ||
}, | ||
{ | ||
"indent_style": "Space", | ||
"indent_style": "space", | ||
"indent_width": 1 | ||
}, | ||
{ | ||
"indent_style": "Tab" | ||
"indent_style": "tab" | ||
} | ||
] |
6 changes: 3 additions & 3 deletions
6
...python_formatter/resources/test/fixtures/ruff/fmt_on_off/mixed_space_and_tab.options.json
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,13 @@ | ||
[ | ||
{ | ||
"indent_style": "Space", | ||
"indent_style": "space", | ||
"indent_width": 4 | ||
}, | ||
{ | ||
"indent_style": "Space", | ||
"indent_style": "space", | ||
"indent_width": 2 | ||
}, | ||
{ | ||
"indent_style": "Tab" | ||
"indent_style": "tab" | ||
} | ||
] |
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
Oops, something went wrong.