Skip to content

Commit 4bda9da

Browse files
dylwil3ntBre
authored andcommitted
[pylint] Stabilize adding U+061C to bidirectional-unicode (PLE2502) (#20276)
Introduced in #20106. Removed gating. Updated tests. No documentation to update.
1 parent 9d972d0 commit 4bda9da

File tree

5 files changed

+14
-91
lines changed

5 files changed

+14
-91
lines changed

crates/ruff_linter/src/preview.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,6 @@ pub(crate) const fn is_maxsplit_without_separator_fix_enabled(settings: &LinterS
249249
settings.preview.is_enabled()
250250
}
251251

252-
// https://github.com/astral-sh/ruff/pull/20106
253-
pub(crate) const fn is_bidi_forbid_arabic_letter_mark_enabled(settings: &LinterSettings) -> bool {
254-
settings.preview.is_enabled()
255-
}
256-
257252
// https://github.com/astral-sh/ruff/pull/20027
258253
pub(crate) const fn is_unnecessary_default_type_args_stubs_enabled(
259254
settings: &LinterSettings,

crates/ruff_linter/src/rules/pylint/mod.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -252,30 +252,6 @@ mod tests {
252252
Ok(())
253253
}
254254

255-
#[test_case(Rule::BidirectionalUnicode, Path::new("bidirectional_unicode.py"))]
256-
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
257-
let snapshot = format!(
258-
"preview__{}_{}",
259-
rule_code.noqa_code(),
260-
path.to_string_lossy()
261-
);
262-
let diagnostics = test_path(
263-
Path::new("pylint").join(path).as_path(),
264-
&LinterSettings {
265-
pylint: pylint::settings::Settings {
266-
allow_dunder_method_names: FxHashSet::from_iter([
267-
"__special_custom_magic__".to_string()
268-
]),
269-
..pylint::settings::Settings::default()
270-
},
271-
preview: PreviewMode::Enabled,
272-
..LinterSettings::for_rule(rule_code)
273-
},
274-
)?;
275-
assert_diagnostics!(snapshot, diagnostics);
276-
Ok(())
277-
}
278-
279255
#[test]
280256
fn continue_in_finally() -> Result<()> {
281257
let diagnostics = test_path(

crates/ruff_linter/src/rules/pylint/rules/bidirectional_unicode.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
use ruff_macros::{ViolationMetadata, derive_message_formats};
22
use ruff_source_file::Line;
33

4-
use crate::{
5-
Violation, checkers::ast::LintContext, preview::is_bidi_forbid_arabic_letter_mark_enabled,
6-
};
4+
use crate::{Violation, checkers::ast::LintContext};
75

8-
const BIDI_UNICODE: [char; 10] = [
6+
const BIDI_UNICODE: [char; 11] = [
97
'\u{202A}', //{LEFT-TO-RIGHT EMBEDDING}
108
'\u{202B}', //{RIGHT-TO-LEFT EMBEDDING}
119
'\u{202C}', //{POP DIRECTIONAL FORMATTING}
@@ -19,6 +17,7 @@ const BIDI_UNICODE: [char; 10] = [
1917
// https://peps.python.org/pep-0672/
2018
// so the list above might not be complete
2119
'\u{200F}', //{RIGHT-TO-LEFT MARK}
20+
'\u{061C}', //{ARABIC LETTER MARK}
2221
// We don't use
2322
// "\u200E" # \n{LEFT-TO-RIGHT MARK}
2423
// as this is the default for latin files and can't be used
@@ -62,12 +61,7 @@ impl Violation for BidirectionalUnicode {
6261

6362
/// PLE2502
6463
pub(crate) fn bidirectional_unicode(line: &Line, context: &LintContext) {
65-
if line.contains(BIDI_UNICODE)
66-
|| (is_bidi_forbid_arabic_letter_mark_enabled(context.settings())
67-
&& line.contains(
68-
'\u{061C}', //{ARABIC LETTER MARK}
69-
))
70-
{
64+
if line.contains(BIDI_UNICODE) {
7165
context.report_diagnostic(BidirectionalUnicode, line.full_range());
7266
}
7367
}

crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLE2502_bidirectional_unicode.py.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ PLE2502 Contains control characters that can permit obfuscated code
2121
7 | # E2502
2222
|
2323

24+
PLE2502 Contains control characters that can permit obfuscated code
25+
--> bidirectional_unicode.py:8:1
26+
|
27+
7 | # E2502
28+
8 | another = "" * 50 # "؜x" is assigned
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
9 |
31+
10 | # E2502
32+
|
33+
2434
PLE2502 Contains control characters that can permit obfuscated code
2535
--> bidirectional_unicode.py:11:1
2636
|

crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__preview__PLE2502_bidirectional_unicode.py.snap

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)