Skip to content

Commit

Permalink
Don't fail out if the python docstring on the first line of a file is…
Browse files Browse the repository at this point in the history
… too long

Summary: See https://app.asana.com/0/27216215224639/40389455104495

Test Plan:
In webapp:

    python -c "print '\"\"\"' + '.' * 80 + '\"\"\"\n'" > foo.py
    ~/khan/devtools/khan-linter/runlint.py foo.py

And see that it outputs this:

    foo.py:1:80: E501 line too long (86 characters)

Instead of this:

    local variable 'linenum' referenced before assignment

Reviewers: csilvers

Reviewed By: csilvers

Subscribers: colin

Differential Revision: https://phabricator.khanacademy.org/D19293
  • Loading branch information
jlfwong committed Jul 14, 2015
1 parent 17bfb1f commit 323c7a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .arcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"project_id": "khan-linter",
"conduit_uri": "https://phabricator.khanacademy.org/",
"lint.engine": "ArcanistConfigurationDrivenLintEngine"
}
9 changes: 9 additions & 0 deletions .arclint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"linters": {
"khan-linter": {
"type": "script-and-regex",
"script-and-regex.script": "~\/khan\/devtools\/khan-linter\/runlint.py --always-exit-0 --blacklist=yes --propose-arc-fixes",
"script-and-regex.regex": "\/^((?P<file>[^:]*):(?P<line>\\d+):((?P<char>\\d+):)? (?P<name>((?P<error>E)|(?P<warning>W))\\S+) (?P<message>[^\\x00]*)(\\x00(?P<original>[^\\x00]*)\\x00(?P<replacement>[^\\x00]*)\\x00)?)|(?P<ignore>SKIPPING.*)$\/m"
}
}
}
6 changes: 4 additions & 2 deletions linters.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ def _process_one_line(self, output_line, contents_lines):
# should work well enough.
if ('E501 line too long' in lintline and
bad_line.lstrip().startswith('"') and
bad_line.rstrip(',\n').endswith('"')):
for linenum in xrange(bad_linenum - 1, 0, -1):
bad_line.rstrip(',\n').endswith('"') and
bad_linenum):

for linenum in xrange(bad_linenum, 0, -1):
if (contents_lines[linenum].lstrip().startswith('"""') or
contents_lines[linenum].lstrip().startswith("'''")):
break
Expand Down

0 comments on commit 323c7a6

Please sign in to comment.