mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix flake8 violations
This commit is contained in:
parent
7dcb40d135
commit
76ecccf8af
@ -63,7 +63,7 @@ def decode_source(fn, lines):
|
|||||||
decoded_lines.append(line.decode(encoding))
|
decoded_lines.append(line.decode(encoding))
|
||||||
except UnicodeDecodeError as err:
|
except UnicodeDecodeError as err:
|
||||||
raise UnicodeError("%s:%d: not decodable: %s\n Line: %r" %
|
raise UnicodeError("%s:%d: not decodable: %s\n Line: %r" %
|
||||||
(fn, lno+1, err, line))
|
(fn, lno + 1, err, line))
|
||||||
except LookupError as err:
|
except LookupError as err:
|
||||||
raise LookupError("unknown encoding: %s" % encoding)
|
raise LookupError("unknown encoding: %s" % encoding)
|
||||||
return decoded_lines
|
return decoded_lines
|
||||||
@ -82,14 +82,14 @@ def check_syntax(fn, lines):
|
|||||||
def check_style(fn, lines):
|
def check_style(fn, lines):
|
||||||
for lno, line in enumerate(lines):
|
for lno, line in enumerate(lines):
|
||||||
if len(line.rstrip('\n')) > 95:
|
if len(line.rstrip('\n')) > 95:
|
||||||
yield lno+1, "line too long"
|
yield lno + 1, "line too long"
|
||||||
if line.strip().startswith('#'):
|
if line.strip().startswith('#'):
|
||||||
continue
|
continue
|
||||||
# m = not_ix_re.search(line)
|
# m = not_ix_re.search(line)
|
||||||
# if m:
|
# if m:
|
||||||
# yield lno+1, '"' + m.group() + '"'
|
# yield lno+1, '"' + m.group() + '"'
|
||||||
if is_const_re.search(line):
|
if is_const_re.search(line):
|
||||||
yield lno+1, 'using == None/True/False'
|
yield lno + 1, 'using == None/True/False'
|
||||||
|
|
||||||
|
|
||||||
@checker('.py', only_pkg=True)
|
@checker('.py', only_pkg=True)
|
||||||
@ -116,11 +116,11 @@ def check_fileheader(fn, lines):
|
|||||||
if l == '"""\n':
|
if l == '"""\n':
|
||||||
# end of docstring
|
# end of docstring
|
||||||
if lno <= 4:
|
if lno <= 4:
|
||||||
yield lno+c, "missing module name in docstring"
|
yield lno + c, "missing module name in docstring"
|
||||||
break
|
break
|
||||||
|
|
||||||
if l != '\n' and l[:4] != ' ' and docopen:
|
if l != '\n' and l[:4] != ' ' and docopen:
|
||||||
yield lno+c, "missing correct docstring indentation"
|
yield lno + c, "missing correct docstring indentation"
|
||||||
|
|
||||||
if lno == 2:
|
if lno == 2:
|
||||||
# if not in package, don't check the module name
|
# if not in package, don't check the module name
|
||||||
@ -145,10 +145,10 @@ def check_fileheader(fn, lines):
|
|||||||
yield 0, "no correct license info"
|
yield 0, "no correct license info"
|
||||||
|
|
||||||
ci = -3
|
ci = -3
|
||||||
copyright = llist[ci:ci+1]
|
copyright = llist[ci:ci + 1]
|
||||||
while copyright and copyright_2_re.match(copyright[0]):
|
while copyright and copyright_2_re.match(copyright[0]):
|
||||||
ci -= 1
|
ci -= 1
|
||||||
copyright = llist[ci:ci+1]
|
copyright = llist[ci:ci + 1]
|
||||||
if not copyright or not copyright_re.match(copyright[0]):
|
if not copyright or not copyright_re.match(copyright[0]):
|
||||||
yield 0, "no correct copyright info"
|
yield 0, "no correct copyright info"
|
||||||
|
|
||||||
@ -157,12 +157,12 @@ def check_fileheader(fn, lines):
|
|||||||
def check_whitespace_and_spelling(fn, lines):
|
def check_whitespace_and_spelling(fn, lines):
|
||||||
for lno, line in enumerate(lines):
|
for lno, line in enumerate(lines):
|
||||||
if '\t' in line:
|
if '\t' in line:
|
||||||
yield lno+1, "OMG TABS!!!1 "
|
yield lno + 1, "OMG TABS!!!1 "
|
||||||
if line[:-1].rstrip(' \t') != line[:-1]:
|
if line[:-1].rstrip(' \t') != line[:-1]:
|
||||||
yield lno+1, "trailing whitespace"
|
yield lno + 1, "trailing whitespace"
|
||||||
for word in misspellings:
|
for word in misspellings:
|
||||||
if word in line and 'ALLOW-MISSPELLING' not in line:
|
if word in line and 'ALLOW-MISSPELLING' not in line:
|
||||||
yield lno+1, '"%s" used' % word
|
yield lno + 1, '"%s" used' % word
|
||||||
|
|
||||||
|
|
||||||
bad_tags = ['<u>', '<s>', '<strike>', '<center>', '<font']
|
bad_tags = ['<u>', '<s>', '<strike>', '<center>', '<font']
|
||||||
@ -173,7 +173,7 @@ def check_xhtml(fn, lines):
|
|||||||
for lno, line in enumerate(lines):
|
for lno, line in enumerate(lines):
|
||||||
for bad_tag in bad_tags:
|
for bad_tag in bad_tags:
|
||||||
if bad_tag in line:
|
if bad_tag in line:
|
||||||
yield lno+1, "used " + bad_tag
|
yield lno + 1, "used " + bad_tag
|
||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
|
@ -35,8 +35,8 @@ def fold(jsonData, splitter):
|
|||||||
lines.append(' ' + code)
|
lines.append(' ' + code)
|
||||||
break
|
break
|
||||||
index = code.index(splitter, 70)
|
index = code.index(splitter, 70)
|
||||||
lines.append(' ' + code[:index+len(splitter)])
|
lines.append(' ' + code[:index + len(splitter)])
|
||||||
code = code[index+len(splitter):]
|
code = code[index + len(splitter):]
|
||||||
lines[0] = lines[0][8:]
|
lines[0] = lines[0][8:]
|
||||||
return '\n'.join(lines)
|
return '\n'.join(lines)
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ def _rstrip(line, JUNK='\n \t'):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
i = len(line)
|
i = len(line)
|
||||||
while i > 0 and line[i-1] in JUNK:
|
while i > 0 and line[i - 1] in JUNK:
|
||||||
i -= 1
|
i -= 1
|
||||||
return line[:i]
|
return line[:i]
|
||||||
|
|
||||||
@ -204,9 +204,9 @@ class Reindenter:
|
|||||||
# we see a line with *something* on it.
|
# we see a line with *something* on it.
|
||||||
i = stats[0][0]
|
i = stats[0][0]
|
||||||
after.extend(lines[1:i])
|
after.extend(lines[1:i])
|
||||||
for i in range(len(stats)-1):
|
for i in range(len(stats) - 1):
|
||||||
thisstmt, thislevel = stats[i]
|
thisstmt, thislevel = stats[i]
|
||||||
nextstmt = stats[i+1][0]
|
nextstmt = stats[i + 1][0]
|
||||||
have = getlspace(lines[thisstmt])
|
have = getlspace(lines[thisstmt])
|
||||||
want = thislevel * 4
|
want = thislevel * 4
|
||||||
if want < 0:
|
if want < 0:
|
||||||
@ -218,7 +218,7 @@ class Reindenter:
|
|||||||
want = have2want.get(have, -1)
|
want = have2want.get(have, -1)
|
||||||
if want < 0:
|
if want < 0:
|
||||||
# Then it probably belongs to the next real stmt.
|
# Then it probably belongs to the next real stmt.
|
||||||
for j in range(i+1, len(stats)-1):
|
for j in range(i + 1, len(stats) - 1):
|
||||||
jline, jlevel = stats[j]
|
jline, jlevel = stats[j]
|
||||||
if jlevel >= 0:
|
if jlevel >= 0:
|
||||||
if have == getlspace(lines[jline]):
|
if have == getlspace(lines[jline]):
|
||||||
@ -228,10 +228,10 @@ class Reindenter:
|
|||||||
# comment like this one,
|
# comment like this one,
|
||||||
# in which case we should shift it like its base
|
# in which case we should shift it like its base
|
||||||
# line got shifted.
|
# line got shifted.
|
||||||
for j in range(i-1, -1, -1):
|
for j in range(i - 1, -1, -1):
|
||||||
jline, jlevel = stats[j]
|
jline, jlevel = stats[j]
|
||||||
if jlevel >= 0:
|
if jlevel >= 0:
|
||||||
want = (have + getlspace(after[jline-1]) -
|
want = (have + getlspace(after[jline - 1]) -
|
||||||
getlspace(lines[jline]))
|
getlspace(lines[jline]))
|
||||||
break
|
break
|
||||||
if want < 0:
|
if want < 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user