mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 14:52:01 +00:00
[syntax-errors] return
outside function (#17300)
Summary -- This PR reimplements [return-outside-function (F706)](https://docs.astral.sh/ruff/rules/return-outside-function/) as a semantic syntax error. These changes are very similar to those in https://github.com/astral-sh/ruff/pull/17298. Test Plan -- New linter tests, plus existing F706 tests.
This commit is contained in:
parent
4bfdf54d1a
commit
da32a83c9f
7 changed files with 82 additions and 29 deletions
|
@ -1061,14 +1061,15 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(Path::new("yield_scope.py"); "yield_scope")]
|
||||
fn test_yield_scope(path: &Path) -> Result<()> {
|
||||
#[test_case(Rule::YieldOutsideFunction, Path::new("yield_scope.py"))]
|
||||
#[test_case(Rule::ReturnOutsideFunction, Path::new("return_outside_function.py"))]
|
||||
fn test_syntax_errors(rule: Rule, path: &Path) -> Result<()> {
|
||||
let snapshot = path.to_string_lossy().to_string();
|
||||
let path = Path::new("resources/test/fixtures/syntax_errors").join(path);
|
||||
let messages = test_contents_syntax_errors(
|
||||
&SourceKind::Python(std::fs::read_to_string(&path)?),
|
||||
&path,
|
||||
&settings::LinterSettings::for_rule(Rule::YieldOutsideFunction),
|
||||
&settings::LinterSettings::for_rule(rule),
|
||||
);
|
||||
insta::with_settings!({filters => vec![(r"\\", "/")]}, {
|
||||
assert_messages!(snapshot, messages);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue