Skip to content

Commit

Permalink
Apply consistent code block labels (#8563)
Browse files Browse the repository at this point in the history
This ensures the python label is used for all python code blocks for
consistency.

## Test Plan

Visual inspection of all changes via git client ensuring no other
changes were made in error.
  • Loading branch information
doolio committed Nov 9, 2023
1 parent 0ea1076 commit 4fdf97a
Show file tree
Hide file tree
Showing 151 changed files with 364 additions and 359 deletions.
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,15 +1415,15 @@ impl<'a> Checker<'a> {
// subsequent nodes are evaluated in the inner scope.
//
// For example, given:
// ```py
// ```python
// class A:
// T = range(10)
//
// L = [x for x in T for y in T]
// ```
//
// Conceptually, this is compiled as:
// ```py
// ```python
// class A:
// T = range(10)
//
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/importer/insertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<'a> Insertion<'a> {
Tok::NonLogicalNewline => {}
Tok::Indent => {
// This is like:
// ```py
// ```python
// if True:
// pass
// ```
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/importer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'a> Importer<'a> {
// We also add a no-op edit to force conflicts with any other fixes that might try to
// remove the import. Consider:
//
// ```py
// ```python
// import sys
//
// quit()
Expand Down
19 changes: 12 additions & 7 deletions crates/ruff_python_formatter/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn black_compatibility() {
// today.
let mut snapshot = String::new();
write!(snapshot, "{}", Header::new("Input")).unwrap();
write!(snapshot, "{}", CodeFrame::new("py", &content)).unwrap();
write!(snapshot, "{}", CodeFrame::new("python", &content)).unwrap();

write!(snapshot, "{}", Header::new("Black Differences")).unwrap();

Expand All @@ -83,10 +83,10 @@ fn black_compatibility() {
write!(snapshot, "{}", CodeFrame::new("diff", &diff)).unwrap();

write!(snapshot, "{}", Header::new("Ruff Output")).unwrap();
write!(snapshot, "{}", CodeFrame::new("py", &formatted_code)).unwrap();
write!(snapshot, "{}", CodeFrame::new("python", &formatted_code)).unwrap();

write!(snapshot, "{}", Header::new("Black Output")).unwrap();
write!(snapshot, "{}", CodeFrame::new("py", &expected_output)).unwrap();
write!(snapshot, "{}", CodeFrame::new("python", &expected_output)).unwrap();

insta::with_settings!({
omit_expression => true,
Expand All @@ -113,7 +113,7 @@ fn format() {

ensure_stability_when_formatting_twice(formatted_code, options.clone(), input_path);

let mut snapshot = format!("## Input\n{}", CodeFrame::new("py", &content));
let mut snapshot = format!("## Input\n{}", CodeFrame::new("python", &content));

let options_path = input_path.with_extension("options.json");
if let Ok(options_file) = fs::File::open(options_path) {
Expand All @@ -135,7 +135,7 @@ fn format() {
"### Output {}\n{}{}",
i + 1,
CodeFrame::new("", &DisplayPyOptions(&options)),
CodeFrame::new("py", &formatted_code)
CodeFrame::new("python", &formatted_code)
)
.unwrap();
}
Expand All @@ -159,14 +159,19 @@ fn format() {
);

if formatted == formatted_preview {
writeln!(snapshot, "## Output\n{}", CodeFrame::new("py", &formatted)).unwrap();
writeln!(
snapshot,
"## Output\n{}",
CodeFrame::new("python", &formatted)
)
.unwrap();
} else {
// Having both snapshots makes it hard to see the difference, so we're keeping only
// diff.
writeln!(
snapshot,
"## Output\n{}\n## Preview changes\n{}",
CodeFrame::new("py", &formatted),
CodeFrame::new("python", &formatted),
CodeFrame::new(
"diff",
TextDiff::from_lines(formatted, formatted_preview)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/condition
---
## Input

```py
```python
long_kwargs_single_line = my_function(
foo="test, this is a sample value",
bar=some_long_value_name_foo_bar_baz if some_boolean_variable else some_fallback_value_foo_bar_baz,
Expand Down Expand Up @@ -149,7 +149,7 @@ def something():

## Ruff Output

```py
```python
long_kwargs_single_line = my_function(
foo="test, this is a sample value",
bar=some_long_value_name_foo_bar_baz
Expand Down Expand Up @@ -238,7 +238,7 @@ def something():

## Black Output

```py
```python
long_kwargs_single_line = my_function(
foo="test, this is a sample value",
bar=(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
def abc ():
return ["hello", "world",
"!"]
Expand Down Expand Up @@ -33,7 +33,7 @@ print( "Incorrect formatting"

## Ruff Output

```py
```python
def abc():
return ["hello", "world", "!"]
Expand All @@ -43,7 +43,7 @@ print("Incorrect formatting")

## Black Output

```py
```python
def abc ():
return ["hello", "world",
"!"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
@dataclass
class DebugVisitor(Visitor[T]):
tree_depth: int = 0
Expand Down Expand Up @@ -79,7 +79,7 @@ class DebugVisitor(Visitor[T]):

## Ruff Output

```py
```python
@dataclass
class DebugVisitor(Visitor[T]):
tree_depth: int = 0
Expand Down Expand Up @@ -116,7 +116,7 @@ class DebugVisitor(Visitor[T]):

## Black Output

```py
```python
@dataclass
class DebugVisitor(Visitor[T]):
tree_depth: int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
# This file doesn't use the standard decomposition.
# Decorator syntax test cases are separated by double # comments.
# Those before the 'output' comment are valid under the old syntax.
Expand Down Expand Up @@ -378,7 +378,7 @@ def f():

## Ruff Output

```py
```python
# This file doesn't use the standard decomposition.
# Decorator syntax test cases are separated by double # comments.
# Those before the 'output' comment are valid under the old syntax.
Expand Down Expand Up @@ -589,7 +589,7 @@ def f():

## Black Output

```py
```python
##
@decorator()()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
class ALonelyClass:
'''
A multiline class docstring.
Expand Down Expand Up @@ -208,7 +208,7 @@ def multiline_backslash_3():

## Ruff Output

```py
```python
class ALonelyClass:
"""
A multiline class docstring.
Expand Down Expand Up @@ -336,7 +336,7 @@ def multiline_backslash_3():

## Black Output

```py
```python
class ALonelyClass:
'''
A multiline class docstring.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
def do_not_touch_this_prefix():
R"""There was a bug where docstring prefixes would be normalized even with -S."""
Expand Down Expand Up @@ -37,7 +37,7 @@ def do_not_touch_this_prefix3():

## Ruff Output

```py
```python
def do_not_touch_this_prefix():
R"""There was a bug where docstring prefixes would be normalized even with -S."""
Expand All @@ -52,7 +52,7 @@ def do_not_touch_this_prefix3():

## Black Output

```py
```python
def do_not_touch_this_prefix():
R"""There was a bug where docstring prefixes would be normalized even with -S."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
# flags: --pyi
from typing import Union
Expand Down Expand Up @@ -119,7 +119,7 @@ def eggs() -> Union[str, int]: ...

## Ruff Output

```py
```python
# flags: --pyi
from typing import Union
Expand Down Expand Up @@ -183,7 +183,7 @@ def eggs() -> Union[str, int]:

## Black Output

```py
```python
from typing import Union
@bird
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
Expand Down Expand Up @@ -324,7 +324,7 @@ long_unmergable_string_with_pragma = (

## Ruff Output

```py
```python
x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."

x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
Expand Down Expand Up @@ -617,7 +617,7 @@ long_unmergable_string_with_pragma = (

## Black Output

```py
```python
x = "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."

x += "This is a really long string that can't possibly be expected to fit all together on one line. In fact it may even take up three or more lines... like four or five... but probably just three."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
importA;()<<0**0#
```

Expand All @@ -25,14 +25,14 @@ importA;()<<0**0#

## Ruff Output

```py
```python
importA
() << 0**0 #
```

## Black Output

```py
```python
importA
(
()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/miscellan
---
## Input

```py
```python
''''''
'\''
Expand Down Expand Up @@ -88,7 +88,7 @@ f"\"{a}\"{'hello' * b}\"{c}\""

## Ruff Output

```py
```python
""""""
"'"
Expand Down Expand Up @@ -151,7 +151,7 @@ f"\"{a}\"{'hello' * b}\"{c}\""
## Black Output
```py
```python
""""""
"'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/black/py_310/pa
---
## Input

```py
```python
import match
match something:
Expand Down Expand Up @@ -162,7 +162,7 @@ match bar1:

## Ruff Output

```py
```python
import match
match something:
Expand Down Expand Up @@ -295,7 +295,7 @@ match bar1:

## Black Output

```py
```python
import match
match something:
Expand Down
Loading

0 comments on commit 4fdf97a

Please sign in to comment.