Skip to content

Commit

Permalink
Make test fixture more compact, clippy, regen snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
qdegraaf committed Sep 15, 2023
1 parent b8f5090 commit 8f03a93
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
11 changes: 2 additions & 9 deletions crates/ruff/resources/test/fixtures/flake8_logging/LOG007.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import logging
from logging import exception


logging.exception("foo") # OK


logging.exception("foo", exc_info=False) # LOG007


logging.exception("foo", exc_info=[]) # LOG007

from logging import exception

exception("foo", exc_info=False) # LOG007


logging.exception("foo", exc_info=True) # OK
exception("foo", exc_info=True) # OK
5 changes: 1 addition & 4 deletions crates/ruff/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,12 +922,9 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {

// flake8-logging
(Flake8Logging, "001") => (RuleGroup::Preview, rules::flake8_logging::rules::DirectLoggerInstantiation),
(Flake8Logging, "007") => (RuleGroup::Preview, rules::flake8_logging::rules::ExcInfoFalseInException),
(Flake8Logging, "009") => (RuleGroup::Preview, rules::flake8_logging::rules::UndocumentedWarn),

// flake8-logging
(Flake8Logging, "007") => (RuleGroup::Nursery, rules::flake8_logging::rules::ExcInfoFalseInException),
(Flake8Logging, "009") => (RuleGroup::Nursery, rules::flake8_logging::rules::UndocumentedWarn),

_ => return None,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::checkers::ast::Checker;
/// `exc_info=False` is the same as using `error()`, which is clearer and doesn’t need the
/// `exc_info`argument. This rule detects `exception()` calls with an exc_info argument that is
/// falsy.
///
///
/// ## Example
/// ```python
/// logging.exception("foo", exc_info=False)
Expand All @@ -42,10 +42,15 @@ pub(crate) fn exc_info_false_in_exception(checker: &mut Checker, call: &ExprCall
.resolve_call_path(call.func.as_ref())
.is_some_and(|call_path| matches!(call_path.as_slice(), ["logging", "exception"]))
{
if let Some(_) = call.arguments.find_keyword("exc_info").filter(|keyword| {
Truthiness::from_expr(&keyword.value, |id| checker.semantic().is_builtin(id))
.is_falsey()
}) {
if call
.arguments
.find_keyword("exc_info")
.filter(|keyword| {
Truthiness::from_expr(&keyword.value, |id| checker.semantic().is_builtin(id))
.is_falsey()
})
.is_some()
{
checker
.diagnostics
.push(Diagnostic::new(ExcInfoFalseInException, call.range()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
---
source: crates/ruff/src/rules/flake8_logging/mod.rs
---
LOG007.py:8:1: LOG007 Use of `logging.exception` with falsy `exc_info`
LOG007.py:4:1: LOG007 Use of `logging.exception` with falsy `exc_info`
|
8 | logging.exception("foo", exc_info=False) # LOG007
3 | logging.exception("foo") # OK
4 | logging.exception("foo", exc_info=False) # LOG007
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LOG007
5 | logging.exception("foo", exc_info=[]) # LOG007
|

LOG007.py:11:1: LOG007 Use of `logging.exception` with falsy `exc_info`
|
11 | logging.exception("foo", exc_info=[]) # LOG007
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LOG007
|
LOG007.py:5:1: LOG007 Use of `logging.exception` with falsy `exc_info`
|
3 | logging.exception("foo") # OK
4 | logging.exception("foo", exc_info=False) # LOG007
5 | logging.exception("foo", exc_info=[]) # LOG007
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LOG007
6 |
7 | from logging import exception
|

LOG007.py:14:1: LOG007 Use of `logging.exception` with falsy `exc_info`
LOG007.py:9:1: LOG007 Use of `logging.exception` with falsy `exc_info`
|
14 | exception("foo", exc_info=False) # LOG007
7 | from logging import exception
8 |
9 | exception("foo", exc_info=False) # LOG007
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LOG007
10 | exception("foo", exc_info=True) # OK
|


0 comments on commit 8f03a93

Please sign in to comment.