Skip to content

Commit 64fe7d3

Browse files
dylwil3ntBre
authored andcommitted
[flake8-errmsg] Stabilize extending raw-string-in-exception (EM101) to support byte strings (#20273)
Introduced in #18867. Removed gating, updated tests, updated docs.
1 parent beeeb8d commit 64fe7d3

File tree

4 files changed

+3
-18
lines changed

4 files changed

+3
-18
lines changed

crates/ruff_linter/src/preview.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@ pub(crate) const fn is_optional_as_none_in_union_enabled(settings: &LinterSettin
200200
settings.preview.is_enabled()
201201
}
202202

203-
// https://github.com/astral-sh/ruff/pull/18867
204-
pub(crate) const fn is_raise_exception_byte_string_enabled(settings: &LinterSettings) -> bool {
205-
settings.preview.is_enabled()
206-
}
207-
208203
// https://github.com/astral-sh/ruff/pull/18683
209204
pub(crate) const fn is_safe_super_call_with_parameters_fix_enabled(
210205
settings: &LinterSettings,

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mod tests {
99
use anyhow::Result;
1010

1111
use crate::registry::Rule;
12-
use crate::settings::types::PreviewMode;
1312
use crate::test::test_path;
1413
use crate::{assert_diagnostics, settings};
1514

@@ -47,15 +46,14 @@ mod tests {
4746
}
4847

4948
#[test]
50-
fn preview_string_exception() -> Result<()> {
49+
fn string_exception() -> Result<()> {
5150
let diagnostics = test_path(
5251
Path::new("flake8_errmsg/EM101_byte_string.py"),
5352
&settings::LinterSettings {
54-
preview: PreviewMode::Enabled,
5553
..settings::LinterSettings::for_rule(Rule::RawStringInException)
5654
},
5755
)?;
58-
assert_diagnostics!("preview", diagnostics);
56+
assert_diagnostics!(diagnostics);
5957
Ok(())
6058
}
6159
}

crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,12 @@ use ruff_text_size::Ranged;
77

88
use crate::Locator;
99
use crate::checkers::ast::Checker;
10-
use crate::preview::is_raise_exception_byte_string_enabled;
1110
use crate::registry::Rule;
1211
use crate::{Edit, Fix, FixAvailability, Violation};
1312

1413
/// ## What it does
1514
/// Checks for the use of string literals in exception constructors.
1615
///
17-
/// In [preview], this rule checks for byte string literals in
18-
/// exception constructors.
19-
///
2016
/// ## Why is this bad?
2117
/// Python includes the `raise` in the default traceback (and formatters
2218
/// like Rich and IPython do too).
@@ -51,8 +47,6 @@ use crate::{Edit, Fix, FixAvailability, Violation};
5147
/// raise RuntimeError(msg)
5248
/// RuntimeError: 'Some value' is incorrect
5349
/// ```
54-
///
55-
/// [preview]: https://docs.astral.sh/ruff/preview/
5650
#[derive(ViolationMetadata)]
5751
pub(crate) struct RawStringInException;
5852

@@ -218,9 +212,7 @@ pub(crate) fn string_in_exception(checker: &Checker, stmt: &Stmt, exc: &Expr) {
218212
// Check for byte string literals.
219213
Expr::BytesLiteral(ast::ExprBytesLiteral { value: bytes, .. }) => {
220214
if checker.settings().rules.enabled(Rule::RawStringInException) {
221-
if bytes.len() >= checker.settings().flake8_errmsg.max_string_length
222-
&& is_raise_exception_byte_string_enabled(checker.settings())
223-
{
215+
if bytes.len() >= checker.settings().flake8_errmsg.max_string_length {
224216
let mut diagnostic =
225217
checker.report_diagnostic(RawStringInException, first.range());
226218
if let Some(indentation) = whitespace::indentation(checker.source(), stmt) {
File renamed without changes.

0 commit comments

Comments
 (0)