[Git][ghc/ghc][wip/lint-testsuite] gitlab-ci: Lint the linters
Ben Gamari
gitlab at gitlab.haskell.org
Wed Jun 12 16:32:51 UTC 2019
Ben Gamari pushed to branch wip/lint-testsuite at Glasgow Haskell Compiler / GHC
Commits:
1a03d259 by Ben Gamari at 2019-06-12T16:32:40Z
gitlab-ci: Lint the linters
- - - - -
2 changed files:
- .gitlab-ci.yml
- .gitlab/linters/linter.py
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -2,7 +2,7 @@ variables:
GIT_SSL_NO_VERIFY: "1"
# Commit of ghc/ci-images repository from which to pull Docker images
- DOCKER_REV: ac65f31dcffb09cd7ca7aaa70f447fcbb19f427f
+ DOCKER_REV: 88e952f165f48cfb956ac9a2486a9263aa4f777c
# Sequential version number capturing the versions of all tools fetched by
# .gitlab/win32-init.sh.
@@ -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
only:
- master
@@ -70,7 +71,18 @@ ghc-linters:
refs:
- merge_requests
+lint-linters:
+ <<: *only-default
+ stage: lint
+ image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
+ script:
+ - mypy .gitlab/linters/*.py
+ dependencies: []
+ tags:
+ - lint
+
lint-testsuite:
+ <<: *only-default
stage: lint
image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:$DOCKER_REV"
script:
@@ -83,6 +95,7 @@ lint-testsuite:
# accomodate, e.g., haddock changes not yet upstream) but not on `master` or
# Marge jobs.
.lint-submods:
+ <<: *only-default
stage: lint
image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
script:
@@ -125,6 +138,7 @@ lint-submods-branch:
- /ghc-[0-9]+\.[0-9]+/
.lint-changelogs:
+ <<: *only-default
stage: lint
image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV"
dependencies: []
=====================================
.gitlab/linters/linter.py
=====================================
@@ -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):
print(textwrap.dedent(msg))
-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):
self.path_filters.append(f)
return self
- def do_lint(self, path):
+ def do_lint(self, path: Path):
if all(f(path) for f in self.path_filters):
self.lint(path)
- 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 path.open('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,18 +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):
+ def __init__(self, regex: str, message: str):
LineLinter.__init__(self)
self.re = re.compile(regex)
self.message = message
- def lint_line(self, path, line_no, line):
+ def lint_line(self, path: Path, line_no: int, line: str):
if self.re.search(line):
w = Warning(path=path, line_no=line_no, line_content=line[:-1],
message=self.message)
self.add_warning(w)
-def run_linters(linters: List[Linter],
+def run_linters(linters: Sequence[Linter],
subdir: str = '.') -> None:
import argparse
parser = argparse.ArgumentParser()
@@ -106,7 +106,7 @@ def run_linters(linters: List[Linter],
if path.startswith('.gitlab/linters'):
continue
for linter in linters:
- linter.do_lint(path)
+ linter.do_lint(Path(path))
warnings = [warning
for linter in linters
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/1a03d2596823a4e788f70c8cfc49ff6f200a83e8
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/commit/1a03d2596823a4e788f70c8cfc49ff6f200a83e8
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190612/8fbed88d/attachment-0001.html>
More information about the ghc-commits
mailing list