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
31 (re.compile(r'.*[^sS]://github\.com/.*'),
32 "github URLs should always use https:// not http://"),
33 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
34 "code.google.com URLs should always use https:// not http://"),
37 (re.compile(r'.*[^sS]://github\.com/.*'),
38 "github URLs should always use https:// (not http://, git://, or git@)"),
39 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
40 "/source is missing"),
41 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
42 "code.google.com URLs should always use https:// not http://"),
43 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
44 "dl.google.com URLs should always use https:// not http://"),
45 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
46 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
49 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
50 "code.google.com URLs should always use https:// not http://"),
51 (re.compile(r'.*[^sS]://dl\.google\.com/.*'),
52 "dl.google.com URLs should always use https:// not http://"),
53 (re.compile(r'.*[^sS]://github\.com/.*'),
54 "github URLs should always use https:// (not http://, git://, or git@)"),
55 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
56 "gitorious URLs should always use https:// (not http://, git://, or git@)"),
57 (re.compile(r'.*[^sS]://[^.]*\.googlecode\.com/svn/?.*'),
58 "Google Code SVN URLs should always use https:// (not http:// or svn://)"),
59 (re.compile(r'.*[^sS]://svn\.apache\.org/repos/?.*'),
60 "Apache SVN URLs should always use https:// (not http:// or svn://)"),
61 (re.compile(r'.*[^sS]://svn\.code\.sf\.net/.*'),
62 "Sourceforge SVN URLs should always use https:// (not http:// or svn://)"),
65 (re.compile(r'.*code\.google\.com/p/[^/]+[/]*$'),
66 "/issues is missing"),
67 (re.compile(r'.*[^sS]://code\.google\.com/.*'),
68 "code.google.com URLs should always use https:// not http://"),
69 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
70 "/issues is missing"),
71 (re.compile(r'.*[^sS]://github\.com/.*'),
72 "github URLs should always use https:// not http://"),
73 (re.compile(r'.*[^sS]://gitorious\.org/.*'),
74 "gitorious URLs should always use https:// not http://"),
77 (re.compile(r'^No description available$'),
78 "Description yet to be filled"),
79 (re.compile(r'[ ]*[*#][^ .]'),
80 "Invalid bulleted list"),
82 "Unnecessary leading space"),
88 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
89 "Appending .git is not necessary"),
90 (re.compile(r'.*code\.google\.com/p/[^/]+/[^w]'),
91 "Possible incorrect path appended to google code project site"),
94 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
95 "Appending .git is not necessary"),
96 (re.compile(r'.*code\.google\.com/p/[^/]+/source/.*'),
97 "/source is often enough on its own"),
100 (re.compile(r'^http://.*'),
101 "if https:// is available, use it instead of http://"),
102 (re.compile(r'^svn://.*'),
103 "if https:// is available, use it instead of svn://"),
106 (re.compile(r'.*code\.google\.com/p/[^/]+/issues/.*'),
107 "/issues is often enough on its own"),
108 (re.compile(r'.*github\.com/[^/]+/[^/]+/issues/.*'),
109 "/issues is often enough on its own"),
112 (re.compile(r'^[a-z]'),
113 "No capitalization was done"),
114 (re.compile(r'.*\bandroid\b.*', re.IGNORECASE),
115 "No need to specify that the app is for Android"),
116 (re.compile(r'.*\b(app|application)\b.*', re.IGNORECASE),
117 "No need to specify that the app is... an app"),
118 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
119 "No need to specify that the app is Free Software"),
120 (re.compile(r'.*[a-z0-9][.,!?][ $]'),
121 "Punctuation should be avoided"),
128 global config, options, appid, app_count, warn_count
135 global appid, app_count, warn_count
140 print ' %s' % message
147 # Parse command line...
148 parser = OptionParser(usage="Usage: %prog [options] [APPID [APPID ...]]")
149 parser.add_option("-p", "--pedantic", action="store_true", default=False,
150 help="Show pedantic warnings that might give false positives")
151 parser.add_option("-v", "--verbose", action="store_true", default=False,
152 help="Spew out even more information than normal")
153 (options, args) = parser.parse_args()
155 config = common.read_config(options)
158 allapps = metadata.read_metadata(xref=False)
159 apps = common.read_app_args(args, allapps, False)
168 for build in app['builds']:
169 if 'commit' in build and 'disable' not in build:
170 lastcommit = build['commit']
172 # Potentially incorrect UCM
173 if (app['Update Check Mode'] == 'RepoManifest' and
174 any(s in lastcommit for s in '.,_-/')):
175 pwarn("Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
176 lastcommit, app['Update Check Mode']))
179 if app['License'] in ('Unknown', 'None', ''):
180 warn("License was not set")
183 summ_chars = len(app['Summary'])
184 if summ_chars > config['char_limits']['Summary']:
185 warn("Summary of length %s is over the %i char limit" % (
186 summ_chars, config['char_limits']['Summary']))
188 # Redundant summaries
189 summary = app['Summary']
190 name = str(app['Name'] if app['Name'] else app['Auto Name'])
192 summary_l = summary.lower()
193 name_l = name.lower()
194 if summary_l == name_l:
195 warn("Summary '%s' is just the app's name" % summary)
196 elif (summary_l in name_l or name_l in summary_l):
197 pwarn("Summary '%s' probably contains redundant info already in app name '%s'" % (
200 # Description size limit
201 desc_chars = sum(len(l) for l in app['Description'])
202 if desc_chars > config['char_limits']['Description']:
203 warn("Description of length %s is over the %i char limit" % (
204 desc_chars, config['char_limits']['Description']))
206 # Regex checks in all kinds of fields
207 for f in regex_warnings:
208 for m, r in regex_warnings[f]:
209 t = metadata.metafieldtype(f)
212 warn("%s '%s': %s" % (f, app[f], r))
213 elif t == 'multiline':
216 warn("%s at line '%s': %s" % (f, l, r))
218 # Regex pedantic checks in all kinds of fields
220 for f in regex_pedantic:
221 for m, r in regex_pedantic[f]:
223 warn("%s '%s': %s" % (f, app[f], r))
226 for build in app['builds']:
227 for n in ['master', 'origin/', 'default', 'trunk']:
228 if 'commit' in build:
229 if build['commit'].startswith(n):
230 warn("Branch '%s' used as commit in build '%s'" % (
231 n, build['version']))
232 if 'srclibs' in build:
233 for srclib in build['srclibs']:
234 ref = srclib.split('@')[1].split('/')[0]
235 if ref.startswith(n):
236 warn("Branch '%s' used as commit in srclib '%s'" % (
242 logging.info("Found a total of %i warnings in %i apps." % (warn_count, app_count))
244 if __name__ == "__main__":