-
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.
## Summary As an initial effort with replicating `refurb` rules (#1348 ), this PR adds support for [FURB113](https://github.com/dosisod/refurb/blob/master/refurb/checks/builtin/list_extend.py) and adds a new category of checks. ## Test Plan I included a new test + checked that all other tests pass.
- Loading branch information
1 parent
1439bb5
commit 26d53c5
Showing
13 changed files
with
1,003 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
from typing import List | ||
|
||
|
||
def func(): | ||
pass | ||
|
||
|
||
nums = [] | ||
nums2 = [] | ||
nums3: list[int] = func() | ||
nums4: List[int] | ||
|
||
|
||
class C: | ||
def append(self, x): | ||
pass | ||
|
||
|
||
# Errors. | ||
|
||
|
||
# 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]): | ||
# FURB113 | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
def yes_two(x: List[int]): | ||
# FURB113 | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
def yes_three(*, x: list[int]): | ||
# FURB113 | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
def yes_four(x: list[int], /): | ||
# FURB113 | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
def yes_five(x: list[int], y: list[int]): | ||
# FURB113 | ||
x.append(1) | ||
x.append(2) | ||
y.append(1) | ||
x.append(3) | ||
|
||
|
||
def yes_six(x: list): | ||
# FURB113 | ||
x.append(1) | ||
x.append(2) | ||
|
||
|
||
# Non-errors. | ||
|
||
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.