terrencepreilly / darglint

A python documentation linter which checks that the docstring description matches the definition.
MIT License
483 stars 41 forks source link

Lint error when decorator and noqa #137

Open KyleKing opened 4 years ago

KyleKing commented 4 years ago

It looks like when a decorator is added, flake8+darglint report the line number off by +1 so the line checked for noqa is shifted. Of the three methods below, the middle one reports linting errors

"""Test darglint with decorators."""

class C:
    """Example class with a decorated method."""

    def foo2(self, arg1, arg2):  # (Line 7)
        """Works as expected."""  # noqa: DAR101,DAR201
        return f'{arg1}-{arg2}'

    @staticmethod
    def foo_static(arg1, arg2):  # (Line 12)
        """Does not ignore the DAR101 and DAR201 errors."""  # noqa: DAR101,DAR201
        return f'{arg1}-{arg2}'

    @staticmethod
    def foo_static_alt(arg1, arg2):  # (Line 17)
        """Ignores the DAR101 and DAR201 errors."""  
        return f'{arg1}-{arg2}'  # noqa: DAR101,DAR201
>> flake8 dar_test.py
dar_test.py:14:1: DAR101 Missing parameter(s) in Docstring: - arg1
dar_test.py:14:1: DAR101 Missing parameter(s) in Docstring: - arg2
dar_test.py:14:1: DAR201 Missing "Returns" in Docstring: - return 
>> python --version
Python 3.7.4
>> python -m pip freeze
flake8==3.8.4
darglint==1.5.5

However, darglint appears to get the line number correct before the flake8-integration

dar_test.py:foo2:7: DAR101: - arg1
dar_test.py:foo2:7: DAR101: - arg2
dar_test.py:foo2:7: DAR201: - return
dar_test.py:foo_static:13: DAR101: - arg1
dar_test.py:foo_static:13: DAR101: - arg2
dar_test.py:foo_static:13: DAR201: - return
dar_test.py:foo_static_alt:18: DAR101: - arg1
dar_test.py:foo_static_alt:18: DAR101: - arg2
dar_test.py:foo_static_alt:18: DAR201: - return

Possibly related to #21

maltevesper commented 3 years ago

I am wondering if the root cause might be something like this: https://stackoverflow.com/a/47584560 ... I might have a look myself, but thats unlikely that I will get around to it.