-
Notifications
You must be signed in to change notification settings - Fork 26
/
Makefile.linting
66 lines (55 loc) · 2.14 KB
/
Makefile.linting
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
### VARIABLES ###
SHELLCHECK_ARGS += $(shell [ ! -d scripts ] || find scripts -type f -exec awk 'FNR == 1 && /sh$$/ { print FILENAME }' {} +)
export SHELLCHECK_ARGS
### TARGETS ###
.PHONY: gitlint golangci-lint markdownlint packagedoc-lint shellcheck yamllint
# [gitlint] validates the commits are valid
gitlint:
if [ -r .gitlint ]; then \
gitlint --commits origin/$(BASE_BRANCH)..HEAD; \
else \
gitlint --config $(SHIPYARD_DIR)/.gitlint --commits origin/$(BASE_BRANCH)..HEAD; \
fi
# [golangci-lint] validates Go code in the project
golangci-lint:
ifneq (,$(shell find . -name '*.go'))
golangci-lint version
golangci-lint linters
# Set up a workspace to include all modules, if necessary
# If a workspace is already set up, it will be used instead
find . -name go.mod -execdir git grep -qFl 'func ' -- '*.go' \; -printf '%h ' | xargs go work init ||:
# Analyse all the modules containing function declarations
golangci-lint run --out-format=colored-line-number --timeout 10m $$(find . -name go.mod -execdir git grep -qFl 'func ' -- '*.go' \; -printf '%h/...\n')
else
@echo 'There are no Go files to lint.'
endif
# [markdownlint] validates Markdown files in the project
markdownlint:
md_ignored=(); \
if [ -r .mdignore ]; then \
md_ignored+=($$(< .mdignore)); \
fi; \
markdownlint -c .markdownlint.yml $${md_ignored[@]/#/-i } .
# [packagedoc-lint] checks that the package docs don’t include the SPDX header
packagedoc-lint:
result=0; \
for package in $$(find . -name vendor -prune -o -name \*.go -printf "%h\n" | sort -u); do \
if $(GO) doc $$package | grep -q SPDX; then \
echo $$package has an invalid package documentation; \
result=1; \
fi; \
done 2>/dev/null; \
exit $$result
# [shellcheck] validates your shell files
shellcheck:
# Only run shellcheck if there are files to check
ifneq (,$(SHELLCHECK_ARGS))
shellcheck -x -P $${SCRIPTS_DIR} $(SHELLCHECK_ARGS)
# https://github.com/koalaman/shellcheck/issues/1659
! grep $$'\t' $(SHELLCHECK_ARGS)
else
@echo 'There are no shell scripts to check; if this is incorrect, specify them in SHELLCHECK_ARGS.'
endif
# [yamllint] validates YAML files in the project
yamllint:
yamllint --strict .