Chromium Code Reviews| Index: third_party/WebKit/Tools/Scripts/webkitpy/formatter/fix_docstrings.py |
| diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/formatter/fix_docstrings.py b/third_party/WebKit/Tools/Scripts/webkitpy/formatter/fix_docstrings.py |
| index 246e5315ec0f47b247e09d01ffd6e247e0fa1aa3..d4ad417db9849257f3f6007962508008be88d0d6 100644 |
| --- a/third_party/WebKit/Tools/Scripts/webkitpy/formatter/fix_docstrings.py |
| +++ b/third_party/WebKit/Tools/Scripts/webkitpy/formatter/fix_docstrings.py |
| @@ -12,6 +12,7 @@ import re |
| from lib2to3.fixer_base import BaseFix |
| from lib2to3.pgen2 import token |
| +from lib2to3.pygram import python_symbols |
| class FixDocstrings(BaseFix): |
| @@ -20,7 +21,21 @@ class FixDocstrings(BaseFix): |
| _accept_type = token.STRING |
| def match(self, node): |
| - return node.value.startswith('"""') and node.prev_sibling is None |
| + """Returns True if the given node appears to be a docstring. |
| + |
| + Docstrings should always have no previous siblings, and should be |
| + direct children of simple_stmt. |
| + |
| + Note: This may also match for some edge cases where there are |
| + simple_stmt strings that aren't the first thing in a module, class |
| + or function, and thus aren't considered docstrings; but changing these |
| + strings should not change behavior. |
| + """ |
| + # Pylint incorrectly warns that there's no member simple_stmt on python_symbols |
| + # because the attribute is set dynamically. pylint: disable=no-member |
| + return (node.value.startswith('"""') and |
| + node.prev_sibling is None and |
| + node.parent.type == python_symbols.simple_stmt) |
|
qyearsley
2016/09/04 19:42:46
After running the formatter on the webkitpy codeba
Dirk Pranke
2016/09/06 01:14:27
Acknowledged.
|
| def transform(self, node, results): |
| # First, strip whitespace at the beginning and end. |