Skip to content

Commit

Permalink
Add DOC604 & 605 test cases; improve DOC605 err msg (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 authored Jun 27, 2024
1 parent 4d0293a commit 98f7a5c
Show file tree
Hide file tree
Showing 8 changed files with 303 additions and 161 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## [0.5.3] - 2024-06-26

- Changed

- Added DOC604 & 605 test cases
- Improved DOC605 error message

- Full diff
- https://github.com/jsh9/pydoclint/compare/0.5.2...0.5.3

## [0.5.2] - 2024-06-26

- Changed
Expand Down
21 changes: 19 additions & 2 deletions pydoclint/utils/violation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,16 @@ def __init__(

self.line = line
self.code = code
self.msg = msgPrefix + ' ' + VIOLATION_CODES[code] + ' ' + msgPostfix
self.violationMsg = VIOLATION_CODES[code]
self.msgPrefix = msgPrefix
self.msgPostfix = msgPostfix
self.msg = ''.join([
msgPrefix,
' ',
self.violationMsg,
' ',
msgPostfix,
]).strip()

@property
def fullErrorCode(self) -> str:
Expand Down Expand Up @@ -107,5 +116,13 @@ def getInfoForFlake8(self) -> Tuple[int, int, str]:
def appendMoreMsg(self, moreMsg: str) -> 'Violation':
"""Append more error message, and return a new Violation object"""
new = deepcopy(self)
new.msg += moreMsg
new.msg = ''.join([
new.msgPrefix,
' ',
new.violationMsg,
' ',
moreMsg,
' ',
new.msgPostfix,
]).strip() # noqa: PAR104
return new
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pydoclint
version = 0.5.2
version = 0.5.3
description = A Python docstring linter that checks arguments, returns, yields, and raises sections
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
28 changes: 28 additions & 0 deletions tests/data/google/class_attributes/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,31 @@ class MyClass7:

hello: int = 2
world: str = 'world'


class MyClass8:
"""
My class 8.
Attributes:
arg1 (str): Arg 1
arg2 (int): Arg 2
"""

arg1: str
arg2: bool


class MyClass9:
"""
My class 9.
Attributes:
arg1 (str): Arg 1
arg2 (bool): Arg 2
arg3 (int): Arg 3
"""

arg1: str
arg3: int
arg2: bool
35 changes: 35 additions & 0 deletions tests/data/numpy/class_attributes/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,38 @@ class MyClass7:

hello: int = 2
world: str = 'world'


class MyClass8:
"""
My class 8.
Attributes
----------
arg1 : str
Arg 1
arg2 : int
Arg 2
"""

arg1: str
arg2: bool


class MyClass9:
"""
My class 9.
Attributes
----------
arg1 : str
Arg 1
arg2 : bool
Arg 2
arg3 : int
Arg 3
"""

arg1: str
arg3: int
arg2: bool
44 changes: 44 additions & 0 deletions tests/data/sphinx/class_attributes/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,47 @@ class MyClass7:

hello: int = 2
world: str = 'world'


class MyClass8:
"""
My class 8.
.. attribute :: arg1
:type: str
Arg 1
.. attribute :: arg2
:type: int
Arg 2
"""

arg1: str
arg2: bool


class MyClass9:
"""
My class 9.
.. attribute :: arg1
:type: str
Arg 1
.. attribute :: arg2
:type: bool
Arg 2
.. attribute :: arg3
:type: int
Arg 3
"""

arg1: str
arg3: int
arg2: bool
2 changes: 1 addition & 1 deletion tests/test_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def bad_docstring_func(arg1: str, arg2: list[int]) -> bool:
'''

expectedNewViolations = [
'DOC101: Function `bad_docstring_func`: Docstring contains fewer arguments than in function signature. ',
'DOC101: Function `bad_docstring_func`: Docstring contains fewer arguments than in function signature.',
'DOC103: Function `bad_docstring_func`: Docstring arguments are different from function arguments. '
'(Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). '
'Arguments in the function signature but not in the docstring: [arg1: str, arg2: list[int]].',
Expand Down
Loading

0 comments on commit 98f7a5c

Please sign in to comment.