diff options
author | Bruno Daniel <bruno.daniel@blue-yonder.com> | 2015-05-10 13:10:27 +0200 |
---|---|---|
committer | Bruno Daniel <bruno.daniel@blue-yonder.com> | 2015-05-10 13:10:27 +0200 |
commit | 91678e7f34c991daf328d6cc3323c797d93ffff4 (patch) | |
tree | bccfccbbf3181b2592f66192190d734a4a4867bc /pylint/extensions | |
parent | 8efbf56f67d6aaaee3596a87eb682a0fe4cefbb3 (diff) | |
download | pylint-91678e7f34c991daf328d6cc3323c797d93ffff4.tar.gz |
better naming, because the checker now supports not just the Sphinx style
Diffstat (limited to 'pylint/extensions')
-rw-r--r-- | pylint/extensions/check_docs.py | 43 | ||||
-rw-r--r-- | pylint/extensions/test/test_check_docs.py | 72 |
2 files changed, 57 insertions, 58 deletions
diff --git a/pylint/extensions/check_docs.py b/pylint/extensions/check_docs.py index 093d3b0..973b38f 100644 --- a/pylint/extensions/check_docs.py +++ b/pylint/extensions/check_docs.py @@ -1,4 +1,5 @@ -"""Pylint plugin for Sphinx parameter documentation checking +"""Pylint plugin for parameter documentation checking in Sphinx, Google or +Numpy style docstrings """ from __future__ import print_function, division, absolute_import @@ -20,11 +21,12 @@ def space_indentation(s): return len(s) - len(s.lstrip(' ')) -class SphinxDocChecker(BaseChecker): - """Checker for Sphinx documentation parameters +class ParamDocChecker(BaseChecker): + """Checker for parameter documentation in Sphinx, Google or Numpy style + docstrings * Check that all function, method and constructor parameters are mentioned - in the Sphinx params and types part of the docstring. By convention, + in the params and types part of the docstring. By convention, constructor parameters are documented in the class docstring. * Check that there are no naming inconsistencies between the signature and the documentation, i.e. also report documented parameters that are missing @@ -42,14 +44,14 @@ class SphinxDocChecker(BaseChecker): """ __implements__ = IAstroidChecker - name = 'Sphinx doc checks' + name = 'parameter doc checks' msgs = { - 'W9003': ('"%s" missing or differing in Sphinx params', - 'missing-sphinx-param', - 'Please add Sphinx param declarations for all arguments.'), - 'W9004': ('"%s" missing or differing in Sphinx types', - 'missing-sphinx-type', - 'Please add Sphinx type declarations for all arguments.'), + 'W9003': ('"%s" missing or differing in parameter documentation', + 'missing-param-doc', + 'Please add parameter declarations for all parameters.'), + 'W9004': ('"%s" missing or differing in parameter type documentation', + 'missing-type-doc', + 'Please add parameter type declarations for all parameters.'), } options = () @@ -119,19 +121,16 @@ class SphinxDocChecker(BaseChecker): not_needed_param_in_docstring = set(['self', 'cls']) def check_arguments_in_docstring(self, node, doc, arguments_node): - """Check that all arguments in a function, method or class constructor - on the one hand and the arguments mentioned in the Sphinx tags 'param' - and 'type' on the other hand are consistent with each other. + """Check that all parameters in a function, method or class constructor + on the one hand and the parameters mentioned in the parameter + documentation (e.g. the Sphinx tags 'param' and 'type') on the other + hand are consistent with each other. * Undocumented parameters except 'self' are noticed. * Undocumented parameter types except for 'self' and the ``*<args>`` and ``**<kwargs>`` parameters are noticed. - * Parameters mentioned in the Sphinx documentation that don't or no + * Parameters mentioned in the parameter documentation that don't or no longer exist in the function parameter list are noticed. - * If there is a Sphinx link like ``:meth:...`` or ``:func:...`` to a - function carrying the same name as the current function, missing - parameter documentations are tolerated, but the existing parameters - mentioned in the documentation are checked. * If the text "For the parameters, see" or "For the other parameters, see" (ignoring additional whitespace) is mentioned in the docstring, missing parameter documentation is tolerated. @@ -208,9 +207,9 @@ class SphinxDocChecker(BaseChecker): if not params_with_doc: tolerate_missing_params = True - compare_args(params_with_doc, 'missing-sphinx-param', + compare_args(params_with_doc, 'missing-param-doc', self.not_needed_param_in_docstring) - compare_args(params_with_type, 'missing-sphinx-type', + compare_args(params_with_type, 'missing-type-doc', not_needed_type_in_docstring) def match_param_docs(self, doc): @@ -314,4 +313,4 @@ def register(linter): :param linter: Main interface object for Pylint plugins :type linter: Pylint object """ - linter.register_checker(SphinxDocChecker(linter)) + linter.register_checker(ParamDocChecker(linter)) diff --git a/pylint/extensions/test/test_check_docs.py b/pylint/extensions/test/test_check_docs.py index bb0b0bf..3ed916b 100644 --- a/pylint/extensions/test/test_check_docs.py +++ b/pylint/extensions/test/test_check_docs.py @@ -1,5 +1,5 @@ """Unit tests for the pylint checkers in :mod:`pylint.extensions.check_docs`, -in particular the Sphinx parameter documentation checker `SphinxDocChecker` +in particular the parameter documentation checker `ParamDocChecker` """ from __future__ import division, print_function, absolute_import @@ -8,12 +8,12 @@ import unittest from astroid import test_utils from pylint.testutils import CheckerTestCase, Message -from pylint.extensions.check_docs import SphinxDocChecker, space_indentation +from pylint.extensions.check_docs import ParamDocChecker, space_indentation -class SpinxDocCheckerTest(CheckerTestCase): - """Tests for pylint_plugin.SphinxDocChecker""" - CHECKER_CLASS = SphinxDocChecker +class ParamDocCheckerTest(CheckerTestCase): + """Tests for pylint_plugin.ParamDocChecker""" + CHECKER_CLASS = ParamDocChecker def test_space_indentation(self): self.assertEqual(space_indentation('abc'), 0) @@ -37,11 +37,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('y',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('x, y',)) ): @@ -65,11 +65,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('y',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('x, y',)) ): @@ -96,11 +96,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('y',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('x, y',)) ): @@ -139,11 +139,11 @@ class SpinxDocCheckerTest(CheckerTestCase): method_node = node.body[0] with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=method_node, args=('y',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=method_node, args=('x, y',)) ): @@ -168,11 +168,11 @@ class SpinxDocCheckerTest(CheckerTestCase): method_node = node.body[0] with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=method_node, args=('y',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=method_node, args=('x, y',)) ): @@ -199,11 +199,11 @@ class SpinxDocCheckerTest(CheckerTestCase): method_node = node.body[0] with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=method_node, args=('y',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=method_node, args=('x, y',)) ): @@ -304,11 +304,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('xarg, xarg1, zarg, zarg1',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('yarg, yarg1, zarg, zarg1',)), ): @@ -327,11 +327,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('yarg1',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('yarg1',)) ): @@ -355,11 +355,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('xarg, xarg1, zarg, zarg1',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('xarg, xarg1, zarg, zarg1',)), ): @@ -378,11 +378,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('yarg1',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('yarg1',)) ): @@ -410,11 +410,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('xarg, xarg1, zarg, zarg1',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('xarg, xarg1, zarg, zarg1',)), ): @@ -435,11 +435,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('yarg1',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('yarg1',)) ): @@ -525,11 +525,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('x',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('x, y',)) ): @@ -557,11 +557,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('x',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('x, y',)) ): @@ -569,7 +569,7 @@ class SpinxDocCheckerTest(CheckerTestCase): def test_constr_params_in_class_numpy(self): """Example of a class with missing constructor parameter documentation - (Sphinx style) + (Numpy style) Everything is completely analogous to functions. """ @@ -591,11 +591,11 @@ class SpinxDocCheckerTest(CheckerTestCase): """) with self.assertAddsMessages( Message( - msg_id='missing-sphinx-param', + msg_id='missing-param-doc', node=node, args=('x',)), Message( - msg_id='missing-sphinx-type', + msg_id='missing-type-doc', node=node, args=('x, y',)) ): |