Skip to content

Commit 50e669f

Browse files
committed
Handle duplicates in docstrings.
1 parent 483c0b7 commit 50e669f

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

flake8_params/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
# stdlib
3030
import ast
31-
from typing import Iterator, List, Optional, Union
31+
from typing import Counter, Iterator, List, Optional, Union
3232

3333
# 3rd party
3434
import flake8_helper
@@ -123,7 +123,12 @@ def check_params(
123123
signature_set = set(signature_args)
124124
docstring_set = set(docstring_args)
125125
if signature_set == docstring_set:
126-
# Wrong order
126+
# Wrong order or duplicated
127+
docstring_counts = {k: v for k, v in Counter(docstring_set).items() if v > 1}
128+
129+
if docstring_counts:
130+
return PRM003 + ": " + ' '.join(sorted(docstring_counts.keys()))
131+
127132
return PRM001
128133
elif signature_set - docstring_set:
129134
# Extras in signature

tests/example_code.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,3 +399,12 @@ def another_command(foo):
399399
"""
400400
Command line entry point.
401401
"""
402+
403+
404+
def duplicated_params(tree: list) -> None:
405+
"""
406+
Does something.
407+
408+
:param tree:
409+
:param tree:
410+
"""

tests/test_flake8_params_/test_plugin.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
311:0: PRM002 Missing parameters in docstring: **baz
2020
356:1: PRM002 Missing parameters in docstring: a b c
2121
372:1: PRM002 Missing parameters in docstring: swallow
22+
404:0: PRM001 Docstring parameters in wrong order.

0 commit comments

Comments
 (0)