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 argparse import ArgumentParser
33 def enforce_https(domain):
34 return (re.compile(r'.*[^sS]://[^/]*' + re.escape(domain) + r'(/.*)?'),
35 domain + " URLs should always use https://")
38 enforce_https('github.com'),
39 enforce_https('gitlab.com'),
40 enforce_https('bitbucket.org'),
41 enforce_https('apache.org'),
42 enforce_https('google.com'),
43 enforce_https('svn.code.sf.net'),
47 def forbid_shortener(domain):
48 return (re.compile(r'https?://[^/]*' + re.escape(domain) + r'/.*'),
49 "URL shorteners should not be used")
51 http_url_shorteners = [
52 forbid_shortener('goo.gl'),
53 forbid_shortener('t.co'),
54 forbid_shortener('ur1.ca'),
57 http_checks = https_enforcings + http_url_shorteners + [
58 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
59 "Appending .git is not necessary"),
60 (re.compile(r'.*://[^/]*(github|gitlab|bitbucket|rawgit)[^/]*/([^/]+/){1,3}master'),
61 "Use /HEAD instead of /master to point at a file in the default branch"),
65 'Web Site': http_checks,
66 'Source Code': http_checks,
67 'Repo': https_enforcings,
68 'Issue Tracker': http_checks + [
69 (re.compile(r'.*github\.com/[^/]+/[^/]+[/]*$'),
70 "/issues is missing"),
72 'Donate': http_checks + [
73 (re.compile(r'.*flattr\.com'),
74 "Flattr donation methods belong in the FlattrID flag"),
76 'Changelog': http_checks,
78 (re.compile(r'^(|None|Unknown)$'),
79 "No license specified"),
83 "Summary yet to be filled"),
84 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
85 "No need to specify that the app is Free Software"),
86 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
87 "No need to specify that the app is for Android"),
88 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
89 "Punctuation should be avoided"),
91 "Unnecessary leading space"),
92 (re.compile(r'.*\s$'),
93 "Unnecessary trailing space"),
96 (re.compile(r'^No description available$'),
97 "Description yet to be filled"),
98 (re.compile(r'\s*[*#][^ .]'),
99 "Invalid bulleted list"),
101 "Unnecessary leading space"),
102 (re.compile(r'.*\s$'),
103 "Unnecessary trailing space"),
104 (re.compile(r'.*([^[]|^)\[[^:[\]]+( |\]|$)'),
105 "Invalid link - use [http://foo.bar Link title] or [http://foo.bar]"),
106 (re.compile(r'(^|.* )https?://[^ ]+'),
107 "Unlinkified link - use [http://foo.bar Link title] or [http://foo.bar]"),
112 def check_regexes(app):
113 for f, checks in regex_checks.iteritems():
116 t = metadata.fieldtype(f)
117 if t == metadata.TYPE_MULTILINE:
118 for l in v.splitlines():
120 yield "%s at line '%s': %s" % (f, l, r)
125 yield "%s '%s': %s" % (f, v, r)
128 def get_lastbuild(builds):
132 if not build.disable:
133 vercode = int(build.vercode)
134 if lowest_vercode == -1 or vercode < lowest_vercode:
135 lowest_vercode = vercode
136 if not lastbuild or int(build.vercode) > int(lastbuild.vercode):
141 def check_ucm_tags(app):
142 lastbuild = get_lastbuild(app.builds)
143 if (lastbuild is not None
145 and app.UpdateCheckMode == 'RepoManifest'
146 and not lastbuild.commit.startswith('unknown')
147 and lastbuild.vercode == app.CurrentVersionCode
148 and not lastbuild.forcevercode
149 and any(s in lastbuild.commit for s in '.,_-/')):
150 yield "Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
151 lastbuild.commit, app.UpdateCheckMode)
154 def check_char_limits(app):
155 limits = config['char_limits']
157 if len(app.Summary) > limits['Summary']:
158 yield "Summary of length %s is over the %i char limit" % (
159 len(app.Summary), limits['Summary'])
161 if len(app.Description) > limits['Description']:
162 yield "Description of length %s is over the %i char limit" % (
163 len(app.Description), limits['Description'])
166 def check_old_links(app):
176 if any(s in app.Repo for s in usual_sites):
177 for f in ['Web Site', 'Source Code', 'Issue Tracker', 'Changelog']:
179 if any(s in v for s in old_sites):
180 yield "App is in '%s' but has a link to '%s'" % (app.Repo, v)
183 def check_useless_fields(app):
184 if app.UpdateCheckName == app.id:
185 yield "Update Check Name is set to the known app id - it can be removed"
187 filling_ucms = re.compile(r'^(Tags.*|RepoManifest.*)')
190 def check_checkupdates_ran(app):
191 if filling_ucms.match(app.UpdateCheckMode):
192 if not app.AutoName and not app.CurrentVersion and app.CurrentVersionCode == '0':
193 yield "UCM is set but it looks like checkupdates hasn't been run yet"
196 def check_empty_fields(app):
197 if not app.Categories:
198 yield "Categories are not set"
200 all_categories = Set([
211 "Science & Education",
221 def check_categories(app):
222 for categ in app.Categories:
223 if categ not in all_categories:
224 yield "Category '%s' is not valid" % categ
227 def check_duplicates(app):
228 if app.Name and app.Name == app.AutoName:
229 yield "Name '%s' is just the auto name - remove it" % app.Name
232 for f in ['Source Code', 'Web Site', 'Issue Tracker', 'Changelog']:
238 yield "Duplicate link in '%s': %s" % (f, v)
242 name = app.Name or app.AutoName
243 if app.Summary and name:
244 if app.Summary.lower() == name.lower():
245 yield "Summary '%s' is just the app's name" % app.Summary
247 if app.Summary and app.Description and len(app.Description) == 1:
248 if app.Summary.lower() == app.Description[0].lower():
249 yield "Description '%s' is just the app's summary" % app.Summary
252 for l in app.Description.splitlines():
256 yield "Description has a duplicate line"
260 desc_url = re.compile(r'(^|[^[])\[([^ ]+)( |\]|$)')
263 def check_mediawiki_links(app):
264 wholedesc = ' '.join(app.Description)
265 for um in desc_url.finditer(wholedesc):
267 for m, r in http_checks:
269 yield "URL '%s' in Description: %s" % (url, r)
272 def check_bulleted_lists(app):
273 validchars = ['*', '#']
276 for l in app.Description.splitlines():
281 if l[0] == lchar and l[1] == ' ':
283 if lcount > 2 and lchar not in validchars:
284 yield "Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar
291 def check_builds(app):
292 for build in app.builds:
295 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
296 if build.commit and build.commit.startswith(s):
297 yield "Branch '%s' used as commit in build '%s'" % (s, build.version)
298 for srclib in build.srclibs:
299 ref = srclib.split('@')[1].split('/')[0]
300 if ref.startswith(s):
301 yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
302 if build.target and build.method() == 'gradle':
303 yield "target= has no gradle support"
308 global config, options
312 # Parse command line...
313 parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
314 common.setup_global_opts(parser)
315 parser.add_argument("-f", "--format", action="store_true", default=False,
316 help="Also warn about formatting issues, like rewritemeta -l")
317 parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
318 options = parser.parse_args()
320 config = common.read_config(options)
323 allapps = metadata.read_metadata(xref=True)
324 apps = common.read_app_args(options.appid, allapps, False)
326 for appid, app in apps.iteritems():
337 check_checkupdates_ran,
338 check_useless_fields,
342 check_mediawiki_links,
343 check_bulleted_lists,
346 warns += check_func(app)
349 if not rewritemeta.proper_format(app):
350 warns.append("Run rewritemeta to fix formatting")
355 print("%s: %s" % (appid, warn))
361 if __name__ == "__main__":