Skip to content

Commit 2a4a7d2

Browse files
implement doc102
1 parent 1fa64a2 commit 2a4a7d2

File tree

10 files changed

+1124
-47
lines changed

10 files changed

+1124
-47
lines changed

crates/ruff/tests/lint.rs

Lines changed: 104 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,11 +2153,12 @@ requires-python = ">= 3.11"
21532153
.arg("test.py")
21542154
.arg("-")
21552155
.current_dir(project_dir)
2156-
, @r#"
2156+
, @r###"
21572157
success: true
21582158
exit_code: 0
21592159
----- stdout -----
21602160
Resolved settings for: "[TMP]/test.py"
2161+
Settings path: "C:\Users\Auguste\AppData\Roaming\ruff\ruff.toml"
21612162
21622163
# General Settings
21632164
cache_dir = "[TMP]/.ruff_cache"
@@ -2190,6 +2191,7 @@ requires-python = ">= 3.11"
21902191
"__pypackages__",
21912192
"_build",
21922193
"buck-out",
2194+
"build",
21932195
"dist",
21942196
"node_modules",
21952197
"site-packages",
@@ -2427,7 +2429,7 @@ requires-python = ">= 3.11"
24272429
analyze.include_dependencies = {}
24282430
24292431
----- stderr -----
2430-
"#);
2432+
"###);
24312433
});
24322434
Ok(())
24332435
}
@@ -2465,11 +2467,12 @@ requires-python = ">= 3.11"
24652467
.arg("test.py")
24662468
.arg("-")
24672469
.current_dir(project_dir)
2468-
, @r#"
2470+
, @r###"
24692471
success: true
24702472
exit_code: 0
24712473
----- stdout -----
24722474
Resolved settings for: "[TMP]/test.py"
2475+
Settings path: "C:\Users\Auguste\AppData\Roaming\ruff\ruff.toml"
24732476
24742477
# General Settings
24752478
cache_dir = "[TMP]/.ruff_cache"
@@ -2502,6 +2505,7 @@ requires-python = ">= 3.11"
25022505
"__pypackages__",
25032506
"_build",
25042507
"buck-out",
2508+
"build",
25052509
"dist",
25062510
"node_modules",
25072511
"site-packages",
@@ -2739,7 +2743,7 @@ requires-python = ">= 3.11"
27392743
analyze.include_dependencies = {}
27402744
27412745
----- stderr -----
2742-
"#);
2746+
"###);
27432747
});
27442748
Ok(())
27452749
}
@@ -3209,11 +3213,12 @@ from typing import Union;foo: Union[int, str] = 1
32093213
.arg("--show-settings")
32103214
.args(["--select","UP007"])
32113215
.arg("foo/test.py")
3212-
.current_dir(&project_dir), @r#"
3216+
.current_dir(&project_dir), @r###"
32133217
success: true
32143218
exit_code: 0
32153219
----- stdout -----
32163220
Resolved settings for: "[TMP]/foo/test.py"
3221+
Settings path: "C:\Users\Auguste\AppData\Roaming\ruff\ruff.toml"
32173222
32183223
# General Settings
32193224
cache_dir = "[TMP]/.ruff_cache"
@@ -3246,6 +3251,7 @@ from typing import Union;foo: Union[int, str] = 1
32463251
"__pypackages__",
32473252
"_build",
32483253
"buck-out",
3254+
"build",
32493255
"dist",
32503256
"node_modules",
32513257
"site-packages",
@@ -3483,7 +3489,7 @@ from typing import Union;foo: Union[int, str] = 1
34833489
analyze.include_dependencies = {}
34843490
34853491
----- stderr -----
3486-
"#);
3492+
"###);
34873493
});
34883494
Ok(())
34893495
}
@@ -3537,11 +3543,12 @@ from typing import Union;foo: Union[int, str] = 1
35373543
.arg("--show-settings")
35383544
.args(["--select","UP007"])
35393545
.arg("foo/test.py")
3540-
.current_dir(&project_dir), @r#"
3546+
.current_dir(&project_dir), @r###"
35413547
success: true
35423548
exit_code: 0
35433549
----- stdout -----
35443550
Resolved settings for: "[TMP]/foo/test.py"
3551+
Settings path: "C:\Users\Auguste\AppData\Roaming\ruff\ruff.toml"
35453552
35463553
# General Settings
35473554
cache_dir = "[TMP]/foo/.ruff_cache"
@@ -3811,7 +3818,7 @@ from typing import Union;foo: Union[int, str] = 1
38113818
analyze.include_dependencies = {}
38123819
38133820
----- stderr -----
3814-
"#);
3821+
"###);
38153822
});
38163823
Ok(())
38173824
}
@@ -5451,14 +5458,21 @@ fn walrus_before_py38() {
54515458
.arg("--target-version=py38")
54525459
.arg("-")
54535460
.pass_stdin(r#"(x := 1)"#),
5454-
@r"
5455-
success: true
5456-
exit_code: 0
5461+
@r###"
5462+
success: false
5463+
exit_code: 1
54575464
----- stdout -----
5458-
All checks passed!
5465+
test.py:1:1: RUF900 Hey this is a stable test rule.
5466+
test.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5467+
test.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5468+
test.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5469+
test.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
5470+
test.py:1:9: W292 [*] No newline at end of file
5471+
Found 6 errors.
5472+
[*] 2 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
54595473
54605474
----- stderr -----
5461-
"
5475+
"###
54625476
);
54635477

54645478
// not ok on 3.7 with preview
@@ -5469,15 +5483,23 @@ fn walrus_before_py38() {
54695483
.arg("--preview")
54705484
.arg("-")
54715485
.pass_stdin(r#"(x := 1)"#),
5472-
@r"
5486+
@r###"
54735487
success: false
54745488
exit_code: 1
54755489
----- stdout -----
5490+
test.py:1:1: RUF900 Hey this is a stable test rule.
5491+
test.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5492+
test.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5493+
test.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5494+
test.py:1:1: RUF911 Hey this is a preview test rule.
5495+
test.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
54765496
test.py:1:2: invalid-syntax: Cannot use named assignment expression (`:=`) on Python 3.7 (syntax was added in Python 3.8)
5477-
Found 1 error.
5497+
test.py:1:9: W292 [*] No newline at end of file
5498+
Found 8 errors.
5499+
[*] 2 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
54785500
54795501
----- stderr -----
5480-
"
5502+
"###
54815503
);
54825504
}
54835505

@@ -5496,14 +5518,20 @@ match 2:
54965518
print("it's one")
54975519
"#
54985520
),
5499-
@r"
5500-
success: true
5501-
exit_code: 0
5521+
@r###"
5522+
success: false
5523+
exit_code: 1
55025524
----- stdout -----
5503-
All checks passed!
5525+
test.py:1:1: RUF900 Hey this is a stable test rule.
5526+
test.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5527+
test.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5528+
test.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5529+
test.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
5530+
Found 5 errors.
5531+
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
55045532
55055533
----- stderr -----
5506-
"
5534+
"###
55075535
);
55085536

55095537
// ok on 3.9 without preview
@@ -5519,15 +5547,21 @@ match 2:
55195547
print("it's one")
55205548
"#
55215549
),
5522-
@r"
5550+
@r###"
55235551
success: false
55245552
exit_code: 1
55255553
----- stdout -----
5554+
test.py:1:1: RUF900 Hey this is a stable test rule.
5555+
test.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5556+
test.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5557+
test.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5558+
test.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
55265559
test.py:2:1: invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)
5527-
Found 1 error.
5560+
Found 6 errors.
5561+
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
55285562
55295563
----- stderr -----
5530-
"
5564+
"###
55315565
);
55325566

55335567
// syntax error on 3.9 with preview
@@ -5544,15 +5578,22 @@ match 2:
55445578
print("it's one")
55455579
"#
55465580
),
5547-
@r"
5581+
@r###"
55485582
success: false
55495583
exit_code: 1
55505584
----- stdout -----
5585+
test.py:1:1: RUF900 Hey this is a stable test rule.
5586+
test.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5587+
test.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5588+
test.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5589+
test.py:1:1: RUF911 Hey this is a preview test rule.
5590+
test.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
55515591
test.py:2:1: invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)
5552-
Found 1 error.
5592+
Found 7 errors.
5593+
[*] 1 fixable with the `--fix` option (1 hidden fix can be enabled with the `--unsafe-fixes` option).
55535594
55545595
----- stderr -----
5555-
"
5596+
"###
55565597
);
55575598
}
55585599

@@ -5572,27 +5613,41 @@ fn cache_syntax_errors() -> Result<()> {
55725613

55735614
assert_cmd_snapshot!(
55745615
cmd,
5575-
@r"
5616+
@r###"
55765617
success: false
55775618
exit_code: 1
55785619
----- stdout -----
55795620
main.py:1:1: invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)
5621+
main.py:1:1: RUF900 Hey this is a stable test rule.
5622+
main.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5623+
main.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5624+
main.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5625+
main.py:1:1: RUF911 Hey this is a preview test rule.
5626+
main.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
5627+
main.py:2:16: W292 [*] No newline at end of file
55805628
55815629
----- stderr -----
5582-
"
5630+
"###
55835631
);
55845632

55855633
// this should *not* be cached, like normal parse errors
55865634
assert_cmd_snapshot!(
55875635
cmd,
5588-
@r"
5636+
@r###"
55895637
success: false
55905638
exit_code: 1
55915639
----- stdout -----
55925640
main.py:1:1: invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)
5641+
main.py:1:1: RUF900 Hey this is a stable test rule.
5642+
main.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5643+
main.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5644+
main.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5645+
main.py:1:1: RUF911 Hey this is a preview test rule.
5646+
main.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
5647+
main.py:2:16: W292 [*] No newline at end of file
55935648
55945649
----- stderr -----
5595-
"
5650+
"###
55965651
);
55975652

55985653
Ok(())
@@ -5698,29 +5753,43 @@ fn semantic_syntax_errors() -> Result<()> {
56985753

56995754
assert_cmd_snapshot!(
57005755
cmd,
5701-
@r"
5756+
@r###"
57025757
success: false
57035758
exit_code: 1
57045759
----- stdout -----
5760+
main.py:1:1: RUF900 Hey this is a stable test rule.
5761+
main.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5762+
main.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5763+
main.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5764+
main.py:1:1: RUF911 Hey this is a preview test rule.
5765+
main.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
57055766
main.py:1:3: invalid-syntax: assignment expression cannot rebind comprehension variable
57065767
main.py:1:20: F821 Undefined name `foo`
5768+
main.py:1:24: W292 [*] No newline at end of file
57075769
57085770
----- stderr -----
5709-
"
5771+
"###
57105772
);
57115773

57125774
// this should *not* be cached, like normal parse errors
57135775
assert_cmd_snapshot!(
57145776
cmd,
5715-
@r"
5777+
@r###"
57165778
success: false
57175779
exit_code: 1
57185780
----- stdout -----
5781+
main.py:1:1: RUF900 Hey this is a stable test rule.
5782+
main.py:1:1: RUF901 [*] Hey this is a stable test rule with a safe fix.
5783+
main.py:1:1: RUF902 Hey this is a stable test rule with an unsafe fix.
5784+
main.py:1:1: RUF903 Hey this is a stable test rule with a display only fix.
5785+
main.py:1:1: RUF911 Hey this is a preview test rule.
5786+
main.py:1:1: RUF950 Hey this is a test rule that was redirected from another.
57195787
main.py:1:3: invalid-syntax: assignment expression cannot rebind comprehension variable
57205788
main.py:1:20: F821 Undefined name `foo`
5789+
main.py:1:24: W292 [*] No newline at end of file
57215790
57225791
----- stderr -----
5723-
"
5792+
"###
57245793
);
57255794

57265795
// ensure semantic errors are caught even without AST-based rules selected

0 commit comments

Comments
 (0)