-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refurb] Implement
repeated-append
rule (FURB113
)
- Loading branch information
1 parent
7e9023b
commit 9b377fd
Showing
10 changed files
with
868 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
from typing import List | ||
|
||
|
||
def foo(): | ||
pass | ||
|
||
nums = [] | ||
nums2 = [] | ||
nums3: list[int] = foo() | ||
nums4: List[int] | ||
|
||
class C: | ||
def append(self, x): | ||
pass | ||
|
||
|
||
# these will match | ||
|
||
|
||
# FURB113 | ||
nums.append(1) | ||
nums.append(2) | ||
pass | ||
|
||
|
||
# FURB113 | ||
nums3.append(1) | ||
nums3.append(2) | ||
pass | ||
|
||
|
||
# FURB113 | ||
nums4.append(1) | ||
nums4.append(2) | ||
pass | ||
|
||
|
||
# FURB113 | ||
nums.append(1) | ||
nums2.append(1) | ||
nums.append(2) | ||
nums.append(3) | ||
pass | ||
|
||
|
||
# FURB113 | ||
nums.append(1) | ||
nums2.append(1) | ||
nums.append(2) | ||
# FURB113 | ||
nums3.append(1) | ||
nums.append(3) | ||
# FURB113 | ||
nums4.append(1) | ||
nums4.append(2) | ||
nums3.append(2) | ||
pass | ||
|
||
# FURB113 | ||
nums.append(1) | ||
nums.append(2) | ||
nums.append(3) | ||
|
||
|
||
if True: | ||
# FURB113 | ||
nums.append(1) | ||
nums.append(2) | ||
|
||
|
||
if True: | ||
# FURB113 | ||
nums.append(1) | ||
nums.append(2) | ||
pass | ||
|
||
|
||
if True: | ||
# FURB113 | ||
nums.append(1) | ||
nums2.append(1) | ||
nums.append(2) | ||
nums.append(3) | ||
|
||
|
||
def yes_one(x: list[int]): | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
def yes_two(x: List[int]): | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
def yes_three(*, x: list[int]): | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
def yes_four(x: list[int], /): | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
# these will not | ||
|
||
nums.append(1) | ||
pass | ||
nums.append(2) | ||
|
||
|
||
if True: | ||
nums.append(1) | ||
pass | ||
nums.append(2) | ||
|
||
|
||
nums.append(1) | ||
pass | ||
|
||
|
||
nums.append(1) | ||
nums2.append(2) | ||
|
||
|
||
nums.copy() | ||
nums.copy() | ||
|
||
|
||
c = C() | ||
c.append(1) | ||
c.append(2) | ||
|
||
|
||
def not_one(x): | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
def not_two(x: C): | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
# redefining a list variable with a new type shouldn't confuse ruff | ||
nums2 = C() | ||
nums2.append(1) | ||
nums2.append(2) |
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
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 @@ | ||
//! Rules from [refurb](https://pypi.org/project/refurb/)/ | ||
pub(crate) mod rules; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
use test_case::test_case; | ||
|
||
use crate::registry::Rule; | ||
use crate::test::test_path; | ||
use crate::{assert_messages, settings}; | ||
|
||
#[test_case(Rule::RepeatedAppend, Path::new("FURB113.py"))] | ||
fn rules(rule_code: Rule, path: &Path) -> Result<()> { | ||
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy()); | ||
let diagnostics = test_path( | ||
Path::new("refurb").join(path).as_path(), | ||
&settings::Settings::for_rule(rule_code), | ||
)?; | ||
assert_messages!(snapshot, diagnostics); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub(crate) use repeated_append::*; | ||
|
||
mod repeated_append; |
Oops, something went wrong.