3 # lint.py - part of the FDroid server tool
4 # Copyright (C) 2013-2014 Daniel Martà <mvdan@mvdan.cc>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See th
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public Licen
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from argparse import ArgumentParser
25 from . import metadata
26 from . import rewritemeta
32 def enforce_https(domain):
33 return (re.compile(r'.*[^sS]://[^/]*' + re.escape(domain) + r'(/.*)?'),
34 domain + " URLs should always use https://")
37 enforce_https('github.com'),
38 enforce_https('gitlab.com'),
39 enforce_https('bitbucket.org'),
40 enforce_https('apache.org'),
41 enforce_https('google.com'),
42 enforce_https('svn.code.sf.net'),
46 def forbid_shortener(domain):
47 return (re.compile(r'https?://[^/]*' + re.escape(domain) + r'/.*'),
48 "URL shorteners should not be used")
50 http_url_shorteners = [
51 forbid_shortener('goo.gl'),
52 forbid_shortener('t.co'),
53 forbid_shortener('ur1.ca'),
56 http_checks = https_enforcings + http_url_shorteners + [
57 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
58 "Appending .git is not necessary"),
59 (re.compile(r'.*://[^/]*(github|gitlab|bitbucket|rawgit)[^/]*/([^/]+/){1,3}master'),
60 "Use /HEAD instead of /master to point at a file in the default branch"),
64 'Web Site': http_checks,
65 'Source Code': http_checks,
66 'Repo': https_enforcings,
67 'Issue Tracker': http_checks + [
68 (re.compile(r'.*github\.com/[^/]+/[^/]+/*$'),
69 "/issues is missing"),
70 (re.compile(r'.*gitlab\.com/[^/]+/[^/]+/*$'),
71 "/issues is missing"),
73 'Donate': http_checks + [
74 (re.compile(r'.*flattr\.com'),
75 "Flattr donation methods belong in the FlattrID flag"),
77 'Changelog': http_checks,
80 "Unnecessary leading space"),
81 (re.compile(r'.*\s$'),
82 "Unnecessary trailing space"),
85 (re.compile(r'^(|None|Unknown)$'),
86 "No license specified"),
90 "Summary yet to be filled"),
91 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
92 "No need to specify that the app is Free Software"),
93 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
94 "No need to specify that the app is for Android"),
95 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
96 "Punctuation should be avoided"),
98 "Unnecessary leading space"),
99 (re.compile(r'.*\s$'),
100 "Unnecessary trailing space"),
103 (re.compile(r'^No description available$'),
104 "Description yet to be filled"),
105 (re.compile(r'\s*[*#][^ .]'),
106 "Invalid bulleted list"),
108 "Unnecessary leading space"),
109 (re.compile(r'.*\s$'),
110 "Unnecessary trailing space"),
111 (re.compile(r'.*([^[]|^)\[[^:[\]]+( |\]|$)'),
112 "Invalid link - use [http://foo.bar Link title] or [http://foo.bar]"),
113 (re.compile(r'(^|.* )https?://[^ ]+'),
114 "Unlinkified link - use [http://foo.bar Link title] or [http://foo.bar]"),
119 def check_regexes(app):
120 for f, checks in regex_checks.items():
123 t = metadata.fieldtype(f)
124 if t == metadata.TYPE_MULTILINE:
125 for l in v.splitlines():
127 yield "%s at line '%s': %s" % (f, l, r)
132 yield "%s '%s': %s" % (f, v, r)
135 def get_lastbuild(builds):
139 if not build.disable:
140 vercode = int(build.vercode)
141 if lowest_vercode == -1 or vercode < lowest_vercode:
142 lowest_vercode = vercode
143 if not lastbuild or int(build.vercode) > int(lastbuild.vercode):
148 def check_ucm_tags(app):
149 lastbuild = get_lastbuild(app.builds)
150 if (lastbuild is not None
152 and app.UpdateCheckMode == 'RepoManifest'
153 and not lastbuild.commit.startswith('unknown')
154 and lastbuild.vercode == app.CurrentVersionCode
155 and not lastbuild.forcevercode
156 and any(s in lastbuild.commit for s in '.,_-/')):
157 yield "Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
158 lastbuild.commit, app.UpdateCheckMode)
161 def check_char_limits(app):
162 limits = config['char_limits']
164 if len(app.Summary) > limits['Summary']:
165 yield "Summary of length %s is over the %i char limit" % (
166 len(app.Summary), limits['Summary'])
168 if len(app.Description) > limits['Description']:
169 yield "Description of length %s is over the %i char limit" % (
170 len(app.Description), limits['Description'])
173 def check_old_links(app):
183 if any(s in app.Repo for s in usual_sites):
184 for f in ['Web Site', 'Source Code', 'Issue Tracker', 'Changelog']:
186 if any(s in v for s in old_sites):
187 yield "App is in '%s' but has a link to '%s'" % (app.Repo, v)
190 def check_useless_fields(app):
191 if app.UpdateCheckName == app.id:
192 yield "Update Check Name is set to the known app id - it can be removed"
194 filling_ucms = re.compile(r'^(Tags.*|RepoManifest.*)')
197 def check_checkupdates_ran(app):
198 if filling_ucms.match(app.UpdateCheckMode):
199 if not app.AutoName and not app.CurrentVersion and app.CurrentVersionCode == '0':
200 yield "UCM is set but it looks like checkupdates hasn't been run yet"
203 def check_empty_fields(app):
204 if not app.Categories:
205 yield "Categories are not set"
207 all_categories = set([
218 "Science & Education",
228 def check_categories(app):
229 for categ in app.Categories:
230 if categ not in all_categories:
231 yield "Category '%s' is not valid" % categ
234 def check_duplicates(app):
235 if app.Name and app.Name == app.AutoName:
236 yield "Name '%s' is just the auto name - remove it" % app.Name
239 for f in ['Source Code', 'Web Site', 'Issue Tracker', 'Changelog']:
245 yield "Duplicate link in '%s': %s" % (f, v)
249 name = app.Name or app.AutoName
250 if app.Summary and name:
251 if app.Summary.lower() == name.lower():
252 yield "Summary '%s' is just the app's name" % app.Summary
254 if app.Summary and app.Description and len(app.Description) == 1:
255 if app.Summary.lower() == app.Description[0].lower():
256 yield "Description '%s' is just the app's summary" % app.Summary
259 for l in app.Description.splitlines():
263 yield "Description has a duplicate line"
267 desc_url = re.compile(r'(^|[^[])\[([^ ]+)( |\]|$)')
270 def check_mediawiki_links(app):
271 wholedesc = ' '.join(app.Description)
272 for um in desc_url.finditer(wholedesc):
274 for m, r in http_checks:
276 yield "URL '%s' in Description: %s" % (url, r)
279 def check_bulleted_lists(app):
280 validchars = ['*', '#']
283 for l in app.Description.splitlines():
288 if l[0] == lchar and l[1] == ' ':
290 if lcount > 2 and lchar not in validchars:
291 yield "Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar
298 def check_builds(app):
299 for build in app.builds:
301 if build.disable.startswith('Generated by import.py'):
302 yield "Build generated by `fdroid import` - remove disable line once ready"
304 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
305 if build.commit and build.commit.startswith(s):
306 yield "Branch '%s' used as commit in build '%s'" % (s, build.version)
307 for srclib in build.srclibs:
308 ref = srclib.split('@')[1].split('/')[0]
309 if ref.startswith(s):
310 yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
313 def check_files_dir(app):
314 dir_path = os.path.join('metadata', app.id)
315 if not os.path.isdir(dir_path):
318 for name in os.listdir(dir_path):
319 path = os.path.join(dir_path, name)
320 if not os.path.isfile(path):
321 yield "Found non-file at %s" % path
326 for build in app.builds:
327 for fname in build.patch:
328 if fname not in files:
329 yield "Unknown file %s in build '%s'" % (fname, build.version)
333 for name in files.difference(used):
334 yield "Unused file at %s" % os.path.join(dir_path, name)
337 def check_format(app):
338 if options.format and not rewritemeta.proper_format(app):
339 yield "Run rewritemeta to fix formatting"
342 def check_extlib_dir(apps):
343 dir_path = os.path.join('build', 'extlib')
345 for root, dirs, names in os.walk(dir_path):
347 files.add(os.path.join(root, name)[len(dir_path) + 1:])
351 for build in app.builds:
352 for path in build.extlibs:
353 if path not in files:
354 yield "%s: Unknown extlib %s in build '%s'" % (app.id, path, build.version)
358 for path in files.difference(used):
359 if any(path.endswith(s) for s in [
361 'source.txt', 'origin.txt', 'md5.txt',
362 'LICENSE', 'LICENSE.txt',
363 'COPYING', 'COPYING.txt',
364 'NOTICE', 'NOTICE.txt',
367 yield "Unused extlib at %s" % os.path.join(dir_path, path)
372 global config, options
374 # Parse command line...
375 parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
376 common.setup_global_opts(parser)
377 parser.add_argument("-f", "--format", action="store_true", default=False,
378 help="Also warn about formatting issues, like rewritemeta -l")
379 parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
380 options = parser.parse_args()
382 config = common.read_config(options)
385 allapps = metadata.read_metadata(xref=True)
386 apps = common.read_app_args(options.appid, allapps, False)
390 apps_check_funcs = []
391 if len(options.appid) == 0:
392 # otherwise it finds tons of unused extlibs
393 apps_check_funcs.append(check_extlib_dir)
394 for check_func in apps_check_funcs:
395 for warn in check_func(apps.values()):
399 for appid, app in apps.items():
408 check_checkupdates_ran,
409 check_useless_fields,
413 check_mediawiki_links,
414 check_bulleted_lists,
420 for check_func in app_check_funcs:
421 for warn in check_func(app):
423 print("%s: %s" % (appid, warn))
429 if __name__ == "__main__":