2 # -*- coding: utf-8 -*-
4 # lint.py - part of the FDroid server tool
5 # Copyright (C) 2013-2014 Daniel Martà <mvdan@mvdan.cc>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See th
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public Licen
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from optparse import OptionParser
25 from collections import Counter
32 (re.compile(r'.*[^sS]://github\.com/.*'),
33 "github URLs should always use https:// not http://"),
34 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
35 "code.google.com URLs should always use https:// not http://"),
38 (re.compile(r'.*[^sS]://github\.com/.*'),
39 "github URLs should always use https:// (not http://, git://, or git@)"),
40 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
41 "/source is missing"),
42 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
43 "code.google.com URLs should always use https:// not http://"),
44 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
45 "dl.google.com URLs should always use https:// not http://"),
46 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
47 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
50 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
51 "code.google.com URLs should always use https:// not http://"),
52 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
53 "dl.google.com URLs should always use https:// not http://"),
54 (re.compile(r'.*[^sS]://github\.com/.*'),
55 "github URLs should always use https:// (not http://, git://, or git@)"),
56 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
57 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
58 (re.compile(r'.*[^sS]://[^.]*\.googlecode\.com/svn/?.*'),
59 "Google Code SVN URLs should always use https:// (not http:// or svn://)"),
60 (re.compile(r'.*[^sS]://svn\.apache\.org/repos/?.*'),
61 "Apache SVN URLs should always use https:// (not http:// or svn://)"),
62 (re.compile(r'.*[^sS]://svn\.code\.sf\.net/.*'),
63 "Sourceforge SVN URLs should always use https:// (not http:// or svn://)"),
66 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
67 "/issues is missing"),
68 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
69 "code.google.com URLs should always use https:// not http://"),
70 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
71 "/issues is missing"),
72 (re.compile(r'.*[^sS]://github\.com/.*'),
73 "github URLs should always use https:// not http://"),
74 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
75 "gitorious URLs should always use https:// not http://"),
78 (re.compile(r'^(|None|Unknown)$'),
79 "No license specified"),
82 (re.compile(r'^No description available$'),
83 "Description yet to be filled"),
84 (re.compile(r'[ ]*[*#][^ .]'),
85 "Invalid bulleted list"),
87 "Unnecessary leading space"),
93 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
94 "Appending .git is not necessary"),
95 (re.compile(r'.*code\.google\.com/p/[^/]+/[^w]'),
96 "Possible incorrect path appended to google code project site"),
99 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
100 "Appending .git is not necessary"),
101 (re.compile(r'.*code\.google\.com/p/[^/]+/source/.*'),
102 "/source is often enough on its own"),
105 (re.compile(r'^http://.*'),
106 "use https:// if available"),
107 (re.compile(r'^svn://.*'),
108 "use https:// if available"),
111 (re.compile(r'.*code\.google\.com/p/[^/]+/issues/.*'),
112 "/issues is often enough on its own"),
113 (re.compile(r'.*github\.com/[^/]+/[^/]+/issues/.*'),
114 "/issues is often enough on its own"),
117 (re.compile(r'^[a-z]'),
118 "No capitalization was done"),
119 (re.compile(r'.*\bandroid\b.*', re.IGNORECASE),
120 "No need to specify that the app is for Android"),
121 (re.compile(r'.*\b(app|application)\b.*', re.IGNORECASE),
122 "No need to specify that the app is... an app"),
123 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
124 "No need to specify that the app is Free Software"),
125 (re.compile(r'.*[a-z0-9][.,!?][ $]'),
126 "Punctuation should be avoided"),
133 global config, options, appid, count
144 print ' %s' % message
151 # Parse command line...
152 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
153 parser.add_option("-v", "--verbose", action="store_true", default=False,
154 help="Spew out even more information than normal")
155 parser.add_option("-q", "--quiet", action="store_true", default=False,
156 help="Restrict output to warnings and errors")
157 parser.add_option("-p", "--pedantic", action="store_true", default=False,
158 help="Show pedantic warnings that might give false positives")
159 (options, args) = parser.parse_args()
161 config = common.read_config(options)
164 allapps = metadata.read_metadata(xref=False)
165 apps = common.read_app_args(args, allapps, False)
167 for appid, app in apps.iteritems():
173 for build in app['builds']:
174 if build['commit'] and not build['disable']:
175 lastcommit = build['commit']
177 # Potentially incorrect UCM
178 if (app['Update Check Mode'] == 'RepoManifest' and
179 any(s in lastcommit for s in '.,_-/')):
180 pwarn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
181 lastcommit, app['Update Check Mode']))
184 summ_chars = len(app['Summary'])
185 if summ_chars > config['char_limits']['Summary']:
186 warn("Summary of length %s is over the %i char limit" % (
187 summ_chars, config['char_limits']['Summary']))
189 # Redundant summaries
190 summary = app['Summary']
191 name = app['Name'] or app['Auto Name']
193 summary_l = summary.lower()
194 name_l = name.lower()
195 if summary_l == name_l:
196 warn("Summary '%s' is just the app's name" % summary)
197 elif (summary_l in name_l or name_l in summary_l):
198 pwarn("Summary '%s' probably contains redundant info already in app name '%s'" % (
201 # Description size limit
202 desc_chars = sum(len(l) for l in app['Description'])
203 if desc_chars > config['char_limits']['Description']:
204 warn("Description of length %s is over the %i char limit" % (
205 desc_chars, config['char_limits']['Description']))
207 # Regex checks in all kinds of fields
208 for f in regex_warnings:
209 for m, r in regex_warnings[f]:
210 t = metadata.metafieldtype(f)
213 warn("%s '%s': %s" % (f, app[f], r))
214 elif t == 'multiline':
217 warn("%s at line '%s': %s" % (f, l, r))
219 # Regex pedantic checks in all kinds of fields
221 for f in regex_pedantic:
222 for m, r in regex_pedantic[f]:
224 warn("%s '%s': %s" % (f, app[f], r))
227 for build in app['builds']:
230 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
231 if build['commit'] and build['commit'].startswith(s):
232 warn("Branch '%s' used as commit in build '%s'" % (
233 s, build['version']))
234 for srclib in build['srclibs']:
235 ref = srclib.split('@')[1].split('/')[0]
236 if ref.startswith(s):
237 warn("Branch '%s' used as commit in srclib '%s'" % (
239 for s in ['git clone', 'git svn clone', 'svn checkout', 'svn co', 'hg clone']:
240 for flag in ['init', 'prebuild', 'build']:
244 # TODO: This should not be pedantic!
245 pwarn("'%s' used in %s '%s'" % (s, flag, build[flag]))
250 logging.info("Found a total of %i warnings in %i apps." % (count['warn'], count['app']))
252 if __name__ == "__main__":