Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions crates/ruff_linter/src/rules/refurb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod tests {
use test_case::test_case;

use crate::registry::Rule;
use crate::settings::types::PreviewMode;
use crate::test::test_path;
use crate::{assert_messages, settings};

Expand Down Expand Up @@ -62,24 +61,6 @@ mod tests {
Ok(())
}

#[test_case(Rule::TypeNoneComparison, Path::new("FURB169.py"))]
Comment thread
ntBre marked this conversation as resolved.
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("refurb").join(path).as_path(),
&settings::LinterSettings {
preview: PreviewMode::Enabled,
..settings::LinterSettings::for_rule(rule_code)
},
)?;
assert_messages!(snapshot, diagnostics);
Ok(())
}

#[test]
fn write_whole_file_python_39() -> Result<()> {
let diagnostics = test_path(
Expand Down
11 changes: 0 additions & 11 deletions crates/ruff_linter/src/rules/refurb/rules/type_none_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ use crate::rules::refurb::helpers::replace_with_identity_check;
/// There is only ever one instance of `None`, so it is more efficient and
/// readable to use the `is` operator to check if an object is `None`.
///
/// Only name expressions (e.g., `type(foo) == type(None)`) are reported.
/// In [preview], the rule will also report other kinds of expressions.
///
/// ## Example
/// ```python
/// type(obj) is type(None)
Expand All @@ -34,8 +31,6 @@ use crate::rules::refurb::helpers::replace_with_identity_check;
/// - [Python documentation: `None`](https://docs.python.org/3/library/constants.html#None)
/// - [Python documentation: `type`](https://docs.python.org/3/library/functions.html#type)
/// - [Python documentation: Identity comparisons](https://docs.python.org/3/reference/expressions.html#is-not)
///
/// [preview]: https://docs.astral.sh/ruff/preview/
#[derive(ViolationMetadata)]
pub(crate) struct TypeNoneComparison {
replacement: IdentityCheck,
Expand Down Expand Up @@ -80,12 +75,6 @@ pub(crate) fn type_none_comparison(checker: &Checker, compare: &ast::ExprCompare
_ => return,
};

if checker.settings.preview.is_disabled()
&& !matches!(other_arg, Expr::Name(_) | Expr::NoneLiteral(_))
{
return;
}

let diagnostic = Diagnostic::new(TypeNoneComparison { replacement }, compare.range);

let negate = replacement == IdentityCheck::IsNot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,102 @@ FURB169.py:27:1: FURB169 [*] When checking against `None`, use `is not` instead
27 |+None is not None
28 28 |
29 29 | type(a.b) is type(None)
30 30 |
30 30 |

FURB169.py:29:1: FURB169 [*] When checking against `None`, use `is` instead of comparison with `type(None)`
|
27 | type(None) != type(None)
28 |
29 | type(a.b) is type(None)
| ^^^^^^^^^^^^^^^^^^^^^^^ FURB169
30 |
31 | type(
|
= help: Replace with `is None`

ℹ Safe fix
26 26 |
27 27 | type(None) != type(None)
28 28 |
29 |-type(a.b) is type(None)
29 |+a.b is None
30 30 |
31 31 | type(
32 32 | a(

FURB169.py:31:1: FURB169 [*] When checking against `None`, use `is not` instead of comparison with `type(None)`
|
29 | type(a.b) is type(None)
30 |
31 | / type(
32 | | a(
33 | | # Comment
34 | | )
35 | | ) != type(None)
| |_______________^ FURB169
36 |
37 | type(
|
= help: Replace with `is not None`

ℹ Unsafe fix
28 28 |
29 29 | type(a.b) is type(None)
30 30 |
31 |-type(
32 |- a(
33 |- # Comment
34 |- )
35 |-) != type(None)
31 |+a() is not None
36 32 |
37 33 | type(
38 34 | a := 1

FURB169.py:37:1: FURB169 [*] When checking against `None`, use `is` instead of comparison with `type(None)`
|
35 | ) != type(None)
36 |
37 | / type(
38 | | a := 1
39 | | ) == type(None)
| |_______________^ FURB169
40 |
41 | type(
|
= help: Replace with `is None`

ℹ Safe fix
34 34 | )
35 35 | ) != type(None)
36 36 |
37 |-type(
38 |- a := 1
39 |-) == type(None)
37 |+(a := 1) is None
40 38 |
41 39 | type(
42 40 | a for a in range(0)

FURB169.py:41:1: FURB169 [*] When checking against `None`, use `is not` instead of comparison with `type(None)`
|
39 | ) == type(None)
40 |
41 | / type(
42 | | a for a in range(0)
43 | | ) is not type(None)
| |___________________^ FURB169
|
= help: Replace with `is not None`

ℹ Safe fix
38 38 | a := 1
39 39 | ) == type(None)
40 40 |
41 |-type(
42 |- a for a in range(0)
43 |-) is not type(None)
41 |+(a for a in range(0)) is not None
44 42 |
45 43 |
46 44 | # Ok.
Loading
Loading