Skip to content

Commit

Permalink
Rename to assert-with-print-message
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Jun 23, 2024
1 parent dbcd1cf commit 416a033
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,8 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
if checker.enabled(Rule::InvalidMockAccess) {
pygrep_hooks::rules::non_existent_mock_method(checker, test);
}
if checker.enabled(Rule::AssertWithPrintExpression) {
ruff::rules::assert_with_print_expression(checker, assert_stmt);
if checker.enabled(Rule::AssertWithPrintMessage) {
ruff::rules::assert_with_print_message(checker, assert_stmt);
}
}
Stmt::With(with_stmt @ ast::StmtWith { items, body, .. }) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
(Ruff, "027") => (RuleGroup::Preview, rules::ruff::rules::MissingFStringSyntax),
(Ruff, "028") => (RuleGroup::Preview, rules::ruff::rules::InvalidFormatterSuppressionComment),
(Ruff, "029") => (RuleGroup::Preview, rules::ruff::rules::UnusedAsync),
(Ruff, "030") => (RuleGroup::Preview, rules::ruff::rules::AssertWithPrintExpression),
(Ruff, "030") => (RuleGroup::Preview, rules::ruff::rules::AssertWithPrintMessage),
(Ruff, "100") => (RuleGroup::Stable, rules::ruff::rules::UnusedNOQA),
(Ruff, "101") => (RuleGroup::Preview, rules::ruff::rules::RedirectedNOQA),
(Ruff, "200") => (RuleGroup::Stable, rules::ruff::rules::InvalidPyprojectToml),
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_linter/src/rules/ruff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ mod tests {
#[test_case(Rule::MissingFStringSyntax, Path::new("RUF027_2.py"))]
#[test_case(Rule::InvalidFormatterSuppressionComment, Path::new("RUF028.py"))]
#[test_case(Rule::UnusedAsync, Path::new("RUF029.py"))]
#[test_case(Rule::AssertWithPrintExpression, Path::new("RUF030.py"))]
#[test_case(Rule::AssertWithPrintMessage, Path::new("RUF030.py"))]
#[test_case(Rule::RedirectedNOQA, Path::new("RUF101.py"))]
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ use crate::checkers::ast::Checker;
/// ## References
/// - [Python documentation: `assert`](https://docs.python.org/3/reference/simple_stmts.html#the-assert-statement)
#[violation]
pub struct AssertWithPrintExpression;
pub struct AssertWithPrintMessage;

impl AlwaysFixableViolation for AssertWithPrintExpression {
impl AlwaysFixableViolation for AssertWithPrintMessage {
#[derive_message_formats]
fn message(&self) -> String {
format!("`print()` expression in `assert` statement is likely unintentional")
Expand All @@ -53,14 +53,14 @@ impl AlwaysFixableViolation for AssertWithPrintExpression {
///
/// Checks if the `msg` argument to an `assert` statement is a `print` call, and if so,
/// replace the message with the arguments to the `print` call.
pub(crate) fn assert_with_print_expression(checker: &mut Checker, stmt: &ast::StmtAssert) {
pub(crate) fn assert_with_print_message(checker: &mut Checker, stmt: &ast::StmtAssert) {
if let Some(Expr::Call(call)) = stmt.msg.as_deref() {
// We have to check that the print call is a call to the built-in `print` function
let semantic = checker.semantic();

if semantic.match_builtin_expr(&call.func, "print") {
// This is the confirmed rule condition
let mut diagnostic = Diagnostic::new(AssertWithPrintExpression, call.range());
let mut diagnostic = Diagnostic::new(AssertWithPrintMessage, call.range());
diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement(
checker.generator().stmt(&Stmt::Assert(ast::StmtAssert {
test: stmt.test.clone(),
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/ruff/rules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub(crate) use ambiguous_unicode_character::*;
pub(crate) use assert_with_print_expression::*;
pub(crate) use assert_with_print_message::*;
pub(crate) use assignment_in_assert::*;
pub(crate) use asyncio_dangling_task::*;
pub(crate) use collection_literal_concatenation::*;
Expand Down Expand Up @@ -31,7 +31,7 @@ pub(crate) use unused_async::*;
pub(crate) use unused_noqa::*;

mod ambiguous_unicode_character;
mod assert_with_print_expression;
mod assert_with_print_message;
mod assignment_in_assert;
mod asyncio_dangling_task;
mod collection_literal_concatenation;
Expand Down

0 comments on commit 416a033

Please sign in to comment.