diff --git a/crates/ruff_linter/resources/test/fixtures/darglint/DAR401_google.py b/crates/ruff_linter/resources/test/fixtures/darglint/DAR401_google.py index cf8bd5698fe60..68e7fb7c07eff 100644 --- a/crates/ruff_linter/resources/test/fixtures/darglint/DAR401_google.py +++ b/crates/ruff_linter/resources/test/fixtures/darglint/DAR401_google.py @@ -114,6 +114,20 @@ def calculate_speed(distance: float, time: float) -> float: raise AnotherError +# DAR401 +def calculate_speed(distance: float, time: float) -> float: + """Calculate speed as distance divided by time. + + Args: + distance: Distance traveled. + time: Time spent traveling. + + Returns: + Speed as distance divided by time. + """ + raise AnotherError() + + # DAR401, but can't resolve the error def calculate_speed(distance: float, time: float) -> float: """Calculate speed as distance divided by time. diff --git a/crates/ruff_linter/src/rules/darglint/rules/check_docstring.rs b/crates/ruff_linter/src/rules/darglint/rules/check_docstring.rs index 8376bf35c5a0c..3419e0265a565 100644 --- a/crates/ruff_linter/src/rules/darglint/rules/check_docstring.rs +++ b/crates/ruff_linter/src/rules/darglint/rules/check_docstring.rs @@ -221,16 +221,35 @@ impl<'a> BodyVisitor<'a> { impl Visitor<'_> for BodyVisitor<'_> { fn visit_stmt(&mut self, stmt: &Stmt) { if let Stmt::Raise(ast::StmtRaise { exc: Some(exc), .. }) = stmt { - if let Expr::Name(ast::ExprName { id, range, .. }) = exc.as_ref() { - // SemanticModel will resolve qualified_name for local Class definitions, - // or imported definitions, but not variables which we want to ignore. - if self.semantic.resolve_qualified_name(exc.as_ref()).is_some() { - self.raised_exceptions.push(Entry { - id: id.to_string(), - range: *range, - }); + match exc.as_ref() { + Expr::Name(ast::ExprName { id, range, .. }) => { + // SemanticModel will resolve qualified_name for local Class definitions, + // or imported definitions, but not variables which we want to ignore. + if self.semantic.resolve_qualified_name(exc.as_ref()).is_some() { + self.raised_exceptions.push(Entry { + id: id.to_string(), + range: *range, + }); + } } - } + Expr::Call(ast::ExprCall { func, range, .. }) => { + if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() { + // SemanticModel will resolve qualified_name for local Class definitions, + // or imported definitions, but not variables which we want to ignore. + if self + .semantic + .resolve_qualified_name(func.as_ref()) + .is_some() + { + self.raised_exceptions.push(Entry { + id: id.to_string(), + range: *range, + }); + } + } + } + _ => {} + }; } visitor::walk_stmt(self, stmt); } diff --git a/crates/ruff_linter/src/rules/darglint/snapshots/ruff_linter__rules__darglint__tests__docstring-missing-exception_DAR401_google.py.snap b/crates/ruff_linter/src/rules/darglint/snapshots/ruff_linter__rules__darglint__tests__docstring-missing-exception_DAR401_google.py.snap index fd3a6be24519d..0b033680b0903 100644 --- a/crates/ruff_linter/src/rules/darglint/snapshots/ruff_linter__rules__darglint__tests__docstring-missing-exception_DAR401_google.py.snap +++ b/crates/ruff_linter/src/rules/darglint/snapshots/ruff_linter__rules__darglint__tests__docstring-missing-exception_DAR401_google.py.snap @@ -34,3 +34,11 @@ DAR401_google.py:114:11: DAR401 Raised exception `AnotherError` missing from doc 114 | raise AnotherError | ^^^^^^^^^^^^ DAR401 | + +DAR401_google.py:128:11: DAR401 Raised exception `AnotherError` missing from docstring + | +126 | Speed as distance divided by time. +127 | """ +128 | raise AnotherError() + | ^^^^^^^^^^^^^^ DAR401 + |