-
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.
Implement
flake8-async
plugin (#4432)
- Loading branch information
Showing
16 changed files
with
495 additions
and
3 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
23 changes: 23 additions & 0 deletions
23
crates/ruff/resources/test/fixtures/flake8_async/ASYNC100.py
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,23 @@ | ||
import urllib.request | ||
import requests | ||
import httpx | ||
|
||
|
||
async def foo(): | ||
urllib.request.urlopen("http://example.com/foo/bar").read() | ||
|
||
|
||
async def foo(): | ||
requests.get() | ||
|
||
|
||
async def foo(): | ||
httpx.get() | ||
|
||
|
||
async def foo(): | ||
requests.post() | ||
|
||
|
||
async def foo(): | ||
httpx.post() |
31 changes: 31 additions & 0 deletions
31
crates/ruff/resources/test/fixtures/flake8_async/ASYNC101.py
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,31 @@ | ||
import os | ||
import subprocess | ||
import time | ||
|
||
|
||
async def foo(): | ||
open("foo") | ||
|
||
|
||
async def foo(): | ||
time.sleep(1) | ||
|
||
|
||
async def foo(): | ||
subprocess.run("foo") | ||
|
||
|
||
async def foo(): | ||
subprocess.call("foo") | ||
|
||
|
||
async def foo(): | ||
subprocess.foo(0) | ||
|
||
|
||
async def foo(): | ||
os.wait4(10) | ||
|
||
|
||
async def foo(): | ||
os.wait(12) |
13 changes: 13 additions & 0 deletions
13
crates/ruff/resources/test/fixtures/flake8_async/ASYNC102.py
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,13 @@ | ||
import os | ||
|
||
|
||
async def foo(): | ||
os.popen() | ||
|
||
|
||
async def foo(): | ||
os.spawnl() | ||
|
||
|
||
async def foo(): | ||
os.fspath("foo") |
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,28 @@ | ||
//! Rules from [flake8-async](https://pypi.org/project/flake8-async/). | ||
pub(crate) mod rules; | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::path::Path; | ||
|
||
use anyhow::Result; | ||
use test_case::test_case; | ||
|
||
use crate::assert_messages; | ||
use crate::registry::Rule; | ||
use crate::settings::Settings; | ||
use crate::test::test_path; | ||
|
||
#[test_case(Rule::BlockingHttpCallInAsyncFunction, Path::new("ASYNC100.py"); "ASYNC100")] | ||
#[test_case(Rule::OpenSleepOrSubprocessInAsyncFunction, Path::new("ASYNC101.py"); "ASYNC101")] | ||
#[test_case(Rule::BlockingOsCallInAsyncFunction, Path::new("ASYNC102.py"); "ASYNC102")] | ||
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("flake8_async").join(path).as_path(), | ||
&Settings::for_rule(rule_code), | ||
)?; | ||
assert_messages!(snapshot, diagnostics); | ||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.