about summary refs log tree commit diff
path: root/xlint
blob: 89809ef981ba4d492b09a188277102dc00dcd9e6 (plain) (blame)
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
#!/bin/sh
# xlint TEMPLATE - scan XBPS template for common mistakes

export LC_ALL=C

scan() {
	local rx="$1" msg="$2"
	grep -P -Hn -e "$rx" "$template" |
		sed "s/^\([^:]*:[^:]*:\)\(.*\)/\1 $msg/"
}

once() {
	head -n 1
}

variables=$(echo -n "#.*
_.*
.*_descr
.*_homedir
.*_groups
.*_shell
CFLAGS
CPPFLAGS
CXXFLAGS
LDFLAGS
XBPS_FETCH_COMMAND
bootstrap
broken
build_options
build_style
build_wrksrc
checksum
conf_files
configure_args
configure_script
conflicts
create_wrksrc
depends
desc_option_.*
disable_debug
disable_parallel_build
distfiles
dkms_modules
force_debug_pkgs
font_dirs
homepage
hostmakedepends
keep_libtool_archives
lib32disabled
lib32mode
license
maintainer
make_build_args
make_build_target
make_dirs
make_install_args
make_install_target
makedepends
mutable_files
noarch
nocross
nostrip
nostrip_files
noverifyrdeps
only_for_archs
patch_args
pkgname
provides
pycompile_dirs
pycompile_module
pycompile_version
python_versions
register_shell
replaces
repository
reverts
revision
sgml_entries
short_desc
skip_extraction
subpackages
system_accounts
system_groups
systemd_services
triggers
update_ignore
update_pattern
update_pkgname
update_site
version
wrksrc
xml_entries" | tr '\n' '|')

ret=0
for template; do
	if [ -f "$template" ]; then
	scan 'short_desc=.*\."' "unwanted trailing dot in short_desc"
	scan 'short_desc=["'\''][a-z]' "short_desc should start uppercase"
	scan 'short_desc=["'\''].{72}' "short_desc should be less than 72 chars"
	scan 'license=.*[^L]GPL[^-]' "license GPL without version"
	scan 'license=.*LGPL[^-]' "license LGPL without version"
	if ! grep -q vlicense "$template"; then
		scan 'license=.*custom' "license 'custom', but no use of vlicense"
	fi
	scan 'vinstall.* usr/bin' "use vbin"
	scan 'vinstall.* usr/share/man' "use vman"
	scan 'vinstall.* usr/share/licenses' "use vlicense"
	scan '^  ' "indent with tabs" | once
	scan '[\t ]$' "trailing whitespace"
	scan '`' "use \$() instead of backticks"
	scan 'replaces=[^<>]*$' "replaces needs depname with version"
	scan 'conflicts=[^<>]*$' "conflicts needs depname with version"
	scan 'maintainer=(?!.*<.*@.*>).*' "maintainer needs email address"
	scan 'nonfree=' "use repository=nonfree"
	scan '^(?!\s*('"$variables"'))[^\s=-]+=' \
		"custom variables should use _ prefix: \2"
	scan '^[^ =]*=(""|''|)$' "variable set to empty string: \2"
	scan 'distfiles=.*sourceforge\.net' 'use $SOURCEFORGE_SITE'
	scan 'distfiles=.*savannah.nongnu\.org' 'use $NONGNU_SITE'
	scan 'distfiles=.*archive\.ubuntu\.com' 'use $UBUNTU_SITE'
	scan 'distfiles=.*xorg\.freedesktop\.org' 'use $XORG_SITE'
	scan 'distfiles=.*(?<!people\.)debian\.org' 'use $DEBIAN_SITE'
	scan 'distfiles=.*gnome\.org/pub' 'use $GNOME_SITE'
	scan 'distfiles=.*www\.kernel\.org' 'use $KERNEL_SITE'
	scan 'distfiles=.*cpan\.org' 'use $CPAN_SITE'
	scan 'distfiles=.*pypi\.python\.org' 'use $PYPI_SITE'
	scan 'distfiles=.*ftp\.mozilla\.org' 'use $MOZILLA_SITE'
	scan 'distfiles=.*ftp\.gnu\.org/(pub/)?gnu' 'use $GNU_SITE'
	scan 'distfiles=.*freedesktop\.org/software' 'use $FREEDESKTOP_SITE'
	else
	echo no such template "$template" 1>&2
	fi | sort -t: -n -k2 | grep . && ret=1
done
exit $ret