Commit 5c97211c authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Marge Bot

gitlab-ci: Lint the linters

parent b5ea9323
Pipeline #7168 failed with stages
in 327 minutes and 36 seconds
......@@ -27,6 +27,7 @@ stages:
- hackage # head.hackage testing
- deploy # push documentation
# N.B.Don't run on wip/ branches, instead on run on merge requests.
.only-default: &only-default
- master
......@@ -70,7 +71,18 @@ ghc-linters:
- merge_requests
<<: *only-default
stage: lint
image: "$DOCKER_REV"
- mypy .gitlab/linters/*.py
dependencies: []
- lint
<<: *only-default
stage: lint
image: "$DOCKER_REV"
......@@ -83,6 +95,7 @@ lint-testsuite:
# accomodate, e.g., haddock changes not yet upstream) but not on `master` or
# Marge jobs.
<<: *only-default
stage: lint
image: "$DOCKER_REV"
......@@ -127,6 +140,7 @@ lint-submods-branch:
- /ghc-[0-9]+\.[0-9]+/
<<: *only-default
stage: lint
image: "$DOCKER_REV"
dependencies: []
......@@ -8,10 +8,10 @@ import re
import textwrap
import subprocess
from pathlib import Path
from typing import List, Optional, Callable
from typing import List, Optional, Callable, Sequence
from collections import namedtuple
def lint_failure(file, line_no, line_content, message):
def lint_failure(file, line_no: int, line_content: str, message: str):
""" Print a lint failure message. """
wrapper = textwrap.TextWrapper(initial_indent=' ',
subsequent_indent=' ')
......@@ -30,7 +30,7 @@ def lint_failure(file, line_no, line_content, message):
def get_changed_files(base_commit, head_commit,
def get_changed_files(base_commit: str, head_commit: str,
subdir: str = '.'):
""" Get the files changed by the given range of commits. """
cmd = ['git', 'diff', '--name-only',
......@@ -56,11 +56,11 @@ class Linter(object):
return self
def do_lint(self, path):
def do_lint(self, path: Path):
if all(f(path) for f in self.path_filters):
def lint(self, path):
def lint(self, path: Path):
raise NotImplementedError
class LineLinter(Linter):
......@@ -69,13 +69,13 @@ class LineLinter(Linter):
the given line from a file and calls :func:`add_warning` for any lint
issues found.
def lint(self, path):
if os.path.isfile(path):
with open(path, 'r') as f:
def lint(self, path: Path):
if path.is_file():
with'r') as f:
for line_no, line in enumerate(f):
self.lint_line(path, line_no+1, line)
def lint_line(self, path, line_no, line):
def lint_line(self, path: Path, line_no: int, line: str):
raise NotImplementedError
class RegexpLinter(LineLinter):
......@@ -83,19 +83,18 @@ class RegexpLinter(LineLinter):
A :class:`RegexpLinter` produces the given warning message for
all lines matching the given regular expression.
def __init__(self, regex, message, path_filter=lambda path: True):
def __init__(self, regex: str, message: str):
LineLinter.__init__(self) = re.compile(regex)
self.message = message
self.path_filter = path_filter
def lint_line(self, path, line_no, line):
if self.path_filter(path) and
def lint_line(self, path: Path, line_no: int, line: str):
w = Warning(path=path, line_no=line_no, line_content=line[:-1],
def run_linters(linters: List[Linter],
def run_linters(linters: Sequence[Linter],
subdir: str = '.') -> None:
import argparse
parser = argparse.ArgumentParser()
......@@ -107,7 +106,7 @@ def run_linters(linters: List[Linter],
if path.startswith('.gitlab/linters'):
for linter in linters:
warnings = [warning
for linter in linters
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment