summaryrefslogtreecommitdiff
path: root/.gitlab/linters/check-makefiles.py
blob: 5a8286c6a7b81c5f96bb25bbde479d30102c70a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3

"""
Linters for testsuite makefiles
"""

from linter import run_linters, RegexpLinter

"""
Warn for use of `--interactive` inside Makefiles (#11468).

Encourage the use of `$(TEST_HC_OPTS_INTERACTIVE)` instead of
`$(TEST_HC_OPTS) --interactive -ignore-dot-ghci -v0`. It's too easy to
forget one of those flags when adding a new test.
"""
interactive_linter = \
    RegexpLinter(r'--interactive',
                 message = "Warning: Use `$(TEST_HC_OPTS_INTERACTIVE)` instead of `--interactive -ignore-dot-ghci -v0`."
                ).add_path_filter(lambda path: path.name == 'Makefile')

test_hc_quotes_linter = \
    RegexpLinter('\t\\$\\(TEST_HC\\)',
                 message = "Warning: $(TEST_HC) should be quoted in Makefiles.",
                ).add_path_filter(lambda path: path.name == 'Makefile')

ghc_pkg_quotes_linter = \
    RegexpLinter('\t\\$\\(GHC_PKG\\)',
                 message = "Warning: $(GHC_PKG) should be quoted in Makefiles.",
                ).add_path_filter(lambda path: path.name == 'Makefile')

haddock_quotes_linter = \
    RegexpLinter('\t\\$\\(HADDOCK\\)',
                 message = "Warning: $(HADDOCK) should be quoted in Makefiles.",
                ).add_path_filter(lambda path: path.name == 'Makefile')

linters = [
    interactive_linter,
    test_hc_quotes_linter,
    ghc_pkg_quotes_linter,
    haddock_quotes_linter
]

if __name__ == '__main__':
    run_linters(linters,
                subdir='testsuite')