Merge branch 'github-actions-lint' into develop

develop
lethosor 2020-07-01 22:08:48 -04:00
commit 8a9e3072e4
3 changed files with 33 additions and 13 deletions

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" Overly-complicated script to check formatting/sorting in Authors.rst """ """ Overly-complicated script to check formatting/sorting in Authors.rst """
import re, sys import os, re, sys
def main(): def main():
success = [True] success = [True]
@ -10,6 +10,8 @@ def main():
for k in kwargs: for k in kwargs:
info += ' %s %s:' % (k, kwargs[k]) info += ' %s %s:' % (k, kwargs[k])
print('line %i:%s %s' % (line, info, msg)) print('line %i:%s %s' % (line, info, msg))
if os.environ.get('GITHUB_ACTIONS'):
print('::error file=docs/Authors.rst,line=%i::%s %s' % (line, info.lstrip(), msg))
success[0] = False success[0] = False
with open('docs/Authors.rst', 'rb') as f: with open('docs/Authors.rst', 'rb') as f:
lines = list(map(lambda line: line.decode('utf8').replace('\n', ''), f.readlines())) lines = list(map(lambda line: line.decode('utf8').replace('\n', ''), f.readlines()))

@ -105,7 +105,7 @@ class TabLinter(Linter):
linters = [cls() for cls in Linter.__subclasses__() if not cls.ignore] linters = [cls() for cls in Linter.__subclasses__() if not cls.ignore]
def main(): def main():
is_github_actions = os.environ.get('GITHUB_ACTIONS') is_github_actions = bool(os.environ.get('GITHUB_ACTIONS'))
root_path = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else '.') root_path = os.path.abspath(sys.argv[1] if len(sys.argv) > 1 else '.')
if not os.path.exists(root_path): if not os.path.exists(root_path):
print('Nonexistent path: %s' % root_path) print('Nonexistent path: %s' % root_path)

@ -1,11 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from __future__ import print_function
from io import open
import os import os
from os.path import basename, dirname, join, splitext from os.path import basename, dirname, join, splitext
import sys import sys
SCRIPT_PATH = sys.argv[1] if len(sys.argv) > 1 else 'scripts' SCRIPT_PATH = sys.argv[1] if len(sys.argv) > 1 else 'scripts'
IS_GITHUB_ACTIONS = bool(os.environ.get('GITHUB_ACTIONS'))
def expected_cmd(path): def expected_cmd(path):
"""Get the command from the name of a script.""" """Get the command from the name of a script."""
@ -20,42 +19,61 @@ def check_ls(fname, line):
line = line.strip() line = line.strip()
comment = '--' if fname.endswith('.lua') else '#' comment = '--' if fname.endswith('.lua') else '#'
if '[====[' in line or not line.startswith(comment): if '[====[' in line or not line.startswith(comment):
print('Error: no leading comment in ' + fname) print_error('missing leading comment (requred for `ls`)', fname)
return 1 return 1
return 0 return 0
def print_error(message, filename, line=None):
if not isinstance(line, int):
line = 1
print('Error: %s:%i: %s' % (filename, line, message))
if IS_GITHUB_ACTIONS:
print('::error file=%s,line=%i::%s' % (filename, line, message))
def check_file(fname): def check_file(fname):
errors, doclines = 0, [] errors, doclines = 0, []
tok1, tok2 = ('=begin', '=end') if fname.endswith('.rb') else \ tok1, tok2 = ('=begin', '=end') if fname.endswith('.rb') else \
('[====[', ']====]') ('[====[', ']====]')
doc_start_line = None
with open(fname, errors='ignore') as f: with open(fname, errors='ignore') as f:
lines = f.readlines() lines = f.readlines()
if not lines:
print_error('empty file', fname)
return 1
errors += check_ls(fname, lines[0]) errors += check_ls(fname, lines[0])
for l in lines: for i, l in enumerate(lines):
if doclines or l.strip().endswith(tok1): if doclines or l.strip().endswith(tok1):
if not doclines:
doc_start_line = i + 1
doclines.append(l.rstrip()) doclines.append(l.rstrip())
if l.startswith(tok2): if l.startswith(tok2):
break break
else: else:
if doclines: if doclines:
print('Error: docs start but not end: ' + fname) print_error('docs start but do not end', fname, doc_start_line)
else: else:
print('Error: no documentation in: ' + fname) print_error('no documentation found', fname)
return 1 return 1
if not doclines: if not doclines:
print('Error: missing or malformed documentation in: ' + fname) print_error('missing or malformed documentation', fname)
return 1 return 1
title, underline = [d for d in doclines title, underline = [d for d in doclines
if d and '=begin' not in d and '[====[' not in d][:2] if d and '=begin' not in d and '[====[' not in d][:2]
if underline != '=' * len(title): title_line = doc_start_line + doclines.index(title)
print('Error: title/underline mismatch:', fname, title, underline) expected_underline = '=' * len(title)
if underline != expected_underline:
print_error('title/underline mismatch: expected {!r}, got {!r}'.format(
expected_underline, underline),
fname, title_line + 1)
errors += 1 errors += 1
if title != expected_cmd(fname): if title != expected_cmd(fname):
print('Warning: expected script title {}, got {}'.format( print_error('expected script title {!r}, got {!r}'.format(
expected_cmd(fname), title)) expected_cmd(fname), title),
fname, title_line)
errors += 1 errors += 1
return errors return errors