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

Improving the dev workflow: Milestone 1.1.3 Custom pylint checks #4967

Merged
merged 55 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
28f20ed
Merge pull request #13 from oppia/develop
apb7 Feb 18, 2018
cdc2856
Merge pull request #14 from oppia/develop
apb7 Feb 22, 2018
af636ec
Merge pull request #15 from oppia/develop
apb7 Feb 25, 2018
860d44c
Merge pull request #16 from oppia/develop
apb7 Feb 26, 2018
0cdc197
Merge pull request #19 from oppia/develop
apb7 Mar 17, 2018
bf888ba
Merge pull request #20 from oppia/develop
apb7 Mar 22, 2018
5e546fd
Merge pull request #21 from oppia/develop
apb7 Mar 28, 2018
9859cd2
Merge pull request #22 from oppia/develop
apb7 Mar 29, 2018
e90fcde
Merge pull request #23 from oppia/develop
apb7 Mar 30, 2018
b7b69fb
Merge pull request #24 from oppia/develop
apb7 Mar 31, 2018
108bd8d
Merge pull request #25 from oppia/develop
apb7 Apr 7, 2018
f165670
Merge pull request #26 from oppia/develop
apb7 Apr 14, 2018
759e4da
Merge pull request #27 from oppia/develop
apb7 Apr 21, 2018
420df20
Merge pull request #28 from oppia/develop
apb7 Apr 24, 2018
0fb552c
Merge pull request #29 from oppia/develop
apb7 May 14, 2018
91dfed9
Merge pull request #30 from oppia/develop
apb7 May 19, 2018
c1f8fea
Merge pull request #31 from oppia/develop
apb7 May 21, 2018
8cf6257
Add local check
apb7 May 22, 2018
dab5560
Basic setup
apb7 May 22, 2018
1a09342
Fix basic lint errors
apb7 May 22, 2018
858c9fc
lint fix
apb7 May 22, 2018
a604851
more lint fix
apb7 May 22, 2018
d4f2f8c
more lint fix
apb7 May 22, 2018
493ddab
lint fix core/controllers
apb7 May 22, 2018
0a9ef41
partial lint fix core/domain
apb7 May 22, 2018
a68d0d7
partial lint fix core/domain()
apb7 May 23, 2018
190d70d
partial lint fix core/domain(2)
apb7 May 23, 2018
e5f6404
lint fix core/domain
apb7 May 23, 2018
d2f2217
lint fix core/platform
apb7 May 23, 2018
0ec1b0e
lint fix core/storage(1)
apb7 May 23, 2018
9552aa9
lint fix core/storage(2)
apb7 May 23, 2018
967925c
lint fix core/tests
apb7 May 23, 2018
5a94ba6
lint fix core/jobs.py
apb7 May 23, 2018
3740fa1
lint fix scripts
apb7 May 23, 2018
16af003
Merge pull request #32 from oppia/develop
apb7 May 23, 2018
038cd2b
Merge branch 'develop' of https://github.com/apb7/oppia into custom-p…
apb7 May 23, 2018
aeeb2b6
more fixes
apb7 May 23, 2018
7bfcffa
some more fixes
apb7 May 23, 2018
bd9548b
add tests
apb7 May 23, 2018
c83ea68
lint fix
apb7 May 23, 2018
b6f14f1
Update returns
apb7 May 23, 2018
308b750
Review changes(1)
apb7 May 24, 2018
2110909
lint fix
apb7 May 24, 2018
5ceec71
minor fix
apb7 May 24, 2018
9075e29
Address all review comments except returns
apb7 May 24, 2018
9e66a21
lint fix
apb7 May 24, 2018
c616ecd
fix yields
apb7 May 24, 2018
aa63883
remove unnecessary returns
apb7 May 24, 2018
8b354ca
Fix backend tests
apb7 May 24, 2018
058b7ee
Address all review comments
apb7 May 25, 2018
3496860
Add doc utils
apb7 May 25, 2018
dae48e7
Add yields line
apb7 May 25, 2018
3cc5d33
lint fix
apb7 May 25, 2018
f398be4
Review changes
apb7 May 25, 2018
5769c5f
Review changes
apb7 May 25, 2018
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
Prev Previous commit
Next Next commit
more lint fix
  • Loading branch information
apb7 committed May 22, 2018
commit a604851e17838ff3f376011c368dc554bb03ecae
3 changes: 2 additions & 1 deletion scripts/_check_docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

"""Utility methods for docstring checking."""

from __future__ import absolute_import, print_function
from __future__ import absolute_import
from __future__ import print_function

import re

Expand Down
61 changes: 37 additions & 24 deletions scripts/custom_lint_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function, division, absolute_import
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import _check_docs_utils as utils
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to follow their convention here. We can just call our file docstrings_checker.py or similar and do import docstrings_checker.

In general try to avoid aliasing (import X as Y) where possible.

import astroid

from pylint.checkers import BaseChecker
from pylint.checkers import utils as checker_utils
from pylint.interfaces import IAstroidChecker
from pylint.interfaces import IRawChecker
from pylint.checkers import utils as checker_utils
import _check_docs_utils as utils


class ExplicitKwargsChecker(BaseChecker):
Expand Down Expand Up @@ -173,15 +176,19 @@ class DocstringParameterChecker(BaseChecker):

name = 'parameter_documentation'
msgs = {
'W9005': ('"%s" has constructor parameters documented in class and __init__',
'W9005': ('''"%s" has constructor parameters
documented in class and __init__''',
'multiple-constructor-doc',
'Please remove parameter declarations in the class or constructor.'),
'''Please remove parameter declarations
in the class or constructor.'''),
'W9006': ('"%s" not documented as being raised',
'missing-raises-doc',
'Please document exceptions for all raised exception types.'),
'''Please document exceptions for
all raised exception types.'''),
'W9008': ('Redundant returns documentation',
'redundant-returns-doc',
'Please remove the return/rtype documentation from this method.'),
'''Please remove the return/rtype
documentation from this method.'''),
'W9010': ('Redundant yields documentation',
'redundant-yields-doc',
'Please remove the yields documentation from this method.'),
Expand Down Expand Up @@ -224,25 +231,25 @@ class DocstringParameterChecker(BaseChecker):
}

options = (('accept-no-param-doc',
{'default': True, 'type' : 'yn', 'metavar' : '<y or n>',
{'default': True, 'type': 'yn', 'metavar': '<y or n>',
'help': 'Whether to accept totally missing parameter '
'documentation in the docstring of a function that has '
'parameters.'
'documentation in the docstring of a '
'function that has parameters.'
}),
('accept-no-raise-doc',
{'default': True, 'type' : 'yn', 'metavar' : '<y or n>',
{'default': True, 'type': 'yn', 'metavar': '<y or n>',
'help': 'Whether to accept totally missing raises '
'documentation in the docstring of a function that '
'raises an exception.'
}),
('accept-no-return-doc',
{'default': True, 'type' : 'yn', 'metavar' : '<y or n>',
{'default': True, 'type': 'yn', 'metavar': '<y or n>',
'help': 'Whether to accept totally missing return '
'documentation in the docstring of a function that '
'returns a statement.'
}),
('accept-no-yields-doc',
{'default': True, 'type' : 'yn', 'metavar': '<y or n>',
{'default': True, 'type': 'yn', 'metavar': '<y or n>',
'help': 'Whether to accept totally missing yields '
'documentation in the docstring of a generator.'
}),
Expand Down Expand Up @@ -270,7 +277,8 @@ def check_functiondef_params(self, node, node_doc):
class_node = checker_utils.node_frame_class(node)
if class_node is not None:
class_doc = utils.docstringify(class_node.doc)
self.check_single_constructor_params(class_doc, node_doc, class_node)
self.check_single_constructor_params(
class_doc, node_doc, class_node)

# __init__ or class docstrings can have no parameters documented
# as long as the other documents them.
Expand All @@ -296,8 +304,11 @@ def check_functiondef_returns(self, node, node_doc):
return

return_nodes = node.nodes_of_class(astroid.Return)
if ((node_doc.has_returns() or node_doc.has_rtype()) and
not any(utils.returns_something(ret_node) for ret_node in return_nodes)):
if ((
node_doc.has_returns() or node_doc.has_rtype()) and
not any(
utils.returns_something(
ret_node) for ret_node in return_nodes)):
self.add_message(
'redundant-returns-doc',
node=node)
Expand Down Expand Up @@ -397,8 +408,8 @@ def visit_yield(self, node):
def visit_yieldfrom(self, node):
self.visit_yield(node)

def check_arguments_in_docstring(self, doc, arguments_node, warning_node,
accept_no_param_doc=None):
def check_arguments_in_docstring(
self, doc, arguments_node, warning_node, accept_no_param_doc=None):
"""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
Expand Down Expand Up @@ -442,8 +453,10 @@ class constructor.
tolerate_missing_params = doc.params_documented_elsewhere()

# Collect the function arguments.
expected_argument_names = set(arg.name for arg in arguments_node.args)
expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
expected_argument_names = set(
arg.name for arg in arguments_node.args)
expected_argument_names.update(
arg.name for arg in arguments_node.kwonlyargs)
not_needed_type_in_docstring = (
self.not_needed_param_in_docstring.copy())

Expand All @@ -460,8 +473,8 @@ class constructor.
and accept_no_param_doc):
tolerate_missing_params = True

def _compare_missing_args(found_argument_names, message_id,
not_needed_names):
def _compare_missing_args(
found_argument_names, message_id, not_needed_names):
"""Compare the found argument names with the expected ones and
generate a message if there are arguments missing.

Expand All @@ -484,8 +497,8 @@ def _compare_missing_args(found_argument_names, message_id,
sorted(missing_argument_names)),),
node=warning_node)

def _compare_different_args(found_argument_names, message_id,
not_needed_names):
def _compare_different_args(
found_argument_names, message_id, not_needed_names):
"""Compare the found argument names with the expected ones and
generate a message if there are extra arguments found.

Expand Down