forked from devilbox/makefiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.lint
152 lines (135 loc) · 5.09 KB
/
Makefile.lint
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
ifneq (,)
.error This Makefile requires GNU Make.
endif
ifndef VERBOSE
MAKEFLAGS += --no-print-directory
endif
# -------------------------------------------------------------------------------------------------
# Default configuration
# -------------------------------------------------------------------------------------------------
CURRENT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# File lint
FL_VERSION = latest
FL_IGNORES = .git/,.github/
# Json lint
JL_VERSION = latest
JL_IGNORES = .git/,.github/
# Yamllint
YL_VERSION = latest
# Shellcheck
SC_IGNORES = .git/,.github/
SC_VERSION = stable
# -------------------------------------------------------------------------------------------------
# Lint Targets
# -------------------------------------------------------------------------------------------------
.PHONY: lint
lint: lint-files
lint: lint-yaml
lint: lint-json
lint: lint-bash
.PHONY: lint-files
lint-files: _lint-files-pull
lint-files:
@echo "################################################################################"
@echo "# Lint Files"
@echo "################################################################################"
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-cr --text --ignore '$(FL_IGNORES)' --path .
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-crlf --text --ignore '$(FL_IGNORES)' --path .
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-trailing-single-newline --text --ignore '$(FL_IGNORES)' --path .
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-trailing-space --text --ignore '$(FL_IGNORES)' --path .
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-utf8 --text --ignore '$(FL_IGNORES)' --path .
@docker run --rm $$(tty -s && echo "-it" || echo) -v $(CURRENT_DIR):/data cytopia/file-lint:$(FL_VERSION) file-utf8-bom --text --ignore '$(FL_IGNORES)' --path .
@echo
.PHONY: lint-yaml
lint-yaml: _lint-yaml-pull
lint-yaml:
@echo "################################################################################"
@echo "# Lint Yaml"
@echo "################################################################################"
@if docker run --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/yamllint:$(YL_VERSION) .; then \
echo "OK"; \
else \
echo "Failed"; \
exit 1; \
fi;
@echo
.PHONY: lint-json
lint-json: _lint-json-pull
lint-json:
@echo "################################################################################"
@echo "# Lint JSON"
@echo "################################################################################"
@if docker run --rm $$(tty -s && echo "-it" || echo) -v "$(CURRENT_DIR):/data:ro" -w /data cytopia/jsonlint:$(JL_VERSION) \
-t ' ' -i '$(JL_IGNORES)' '*.json'; then \
echo "OK"; \
else \
echo "Failed"; \
exit 1; \
fi;
@echo
.PHONY: lint-bash
lint-bash: _lint-bash-pull
lint-bash:
@echo "################################################################################"
@echo "# Lint Bash"
@echo "################################################################################"
@IGNORES=""; \
if [ "$(SC_IGNORES)" ]; then \
IGNORES="$$( echo "-not \( -path \"./$(SC_IGNORES)*\"" | sed 's|,|*" -o -path "./|g' ) \)"; \
fi; \
CMD="find . -name '*.sh' $${IGNORES} -print0"; \
echo "$${CMD}"; \
if [ "$$( eval "$${CMD}" )" != "" ]; then \
eval "$${CMD}" | xargs -0 -n1 docker run --rm -v $(CURRENT_DIR):/data -w /data koalaman/shellcheck:$(SC_VERSION) --shell=bash; \
fi
# -------------------------------------------------------------------------------------------------
# Helper Targets
# -------------------------------------------------------------------------------------------------
.PHONY: _lint-files-pull
_lint-files-pull:
@echo "Pulling cytopia/file-lint:$(FL_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q cytopia/file-lint:$(FL_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
.PHONY: _lint-yaml-pull
_lint-yaml-pull:
@echo "Pulling cytopia/yamllint:$(YL_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q cytopia/yamllint:$(YL_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
.PHONY: _lint-json-pull
_lint-json-pull:
@echo "Pulling cytopia/jsonlint:$(JL_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q cytopia/jsonlint:$(JL_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;
.PHONY: _lint-bash-pull
_lint-bash-pull:
@echo "Pulling koalaman/shellcheck:$(SC_VERSION)"; \
SUCC=0; \
for i in $$(seq 10); do \
if docker pull -q koalaman/shellcheck:$(SC_VERSION); then \
SUCC=1; \
break; \
fi; \
sleep 1; \
done; \
if [ "$${SUCC}" = "0" ]; then echo "FAILED"; exit 1; fi;