[Git][ghc/ghc][wip/lint-testsuite] 2 commits: lint: Only apply --interactive lint to testsuite .T files
Ben Gamari
gitlab at gitlab.haskell.org
Wed Jun 12 15:11:49 UTC 2019
Ben Gamari pushed to branch wip/lint-testsuite at Glasgow Haskell Compiler / GHC
Commits:
d117bb78 by Ben Gamari at 2019-06-12T15:07:16Z
lint: Only apply --interactive lint to testsuite .T files
- - - - -
e6f8160a by Ben Gamari at 2019-06-12T15:11:31Z
gitlab-ci: Lint the linters
- - - - -
3 changed files:
- .gitlab-ci.yml
- .gitlab/linters/check-makefiles.py
- .gitlab/linters/linter.py
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -70,6 +70,15 @@ ghc-linters:
refs:
- merge_requests
+lint-linters:
+ stage: lint
+ image: "nixos/nix"
+ script:
+ - nix run nixpkgs.python3Packages.mypy -c mypy .gitlab/linters/*.py
+ dependencies: []
+ tags:
+ - lint
+
lint-testsuite:
stage: lint
image: "registry.gitlab.haskell.org/ghc/ci-images/x86_64-linux-deb9:$DOCKER_REV"
=====================================
.gitlab/linters/check-makefiles.py
=====================================
@@ -12,8 +12,10 @@ from linter import run_linters, RegexpLinter
linters = [
RegexpLinter(r'--interactive',
- message = "Warning: Use `$(TEST_HC_OPTS_INTERACTIVE)` instead of `--interactive -ignore-dot-ghci -v0`.")
+ message = "Warning: Use `$(TEST_HC_OPTS_INTERACTIVE)` instead of `--interactive -ignore-dot-ghci -v0`."
+ ).add_path_filter(lambda path: path.suffix == '.T')
]
if __name__ == '__main__':
- run_linters(linters, subdir='testsuite')
+ run_linters(linters,
+ subdir='testsuite')
=====================================
.gitlab/linters/linter.py
=====================================
@@ -7,7 +7,8 @@ import sys
import re
import textwrap
import subprocess
-from typing import List, Optional
+from pathlib import Path
+from typing import List, Optional, Callable, Sequence
from collections import namedtuple
def lint_failure(file, line_no, line_content, message):
@@ -46,12 +47,21 @@ class Linter(object):
"""
def __init__(self):
self.warnings = [] # type: List[Warning]
+ self.path_filters = [] # type: List[Callable[[Path], bool]]
def add_warning(self, w: Warning):
self.warnings.append(w)
+ def add_path_filter(self, f: Callable[[Path], bool]) -> "Linter":
+ self.path_filters.append(f)
+ return self
+
+ def do_lint(self, path):
+ if all(f(path) for f in self.path_filters):
+ self.lint(path)
+
def lint(self, path):
- pass
+ raise NotImplementedError
class LineLinter(Linter):
"""
@@ -66,7 +76,7 @@ class LineLinter(Linter):
self.lint_line(path, line_no+1, line)
def lint_line(self, path, line_no, line):
- pass
+ raise NotImplementedError
class RegexpLinter(LineLinter):
"""
@@ -84,7 +94,7 @@ class RegexpLinter(LineLinter):
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()
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/57dfc10b675e5d3ac5b59edafeabe513b825a300...e6f8160a268563622cf8aafaf8f27abcbb657bc6
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/57dfc10b675e5d3ac5b59edafeabe513b825a300...e6f8160a268563622cf8aafaf8f27abcbb657bc6
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/e59e8632/attachment-0001.html>
More information about the ghc-commits
mailing list