Skip to content

Commit

Permalink
Avoid flagging logging-too-few-args with no arguments (#3220)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 25, 2023
1 parent bbc55cd commit 2485902
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

logging.warning("Hello %s", "World!")

# do not handle calls without any args
logging.info("100% dynamic")

import warning

warning.warning("Hello %s %s", "World!")
28 changes: 14 additions & 14 deletions crates/ruff/src/rules/pylint/rules/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ pub fn logging_call(checker: &mut Checker, func: &Expr, args: &[Expr], keywords:

let message_args = call_args.args.len() - 1;

if checker.settings.rules.enabled(&Rule::LoggingTooManyArgs)
&& summary.num_positional < message_args
{
checker.diagnostics.push(Diagnostic::new(
LoggingTooManyArgs,
Range::from_located(func),
));
if checker.settings.rules.enabled(&Rule::LoggingTooManyArgs) {
if summary.num_positional < message_args {
checker.diagnostics.push(Diagnostic::new(
LoggingTooManyArgs,
Range::from_located(func),
));
}
}

if checker.settings.rules.enabled(&Rule::LoggingTooFewArgs)
&& summary.num_positional > message_args
{
checker.diagnostics.push(Diagnostic::new(
LoggingTooFewArgs,
Range::from_located(func),
));
if checker.settings.rules.enabled(&Rule::LoggingTooFewArgs) {
if message_args > 0 && summary.num_positional > message_args {
checker.diagnostics.push(Diagnostic::new(
LoggingTooFewArgs,
Range::from_located(func),
));
}
}
}
}
Expand Down

0 comments on commit 2485902

Please sign in to comment.