mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-17 11:03:00 +00:00
[pylint] Stabilize adding U+061C to bidirectional-unicode (PLE2502) (#20276)
Introduced in #20106. Removed gating. Updated tests. No documentation to update.
This commit is contained in:
parent
9d972d0583
commit
4bda9dad68
5 changed files with 14 additions and 91 deletions
|
|
@ -249,11 +249,6 @@ pub(crate) const fn is_maxsplit_without_separator_fix_enabled(settings: &LinterS
|
||||||
settings.preview.is_enabled()
|
settings.preview.is_enabled()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/astral-sh/ruff/pull/20106
|
|
||||||
pub(crate) const fn is_bidi_forbid_arabic_letter_mark_enabled(settings: &LinterSettings) -> bool {
|
|
||||||
settings.preview.is_enabled()
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://github.com/astral-sh/ruff/pull/20027
|
// https://github.com/astral-sh/ruff/pull/20027
|
||||||
pub(crate) const fn is_unnecessary_default_type_args_stubs_enabled(
|
pub(crate) const fn is_unnecessary_default_type_args_stubs_enabled(
|
||||||
settings: &LinterSettings,
|
settings: &LinterSettings,
|
||||||
|
|
|
||||||
|
|
@ -252,30 +252,6 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test_case(Rule::BidirectionalUnicode, Path::new("bidirectional_unicode.py"))]
|
|
||||||
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
|
|
||||||
let snapshot = format!(
|
|
||||||
"preview__{}_{}",
|
|
||||||
rule_code.noqa_code(),
|
|
||||||
path.to_string_lossy()
|
|
||||||
);
|
|
||||||
let diagnostics = test_path(
|
|
||||||
Path::new("pylint").join(path).as_path(),
|
|
||||||
&LinterSettings {
|
|
||||||
pylint: pylint::settings::Settings {
|
|
||||||
allow_dunder_method_names: FxHashSet::from_iter([
|
|
||||||
"__special_custom_magic__".to_string()
|
|
||||||
]),
|
|
||||||
..pylint::settings::Settings::default()
|
|
||||||
},
|
|
||||||
preview: PreviewMode::Enabled,
|
|
||||||
..LinterSettings::for_rule(rule_code)
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
assert_diagnostics!(snapshot, diagnostics);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn continue_in_finally() -> Result<()> {
|
fn continue_in_finally() -> Result<()> {
|
||||||
let diagnostics = test_path(
|
let diagnostics = test_path(
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,9 @@
|
||||||
use ruff_macros::{ViolationMetadata, derive_message_formats};
|
use ruff_macros::{ViolationMetadata, derive_message_formats};
|
||||||
use ruff_source_file::Line;
|
use ruff_source_file::Line;
|
||||||
|
|
||||||
use crate::{
|
use crate::{Violation, checkers::ast::LintContext};
|
||||||
Violation, checkers::ast::LintContext, preview::is_bidi_forbid_arabic_letter_mark_enabled,
|
|
||||||
};
|
|
||||||
|
|
||||||
const BIDI_UNICODE: [char; 10] = [
|
const BIDI_UNICODE: [char; 11] = [
|
||||||
'\u{202A}', //{LEFT-TO-RIGHT EMBEDDING}
|
'\u{202A}', //{LEFT-TO-RIGHT EMBEDDING}
|
||||||
'\u{202B}', //{RIGHT-TO-LEFT EMBEDDING}
|
'\u{202B}', //{RIGHT-TO-LEFT EMBEDDING}
|
||||||
'\u{202C}', //{POP DIRECTIONAL FORMATTING}
|
'\u{202C}', //{POP DIRECTIONAL FORMATTING}
|
||||||
|
|
@ -19,6 +17,7 @@ const BIDI_UNICODE: [char; 10] = [
|
||||||
// https://peps.python.org/pep-0672/
|
// https://peps.python.org/pep-0672/
|
||||||
// so the list above might not be complete
|
// so the list above might not be complete
|
||||||
'\u{200F}', //{RIGHT-TO-LEFT MARK}
|
'\u{200F}', //{RIGHT-TO-LEFT MARK}
|
||||||
|
'\u{061C}', //{ARABIC LETTER MARK}
|
||||||
// We don't use
|
// We don't use
|
||||||
// "\u200E" # \n{LEFT-TO-RIGHT MARK}
|
// "\u200E" # \n{LEFT-TO-RIGHT MARK}
|
||||||
// as this is the default for latin files and can't be used
|
// as this is the default for latin files and can't be used
|
||||||
|
|
@ -62,12 +61,7 @@ impl Violation for BidirectionalUnicode {
|
||||||
|
|
||||||
/// PLE2502
|
/// PLE2502
|
||||||
pub(crate) fn bidirectional_unicode(line: &Line, context: &LintContext) {
|
pub(crate) fn bidirectional_unicode(line: &Line, context: &LintContext) {
|
||||||
if line.contains(BIDI_UNICODE)
|
if line.contains(BIDI_UNICODE) {
|
||||||
|| (is_bidi_forbid_arabic_letter_mark_enabled(context.settings())
|
|
||||||
&& line.contains(
|
|
||||||
'\u{061C}', //{ARABIC LETTER MARK}
|
|
||||||
))
|
|
||||||
{
|
|
||||||
context.report_diagnostic(BidirectionalUnicode, line.full_range());
|
context.report_diagnostic(BidirectionalUnicode, line.full_range());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,16 @@ PLE2502 Contains control characters that can permit obfuscated code
|
||||||
7 | # E2502
|
7 | # E2502
|
||||||
|
|
|
|
||||||
|
|
||||||
|
PLE2502 Contains control characters that can permit obfuscated code
|
||||||
|
--> bidirectional_unicode.py:8:1
|
||||||
|
|
|
||||||
|
7 | # E2502
|
||||||
|
8 | another = "x" * 50 # "x" is assigned
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
9 |
|
||||||
|
10 | # E2502
|
||||||
|
|
|
||||||
|
|
||||||
PLE2502 Contains control characters that can permit obfuscated code
|
PLE2502 Contains control characters that can permit obfuscated code
|
||||||
--> bidirectional_unicode.py:11:1
|
--> bidirectional_unicode.py:11:1
|
||||||
|
|
|
|
||||||
|
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ruff_linter/src/rules/pylint/mod.rs
|
|
||||||
---
|
|
||||||
PLE2502 Contains control characters that can permit obfuscated code
|
|
||||||
--> bidirectional_unicode.py:2:1
|
|
||||||
|
|
|
||||||
1 | # E2502
|
|
||||||
2 | print("שלום")
|
|
||||||
| ^^^^^^^^^^^^^
|
|
||||||
3 |
|
|
||||||
4 | # E2502
|
|
||||||
|
|
|
||||||
|
|
||||||
PLE2502 Contains control characters that can permit obfuscated code
|
|
||||||
--> bidirectional_unicode.py:5:1
|
|
||||||
|
|
|
||||||
4 | # E2502
|
|
||||||
5 | example = "x" * 100 # "x" is assigned
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
6 |
|
|
||||||
7 | # E2502
|
|
||||||
|
|
|
||||||
|
|
||||||
PLE2502 Contains control characters that can permit obfuscated code
|
|
||||||
--> bidirectional_unicode.py:8:1
|
|
||||||
|
|
|
||||||
7 | # E2502
|
|
||||||
8 | another = "x" * 50 # "x" is assigned
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
9 |
|
|
||||||
10 | # E2502
|
|
||||||
|
|
|
||||||
|
|
||||||
PLE2502 Contains control characters that can permit obfuscated code
|
|
||||||
--> bidirectional_unicode.py:11:1
|
|
||||||
|
|
|
||||||
10 | # E2502
|
|
||||||
11 | if access_level != "none": # Check if admin ' and access_level != 'user
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
12 | print("You are an admin.")
|
|
||||||
|
|
|
||||||
|
|
||||||
PLE2502 Contains control characters that can permit obfuscated code
|
|
||||||
--> bidirectional_unicode.py:17:1
|
|
||||||
|
|
|
||||||
15 | # E2502
|
|
||||||
16 | def subtract_funds(account: str, amount: int):
|
|
||||||
17 | """Subtract funds from bank account then """
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
18 | return
|
|
||||||
19 | bank[account] -= amount
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue