Skip to content

Commit

Permalink
revert the addition of config option
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerBin committed Aug 17, 2024
1 parent ad49c0d commit d52206a
Show file tree
Hide file tree
Showing 9 changed files with 3 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ linter.pylint.max_public_methods = 20
linter.pylint.max_locals = 15
linter.pyupgrade.keep_runtime_typing = false
linter.ruff.parenthesize_tuple_in_subscript = false
linter.ruff.allow_fastapi_routes_unused_async = false

# Formatter Settings
formatter.exclude = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@


@app.post("/count")
async def fastapi_route():
async def fastapi_route(): # Ok: FastApi routes can be async without actually using await
return 1
35 changes: 1 addition & 34 deletions crates/ruff_linter/src/rules/ruff/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ mod tests {
#[test_case(Rule::MissingFStringSyntax, Path::new("RUF027_2.py"))]
#[test_case(Rule::InvalidFormatterSuppressionComment, Path::new("RUF028.py"))]
#[test_case(Rule::UnusedAsync, Path::new("RUF029.py"))]
#[test_case(Rule::UnusedAsync, Path::new("RUF029_fastapi.py"))]
#[test_case(Rule::AssertWithPrintMessage, Path::new("RUF030.py"))]
#[test_case(Rule::IncorrectlyParenthesizedTupleInSubscript, Path::new("RUF031.py"))]
#[test_case(Rule::RedirectedNOQA, Path::new("RUF101.py"))]
Expand All @@ -68,46 +69,13 @@ mod tests {
Ok(())
}

#[test]
fn dont_allow_fastapi_routes_unused_async() -> Result<()> {
let diagnostics = test_path(
Path::new("ruff/RUF029_fastapi.py"),
&LinterSettings {
ruff: super::settings::Settings {
parenthesize_tuple_in_subscript: false,
allow_fastapi_routes_unused_async: false,
},
..LinterSettings::for_rule(Rule::UnusedAsync)
},
)?;
assert_messages!(diagnostics);
Ok(())
}

#[test]
fn allow_fastapi_routes_unused_async() -> Result<()> {
let diagnostics = test_path(
Path::new("ruff/RUF029_fastapi.py"),
&LinterSettings {
ruff: super::settings::Settings {
parenthesize_tuple_in_subscript: false,
allow_fastapi_routes_unused_async: true,
},
..LinterSettings::for_rule(Rule::UnusedAsync)
},
)?;
assert_messages!(diagnostics);
Ok(())
}

#[test]
fn prefer_parentheses_getitem_tuple() -> Result<()> {
let diagnostics = test_path(
Path::new("ruff/RUF031_prefer_parens.py"),
&LinterSettings {
ruff: super::settings::Settings {
parenthesize_tuple_in_subscript: true,
allow_fastapi_routes_unused_async: false,
},
..LinterSettings::for_rule(Rule::IncorrectlyParenthesizedTupleInSubscript)
},
Expand All @@ -123,7 +91,6 @@ mod tests {
&LinterSettings {
ruff: super::settings::Settings {
parenthesize_tuple_in_subscript: false,
allow_fastapi_routes_unused_async: false,
},
target_version: PythonVersion::Py310,
..LinterSettings::for_rule(Rule::IncorrectlyParenthesizedTupleInSubscript)
Expand Down
6 changes: 1 addition & 5 deletions crates/ruff_linter/src/rules/ruff/rules/unused_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ use ruff_python_semantic::Modules;
/// def foo():
/// bar()
/// ```
///
/// ## Options
/// - `lint.ruff.allow-fastapi-routes-unused-async`
#[violation]
pub struct UnusedAsync {
name: String,
Expand Down Expand Up @@ -177,8 +174,7 @@ pub(crate) fn unused_async(
return;
}

if checker.settings.ruff.allow_fastapi_routes_unused_async
&& checker.semantic().seen_module(Modules::FASTAPI)
if checker.semantic().seen_module(Modules::FASTAPI)
&& is_fastapi_route(function_def, checker.semantic())
{
return;
Expand Down
2 changes: 0 additions & 2 deletions crates/ruff_linter/src/rules/ruff/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::fmt;
#[derive(Debug, Clone, CacheKey, Default)]
pub struct Settings {
pub parenthesize_tuple_in_subscript: bool,
pub allow_fastapi_routes_unused_async: bool,
}

impl fmt::Display for Settings {
Expand All @@ -17,7 +16,6 @@ impl fmt::Display for Settings {
namespace = "linter.ruff",
fields = [
self.parenthesize_tuple_in_subscript,
self.allow_fastapi_routes_unused_async
]
}
Ok(())
Expand Down

This file was deleted.

15 changes: 0 additions & 15 deletions crates/ruff_workspace/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2986,18 +2986,6 @@ pub struct RuffOptions {
"#
)]
pub parenthesize_tuple_in_subscript: Option<bool>,

/// Whether to allow fastapi routes to be defined as async function, although they don't use
/// any asynchronous code (see `RUF029` and [FastAPI docs](https://fastapi.tiangolo.com/async/)).
#[option(
default = r#"false"#,
value_type = "bool",
example = r#"
# Make it a ok to have async functions in FastAPI routes that don't use await
parenthesize-tuple-in-subscript = true
"#
)]
pub allow_fastapi_routes_unused_async: Option<bool>,
}

impl RuffOptions {
Expand All @@ -3006,9 +2994,6 @@ impl RuffOptions {
parenthesize_tuple_in_subscript: self
.parenthesize_tuple_in_subscript
.unwrap_or_default(),
allow_fastapi_routes_unused_async: self
.allow_fastapi_routes_unused_async
.unwrap_or_default(),
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions ruff.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d52206a

Please sign in to comment.