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://")
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")
52 http_url_shorteners = [
53 forbid_shortener('goo.gl'),
54 forbid_shortener('t.co'),
55 forbid_shortener('ur1.ca'),
56 forbid_shortener('is.gd'),
57 forbid_shortener('bit.ly'),
58 forbid_shortener('tiny.cc'),
59 forbid_shortener('tinyurl.com'),
62 http_checks = https_enforcings + http_url_shorteners + [
63 (re.compile(r'.*github\.com/[^/]+/[^/]+\.git'),
64 "Appending .git is not necessary"),
65 (re.compile(r'.*://[^/]*(github|gitlab|bitbucket|rawgit)[^/]*/([^/]+/){1,3}master'),
66 "Use /HEAD instead of /master to point at a file in the default branch"),
70 'WebSite': http_checks,
71 'SourceCode': http_checks,
72 'Repo': https_enforcings,
73 'IssueTracker': http_checks + [
74 (re.compile(r'.*github\.com/[^/]+/[^/]+/*$'),
75 "/issues is missing"),
76 (re.compile(r'.*gitlab\.com/[^/]+/[^/]+/*$'),
77 "/issues is missing"),
79 'Donate': http_checks + [
80 (re.compile(r'.*flattr\.com'),
81 "Flattr donation methods belong in the FlattrID flag"),
83 'Changelog': http_checks,
86 "Unnecessary leading space"),
87 (re.compile(r'.*\s$'),
88 "Unnecessary trailing space"),
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'\s*[*#][^ .]'),
104 "Invalid bulleted list"),
106 "Unnecessary leading space"),
107 (re.compile(r'.*\s$'),
108 "Unnecessary trailing space"),
109 (re.compile(r'.*([^[]|^)\[[^:[\]]+( |\]|$)'),
110 "Invalid link - use [http://foo.bar Link title] or [http://foo.bar]"),
111 (re.compile(r'(^|.* )https?://[^ ]+'),
112 "Unlinkified link - use [http://foo.bar Link title] or [http://foo.bar]"),
116 locale_pattern = re.compile(r'^[a-z]{2,3}(-[A-Z][A-Z])?$')
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.versionCode)
141 if lowest_vercode == -1 or vercode < lowest_vercode:
142 lowest_vercode = vercode
143 if not lastbuild or int(build.versionCode) > int(lastbuild.versionCode):
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.versionCode == 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 ['WebSite', 'SourceCode', 'IssueTracker', '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"
195 filling_ucms = re.compile(r'^(Tags.*|RepoManifest.*)')
198 def check_checkupdates_ran(app):
199 if filling_ucms.match(app.UpdateCheckMode):
200 if not app.AutoName and not app.CurrentVersion and app.CurrentVersionCode == '0':
201 yield "UCM is set but it looks like checkupdates hasn't been run yet"
204 def check_empty_fields(app):
205 if not app.Categories:
206 yield "Categories are not set"
209 all_categories = set([
220 "Science & Education",
230 def check_categories(app):
231 for categ in app.Categories:
232 if categ not in all_categories:
233 yield "Category '%s' is not valid" % categ
236 def check_duplicates(app):
237 if app.Name and app.Name == app.AutoName:
238 yield "Name '%s' is just the auto name - remove it" % app.Name
241 for f in ['Source Code', 'Web Site', 'Issue Tracker', 'Changelog']:
247 yield "Duplicate link in '%s': %s" % (f, v)
251 name = app.Name or app.AutoName
252 if app.Summary and name:
253 if app.Summary.lower() == name.lower():
254 yield "Summary '%s' is just the app's name" % app.Summary
256 if app.Summary and app.Description and len(app.Description) == 1:
257 if app.Summary.lower() == app.Description[0].lower():
258 yield "Description '%s' is just the app's summary" % app.Summary
261 for l in app.Description.splitlines():
265 yield "Description has a duplicate line"
269 desc_url = re.compile(r'(^|[^[])\[([^ ]+)( |\]|$)')
272 def check_mediawiki_links(app):
273 wholedesc = ' '.join(app.Description)
274 for um in desc_url.finditer(wholedesc):
276 for m, r in http_checks:
278 yield "URL '%s' in Description: %s" % (url, r)
281 def check_bulleted_lists(app):
282 validchars = ['*', '#']
285 for l in app.Description.splitlines():
290 if l[0] == lchar and l[1] == ' ':
292 if lcount > 2 and lchar not in validchars:
293 yield "Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar
300 def check_builds(app):
301 for build in app.builds:
303 if build.disable.startswith('Generated by import.py'):
304 yield "Build generated by `fdroid import` - remove disable line once ready"
306 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
307 if build.commit and build.commit.startswith(s):
308 yield "Branch '%s' used as commit in build '%s'" % (s, build.versionName)
309 for srclib in build.srclibs:
310 ref = srclib.split('@')[1].split('/')[0]
311 if ref.startswith(s):
312 yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
315 def check_files_dir(app):
316 dir_path = os.path.join('metadata', app.id)
317 if not os.path.isdir(dir_path):
320 for name in os.listdir(dir_path):
321 path = os.path.join(dir_path, name)
322 if not (os.path.isfile(path) or name == 'signatures' or locale_pattern.match(name)):
323 yield "Found non-file at %s" % path
327 used = {'signatures', }
328 for build in app.builds:
329 for fname in build.patch:
330 if fname not in files:
331 yield "Unknown file %s in build '%s'" % (fname, build.versionName)
335 for name in files.difference(used):
336 if locale_pattern.match(name):
338 yield "Unused file at %s" % os.path.join(dir_path, name)
341 def check_format(app):
342 if options.format and not rewritemeta.proper_format(app):
343 yield "Run rewritemeta to fix formatting"
346 def check_license_tag(app):
347 '''Ensure all license tags are in https://spdx.org/license-list'''
348 if app.License.rstrip('+') not in SPDX:
349 yield 'Invalid license tag "%s"! Use only tags from https://spdx.org/license-list' \
353 def check_extlib_dir(apps):
354 dir_path = os.path.join('build', 'extlib')
356 for root, dirs, names in os.walk(dir_path):
358 files.add(os.path.join(root, name)[len(dir_path) + 1:])
362 for build in app.builds:
363 for path in build.extlibs:
364 if path not in files:
365 yield "%s: Unknown extlib %s in build '%s'" % (app.id, path, build.versionName)
369 for path in files.difference(used):
370 if any(path.endswith(s) for s in [
372 'source.txt', 'origin.txt', 'md5.txt',
373 'LICENSE', 'LICENSE.txt',
374 'COPYING', 'COPYING.txt',
375 'NOTICE', 'NOTICE.txt',
378 yield "Unused extlib at %s" % os.path.join(dir_path, path)
383 global config, options
385 # Parse command line...
386 parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
387 common.setup_global_opts(parser)
388 parser.add_argument("-f", "--format", action="store_true", default=False,
389 help="Also warn about formatting issues, like rewritemeta -l")
390 parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
391 metadata.add_metadata_arguments(parser)
392 options = parser.parse_args()
393 metadata.warnings_action = options.W
395 config = common.read_config(options)
398 allapps = metadata.read_metadata(xref=True)
399 apps = common.read_app_args(options.appid, allapps, False)
403 apps_check_funcs = []
404 if len(options.appid) == 0:
405 # otherwise it finds tons of unused extlibs
406 apps_check_funcs.append(check_extlib_dir)
407 for check_func in apps_check_funcs:
408 for warn in check_func(apps.values()):
412 for appid, app in apps.items():
421 check_checkupdates_ran,
422 check_useless_fields,
426 check_mediawiki_links,
427 check_bulleted_lists,
434 for check_func in app_check_funcs:
435 for warn in check_func(app):
437 print("%s: %s" % (appid, warn))
443 # A compiled, public domain list of official SPDX license tags from:
444 # https://github.com/sindresorhus/spdx-license-list/blob/v3.0.1/spdx-simple.json
445 # The deprecated license tags have been removed from the list, they are at the
446 # bottom, starting after the last license tags that start with Z.
447 # This is at the bottom, since its a long list of data
449 "PublicDomain", # an F-Droid addition, until we can enforce a better option
489 "BSD-2-Clause-FreeBSD",
490 "BSD-2-Clause-NetBSD",
492 "BSD-3-Clause-Clear",
493 "BSD-3-Clause-No-Nuclear-License",
494 "BSD-3-Clause-No-Nuclear-License-2014",
495 "BSD-3-Clause-No-Nuclear-Warranty",
499 "BSD-3-Clause-Attribution",
515 "CNRI-Python-GPL-Compatible",
649 "MPL-2.0-no-copyleft-exception",
773 "zlib-acknowledgement",
779 if __name__ == "__main__":