-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[
flake8-boolean-trap
] Add setting for user defined allowed boolean …
…trap (#10531) ## Summary Add a setting `extend-allowed-calls` to allow users to define their own list of calls which allow boolean traps. Resolves #10485. Resolves #10356. ## Test Plan Extended text fixture and added setting test.
- Loading branch information
1 parent
9f56902
commit 3c48913
Showing
13 changed files
with
288 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
crates/ruff_linter/src/rules/flake8_boolean_trap/settings.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! Settings for the `flake8-boolean-trap` plugin. | ||
use std::fmt; | ||
|
||
use ruff_macros::CacheKey; | ||
|
||
use crate::display_settings; | ||
|
||
#[derive(Debug, CacheKey, Default)] | ||
pub struct Settings { | ||
pub extend_allowed_calls: Vec<String>, | ||
} | ||
|
||
impl fmt::Display for Settings { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
display_settings! { | ||
formatter = f, | ||
namespace = "linter.flake8_boolean_trap", | ||
fields = [ | ||
self.extend_allowed_calls | array, | ||
] | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 41 additions & 17 deletions
58
...boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,61 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_boolean_trap/mod.rs | ||
--- | ||
FBT.py:42:11: FBT003 Boolean positional value in function call | ||
FBT.py:41:11: FBT003 Boolean positional value in function call | ||
| | ||
42 | used("a", True) | ||
41 | used("a", True) | ||
| ^^^^ FBT003 | ||
43 | used(do=True) | ||
42 | used(do=True) | ||
| | ||
|
||
FBT.py:57:11: FBT003 Boolean positional value in function call | ||
FBT.py:56:11: FBT003 Boolean positional value in function call | ||
| | ||
55 | {}.pop(True, False) | ||
56 | dict.fromkeys(("world",), True) | ||
57 | {}.deploy(True, False) | ||
54 | {}.pop(True, False) | ||
55 | dict.fromkeys(("world",), True) | ||
56 | {}.deploy(True, False) | ||
| ^^^^ FBT003 | ||
58 | getattr(someobj, attrname, False) | ||
59 | mylist.index(True) | ||
57 | getattr(someobj, attrname, False) | ||
58 | mylist.index(True) | ||
| | ||
|
||
FBT.py:57:17: FBT003 Boolean positional value in function call | ||
FBT.py:56:17: FBT003 Boolean positional value in function call | ||
| | ||
55 | {}.pop(True, False) | ||
56 | dict.fromkeys(("world",), True) | ||
57 | {}.deploy(True, False) | ||
54 | {}.pop(True, False) | ||
55 | dict.fromkeys(("world",), True) | ||
56 | {}.deploy(True, False) | ||
| ^^^^^ FBT003 | ||
58 | getattr(someobj, attrname, False) | ||
59 | mylist.index(True) | ||
57 | getattr(someobj, attrname, False) | ||
58 | mylist.index(True) | ||
| | ||
|
||
FBT.py:121:10: FBT003 Boolean positional value in function call | ||
FBT.py:120:10: FBT003 Boolean positional value in function call | ||
| | ||
121 | settings(True) | ||
120 | settings(True) | ||
| ^^^^ FBT003 | ||
| | ||
|
||
FBT.py:144:20: FBT003 Boolean positional value in function call | ||
| | ||
142 | is_foo_or_bar=Case( | ||
143 | When(Q(is_foo=True) | Q(is_bar=True)), | ||
144 | then=Value(True), | ||
| ^^^^ FBT003 | ||
145 | ), | ||
146 | default=Value(False), | ||
| | ||
|
||
FBT.py:146:19: FBT003 Boolean positional value in function call | ||
| | ||
144 | then=Value(True), | ||
145 | ), | ||
146 | default=Value(False), | ||
| ^^^^^ FBT003 | ||
147 | ) | ||
| | ||
|
||
FBT.py:156:23: FBT003 Boolean positional value in function call | ||
| | ||
155 | class Settings(BaseSettings): | ||
156 | foo: bool = Field(True, exclude=True) | ||
| ^^^^ FBT003 | ||
| |
35 changes: 35 additions & 0 deletions
35
...ap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__extend_allowed_callable.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_boolean_trap/mod.rs | ||
--- | ||
FBT.py:41:11: FBT003 Boolean positional value in function call | ||
| | ||
41 | used("a", True) | ||
| ^^^^ FBT003 | ||
42 | used(do=True) | ||
| | ||
|
||
FBT.py:56:11: FBT003 Boolean positional value in function call | ||
| | ||
54 | {}.pop(True, False) | ||
55 | dict.fromkeys(("world",), True) | ||
56 | {}.deploy(True, False) | ||
| ^^^^ FBT003 | ||
57 | getattr(someobj, attrname, False) | ||
58 | mylist.index(True) | ||
| | ||
|
||
FBT.py:56:17: FBT003 Boolean positional value in function call | ||
| | ||
54 | {}.pop(True, False) | ||
55 | dict.fromkeys(("world",), True) | ||
56 | {}.deploy(True, False) | ||
| ^^^^^ FBT003 | ||
57 | getattr(someobj, attrname, False) | ||
58 | mylist.index(True) | ||
| | ||
|
||
FBT.py:120:10: FBT003 Boolean positional value in function call | ||
| | ||
120 | settings(True) | ||
| ^^^^ FBT003 | ||
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.