Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pydoclint] Add docstring-missing-yields amd docstring-extraneous-yields (DOC402, DOC403) #12538

Merged
merged 9 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# DOC402
def foo(num: int) -> str:
"""
Do something

Args:
num (int): A number
"""
yield 'test'


# OK
def foo(num: int) -> str:
"""
Do something

Args:
num (int): A number

Yields:
str: A string
"""
yield 'test'


class Bar:

# OK
def foo(self) -> str:
"""
Do something

Args:
num (int): A number

Yields:
str: A string
"""
yield 'test'


# DOC402
def bar(self) -> str:
"""
Do something

Args:
num (int): A number
"""
yield 'test'


# OK
def test():
"""Do something."""
# DOC402
def nested():
"""Do something nested."""
yield 5

print("I never yield")


# DOC402
def test():
"""Do something."""
yield from range(10)

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# DOC402
def foo(num: int) -> str:
"""
Do something

Parameters
----------
num : int
A number
"""
yield 'test'


# OK
def foo(num: int) -> str:
"""
Do something

Parameters
----------
num : int
A number

Yields
-------
str
A string
"""
yield 'test'


class Bar:

# OK
def foo(self) -> str:
"""
Do something

Parameters
----------
num : int
A number

Yields
-------
str
A string
"""
yield 'test'


# DOC402
def bar(self) -> str:
"""
Do something

Parameters
----------
num : int
A number
"""
yield 'test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# OK
def foo(num: int) -> str:
"""
Do something

Args:
num (int): A number
"""
print('test')


# DOC403
def foo(num: int) -> str:
"""
Do something

Args:
num (int): A number

Yields:
str: A string
"""
print('test')


class Bar:

# DOC403
def foo(self) -> str:
"""
Do something

Args:
num (int): A number

Yields:
str: A string
"""
print('test')


# OK
def bar(self) -> str:
"""
Do something

Args:
num (int): A number
"""
print('test')
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# OK
def foo(num: int) -> str:
"""
Do something

Parameters
----------
num : int
A number
"""
print('test')


# DOC403
def foo(num: int) -> str:
"""
Do something

Parameters
----------
num : int
A number

Yields
-------
str
A string
"""
print('test')


class Bar:

# DOC403
def foo(self) -> str:
"""
Do something

Parameters
----------
num : int
A number

Yields
-------
str
A string
"""
print('test')


# OK
def bar(self) -> str:
"""
Do something

Parameters
----------
num : int
A number
"""
print('test')
2 changes: 2 additions & 0 deletions crates/ruff_linter/src/checkers/ast/analyze/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub(crate) fn definitions(checker: &mut Checker) {
let enforce_pydoclint = checker.any_enabled(&[
Rule::DocstringMissingReturns,
Rule::DocstringExtraneousReturns,
Rule::DocstringMissingYields,
Rule::DocstringExtraneousYields,
Rule::DocstringMissingException,
Rule::DocstringExtraneousException,
]);
Expand Down
2 changes: 2 additions & 0 deletions crates/ruff_linter/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
// pydoclint
(Pydoclint, "201") => (RuleGroup::Preview, rules::pydoclint::rules::DocstringMissingReturns),
(Pydoclint, "202") => (RuleGroup::Preview, rules::pydoclint::rules::DocstringExtraneousReturns),
(Pydoclint, "402") => (RuleGroup::Preview, rules::pydoclint::rules::DocstringMissingYields),
(Pydoclint, "403") => (RuleGroup::Preview, rules::pydoclint::rules::DocstringExtraneousYields),
(Pydoclint, "501") => (RuleGroup::Preview, rules::pydoclint::rules::DocstringMissingException),
(Pydoclint, "502") => (RuleGroup::Preview, rules::pydoclint::rules::DocstringExtraneousException),

Expand Down
4 changes: 4 additions & 0 deletions crates/ruff_linter/src/rules/pydoclint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ mod tests {

#[test_case(Rule::DocstringMissingReturns, Path::new("DOC201_google.py"))]
#[test_case(Rule::DocstringExtraneousReturns, Path::new("DOC202_google.py"))]
#[test_case(Rule::DocstringMissingYields, Path::new("DOC402_google.py"))]
#[test_case(Rule::DocstringExtraneousYields, Path::new("DOC403_google.py"))]
#[test_case(Rule::DocstringMissingException, Path::new("DOC501_google.py"))]
#[test_case(Rule::DocstringExtraneousException, Path::new("DOC502_google.py"))]
fn rules_google_style(rule_code: Rule, path: &Path) -> Result<()> {
Expand All @@ -45,6 +47,8 @@ mod tests {

#[test_case(Rule::DocstringMissingReturns, Path::new("DOC201_numpy.py"))]
#[test_case(Rule::DocstringExtraneousReturns, Path::new("DOC202_numpy.py"))]
#[test_case(Rule::DocstringMissingYields, Path::new("DOC402_numpy.py"))]
#[test_case(Rule::DocstringExtraneousYields, Path::new("DOC403_numpy.py"))]
#[test_case(Rule::DocstringMissingException, Path::new("DOC501_numpy.py"))]
#[test_case(Rule::DocstringExtraneousException, Path::new("DOC502_numpy.py"))]
fn rules_numpy_style(rule_code: Rule, path: &Path) -> Result<()> {
Expand Down
Loading
Loading