Skip to content

Commit daa0d26

Browse files
committed
Merge branch 'main' into brent/violation-rules
2 parents 2103675 + a3ee6bb commit daa0d26

File tree

644 files changed

+5409
-4558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

644 files changed

+5409
-4558
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_implicit_str_concat/ISC.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,99 @@
9191
_ = "\12""8" # fix should be "\128"
9292
_ = "\12""foo" # fix should be "\12foo"
9393
_ = "\12" "" # fix should be "\12"
94+
95+
96+
# Mixed literal + non-literal scenarios
97+
_ = (
98+
"start" +
99+
variable +
100+
"end"
101+
)
102+
103+
_ = (
104+
f"format" +
105+
func_call() +
106+
"literal"
107+
)
108+
109+
_ = (
110+
rf"raw_f{x}" +
111+
r"raw_normal"
112+
)
113+
114+
115+
# Different prefix combinations
116+
_ = (
117+
u"unicode" +
118+
r"raw"
119+
)
120+
121+
_ = (
122+
rb"raw_bytes" +
123+
b"normal_bytes"
124+
)
125+
126+
_ = (
127+
b"bytes" +
128+
b"with_bytes"
129+
)
130+
131+
# Repeated concatenation
132+
133+
_ = ("a" +
134+
"b" +
135+
"c" +
136+
"d" + "e"
137+
)
138+
139+
_ = ("a"
140+
+ "b"
141+
+ "c"
142+
+ "d"
143+
+ "e"
144+
)
145+
146+
_ = (
147+
"start" +
148+
variable + # comment
149+
"end"
150+
)
151+
152+
_ = (
153+
"start" +
154+
variable
155+
# leading comment
156+
+ "end"
157+
)
158+
159+
_ = (
160+
"first"
161+
+ "second" # extra spaces around +
162+
)
163+
164+
_ = (
165+
"first" + # trailing spaces before +
166+
"second"
167+
)
168+
169+
_ = ((
170+
"deep" +
171+
"nesting"
172+
))
173+
174+
_ = (
175+
"contains + plus" +
176+
"another string"
177+
)
178+
179+
_ = (
180+
"start"
181+
# leading comment
182+
+ "end"
183+
)
184+
185+
_ = (
186+
"start" +
187+
# leading comment
188+
"end"
189+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
from pathlib import Path
3+
4+
5+
os.symlink("usr/bin/python", "tmp/python")
6+
os.symlink(b"usr/bin/python", b"tmp/python")
7+
Path("tmp/python").symlink_to("usr/bin/python") # Ok
8+
9+
os.symlink("usr/bin/python", "tmp/python", target_is_directory=True)
10+
os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True)
11+
Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok
12+
13+
fd = os.open(".", os.O_RDONLY)
14+
os.symlink("source.txt", "link.txt", dir_fd=fd) # Ok: dir_fd is not supported by pathlib
15+
os.close(fd)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
class A:
2+
...
3+
4+
5+
class A(metaclass=type):
6+
...
7+
8+
9+
class A(
10+
metaclass=type
11+
):
12+
...
13+
14+
15+
class A(
16+
metaclass=type
17+
#
18+
):
19+
...
20+
21+
22+
class A(
23+
#
24+
metaclass=type
25+
):
26+
...
27+
28+
29+
class A(
30+
metaclass=type,
31+
#
32+
):
33+
...
34+
35+
36+
class A(
37+
#
38+
metaclass=type,
39+
#
40+
):
41+
...
42+
43+
44+
class B(A, metaclass=type):
45+
...
46+
47+
48+
class B(
49+
A,
50+
metaclass=type,
51+
):
52+
...
53+
54+
55+
class B(
56+
A,
57+
# comment
58+
metaclass=type,
59+
):
60+
...
61+
62+
63+
def foo():
64+
class A(metaclass=type):
65+
...
66+
67+
68+
class A(
69+
metaclass=type # comment
70+
,
71+
):
72+
...
73+
74+
75+
type = str
76+
77+
class Foo(metaclass=type):
78+
...
79+
80+
81+
import builtins
82+
83+
class A(metaclass=builtins.type):
84+
...
Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use ruff_text_size::Ranged;
22

3+
use crate::Fix;
34
use crate::checkers::ast::Checker;
45
use crate::codes::Rule;
56
use crate::rules::{
67
flake8_import_conventions, flake8_pyi, flake8_pytest_style, flake8_type_checking, pyflakes,
78
pylint, pyupgrade, refurb, ruff,
89
};
9-
use crate::{Diagnostic, Fix};
1010

1111
/// Run lint rules over the [`Binding`]s.
1212
pub(crate) fn bindings(checker: &Checker) {
@@ -38,92 +38,64 @@ pub(crate) fn bindings(checker: &Checker) {
3838
.dummy_variable_rgx
3939
.is_match(binding.name(checker.source()))
4040
{
41-
let mut diagnostic = Diagnostic::new(
42-
pyflakes::rules::UnusedVariable {
43-
name: binding.name(checker.source()).to_string(),
44-
},
45-
binding.range(),
46-
);
47-
diagnostic.try_set_fix(|| {
48-
pyflakes::fixes::remove_exception_handler_assignment(binding, checker.locator)
41+
checker
42+
.report_diagnostic(
43+
pyflakes::rules::UnusedVariable {
44+
name: binding.name(checker.source()).to_string(),
45+
},
46+
binding.range(),
47+
)
48+
.try_set_fix(|| {
49+
pyflakes::fixes::remove_exception_handler_assignment(
50+
binding,
51+
checker.locator,
52+
)
4953
.map(Fix::safe_edit)
50-
});
51-
checker.report_diagnostic(diagnostic);
54+
});
5255
}
5356
}
5457
if checker.enabled(Rule::InvalidAllFormat) {
55-
if let Some(diagnostic) = pylint::rules::invalid_all_format(binding) {
56-
checker.report_diagnostic(diagnostic);
57-
}
58+
pylint::rules::invalid_all_format(checker, binding);
5859
}
5960
if checker.enabled(Rule::InvalidAllObject) {
60-
if let Some(diagnostic) = pylint::rules::invalid_all_object(binding) {
61-
checker.report_diagnostic(diagnostic);
62-
}
61+
pylint::rules::invalid_all_object(checker, binding);
6362
}
6463
if checker.enabled(Rule::NonAsciiName) {
65-
if let Some(diagnostic) = pylint::rules::non_ascii_name(binding, checker.locator) {
66-
checker.report_diagnostic(diagnostic);
67-
}
64+
pylint::rules::non_ascii_name(checker, binding);
6865
}
6966
if checker.enabled(Rule::UnconventionalImportAlias) {
70-
if let Some(diagnostic) = flake8_import_conventions::rules::unconventional_import_alias(
67+
flake8_import_conventions::rules::unconventional_import_alias(
7168
checker,
7269
binding,
7370
&checker.settings.flake8_import_conventions.aliases,
74-
) {
75-
checker.report_diagnostic(diagnostic);
76-
}
71+
);
7772
}
7873
if checker.enabled(Rule::UnaliasedCollectionsAbcSetImport) {
79-
if let Some(diagnostic) =
80-
flake8_pyi::rules::unaliased_collections_abc_set_import(checker, binding)
81-
{
82-
checker.report_diagnostic(diagnostic);
83-
}
74+
flake8_pyi::rules::unaliased_collections_abc_set_import(checker, binding);
8475
}
8576
if !checker.source_type.is_stub() && checker.enabled(Rule::UnquotedTypeAlias) {
8677
flake8_type_checking::rules::unquoted_type_alias(checker, binding);
8778
}
8879
if checker.enabled(Rule::UnsortedDunderSlots) {
89-
if let Some(diagnostic) = ruff::rules::sort_dunder_slots(checker, binding) {
90-
checker.report_diagnostic(diagnostic);
91-
}
80+
ruff::rules::sort_dunder_slots(checker, binding);
9281
}
9382
if checker.enabled(Rule::UsedDummyVariable) {
94-
if let Some(diagnostic) = ruff::rules::used_dummy_variable(checker, binding, binding_id)
95-
{
96-
checker.report_diagnostic(diagnostic);
97-
}
83+
ruff::rules::used_dummy_variable(checker, binding, binding_id);
9884
}
9985
if checker.enabled(Rule::AssignmentInAssert) {
100-
if let Some(diagnostic) = ruff::rules::assignment_in_assert(checker, binding) {
101-
checker.report_diagnostic(diagnostic);
102-
}
86+
ruff::rules::assignment_in_assert(checker, binding);
10387
}
10488
if checker.enabled(Rule::PytestUnittestRaisesAssertion) {
105-
if let Some(diagnostic) =
106-
flake8_pytest_style::rules::unittest_raises_assertion_binding(checker, binding)
107-
{
108-
checker.report_diagnostic(diagnostic);
109-
}
89+
flake8_pytest_style::rules::unittest_raises_assertion_binding(checker, binding);
11090
}
11191
if checker.enabled(Rule::ForLoopWrites) {
112-
if let Some(diagnostic) = refurb::rules::for_loop_writes_binding(checker, binding) {
113-
checker.report_diagnostic(diagnostic);
114-
}
92+
refurb::rules::for_loop_writes_binding(checker, binding);
11593
}
11694
if checker.enabled(Rule::CustomTypeVarForSelf) {
117-
if let Some(diagnostic) =
118-
flake8_pyi::rules::custom_type_var_instead_of_self(checker, binding)
119-
{
120-
checker.report_diagnostic(diagnostic);
121-
}
95+
flake8_pyi::rules::custom_type_var_instead_of_self(checker, binding);
12296
}
12397
if checker.enabled(Rule::PrivateTypeParameter) {
124-
if let Some(diagnostic) = pyupgrade::rules::private_type_parameter(checker, binding) {
125-
checker.report_diagnostic(diagnostic);
126-
}
98+
pyupgrade::rules::private_type_parameter(checker, binding);
12799
}
128100
}
129101
}

0 commit comments

Comments
 (0)