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"),
92 "Summary yet to be filled"),
93 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
94 "No need to specify that the app is Free Software"),
95 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
96 "No need to specify that the app is for Android"),
97 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
98 "Punctuation should be avoided"),
100 "Unnecessary leading space"),
101 (re.compile(r'.*\s$'),
102 "Unnecessary trailing space"),
105 (re.compile(r'^No description available$'),
106 "Description yet to be filled"),
107 (re.compile(r'\s*[*#][^ .]'),
108 "Invalid bulleted list"),
110 "Unnecessary leading space"),
111 (re.compile(r'.*\s$'),
112 "Unnecessary trailing space"),
113 (re.compile(r'.*([^[]|^)\[[^:[\]]+( |\]|$)'),
114 "Invalid link - use [http://foo.bar Link title] or [http://foo.bar]"),
115 (re.compile(r'(^|.* )https?://[^ ]+'),
116 "Unlinkified link - use [http://foo.bar Link title] or [http://foo.bar]"),
120 locale_pattern = re.compile(r'^[a-z]{2,3}(-[A-Z][A-Z])?$')
123 def check_regexes(app):
124 for f, checks in regex_checks.items():
127 t = metadata.fieldtype(f)
128 if t == metadata.TYPE_MULTILINE:
129 for l in v.splitlines():
131 yield "%s at line '%s': %s" % (f, l, r)
136 yield "%s '%s': %s" % (f, v, r)
139 def get_lastbuild(builds):
143 if not build.disable:
144 vercode = int(build.versionCode)
145 if lowest_vercode == -1 or vercode < lowest_vercode:
146 lowest_vercode = vercode
147 if not lastbuild or int(build.versionCode) > int(lastbuild.versionCode):
152 def check_ucm_tags(app):
153 lastbuild = get_lastbuild(app.builds)
154 if (lastbuild is not None
156 and app.UpdateCheckMode == 'RepoManifest'
157 and not lastbuild.commit.startswith('unknown')
158 and lastbuild.versionCode == app.CurrentVersionCode
159 and not lastbuild.forcevercode
160 and any(s in lastbuild.commit for s in '.,_-/')):
161 yield "Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
162 lastbuild.commit, app.UpdateCheckMode)
165 def check_char_limits(app):
166 limits = config['char_limits']
168 if len(app.Summary) > limits['summary']:
169 yield "Summary of length %s is over the %i char limit" % (
170 len(app.Summary), limits['summary'])
172 if len(app.Description) > limits['description']:
173 yield "Description of length %s is over the %i char limit" % (
174 len(app.Description), limits['description'])
177 def check_old_links(app):
187 if any(s in app.Repo for s in usual_sites):
188 for f in ['WebSite', 'SourceCode', 'IssueTracker', 'Changelog']:
190 if any(s in v for s in old_sites):
191 yield "App is in '%s' but has a link to '%s'" % (app.Repo, v)
194 def check_useless_fields(app):
195 if app.UpdateCheckName == app.id:
196 yield "Update Check Name is set to the known app id - it can be removed"
199 filling_ucms = re.compile(r'^(Tags.*|RepoManifest.*)')
202 def check_checkupdates_ran(app):
203 if filling_ucms.match(app.UpdateCheckMode):
204 if not app.AutoName and not app.CurrentVersion and app.CurrentVersionCode == '0':
205 yield "UCM is set but it looks like checkupdates hasn't been run yet"
208 def check_empty_fields(app):
209 if not app.Categories:
210 yield "Categories are not set"
213 all_categories = set([
224 "Science & Education",
234 def check_categories(app):
235 for categ in app.Categories:
236 if categ not in all_categories:
237 yield "Category '%s' is not valid" % categ
240 def check_duplicates(app):
241 if app.Name and app.Name == app.AutoName:
242 yield "Name '%s' is just the auto name - remove it" % app.Name
245 for f in ['Source Code', 'Web Site', 'Issue Tracker', 'Changelog']:
251 yield "Duplicate link in '%s': %s" % (f, v)
255 name = app.Name or app.AutoName
256 if app.Summary and name:
257 if app.Summary.lower() == name.lower():
258 yield "Summary '%s' is just the app's name" % app.Summary
260 if app.Summary and app.Description and len(app.Description) == 1:
261 if app.Summary.lower() == app.Description[0].lower():
262 yield "Description '%s' is just the app's summary" % app.Summary
265 for l in app.Description.splitlines():
269 yield "Description has a duplicate line"
273 desc_url = re.compile(r'(^|[^[])\[([^ ]+)( |\]|$)')
276 def check_mediawiki_links(app):
277 wholedesc = ' '.join(app.Description)
278 for um in desc_url.finditer(wholedesc):
280 for m, r in http_checks:
282 yield "URL '%s' in Description: %s" % (url, r)
285 def check_bulleted_lists(app):
286 validchars = ['*', '#']
289 for l in app.Description.splitlines():
294 if l[0] == lchar and l[1] == ' ':
296 if lcount > 2 and lchar not in validchars:
297 yield "Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar
304 def check_builds(app):
305 for build in app.builds:
307 if build.disable.startswith('Generated by import.py'):
308 yield "Build generated by `fdroid import` - remove disable line once ready"
310 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
311 if build.commit and build.commit.startswith(s):
312 yield "Branch '%s' used as commit in build '%s'" % (s, build.versionName)
313 for srclib in build.srclibs:
314 ref = srclib.split('@')[1].split('/')[0]
315 if ref.startswith(s):
316 yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
319 def check_files_dir(app):
320 dir_path = os.path.join('metadata', app.id)
321 if not os.path.isdir(dir_path):
324 for name in os.listdir(dir_path):
325 path = os.path.join(dir_path, name)
326 if not (os.path.isfile(path) or name == 'signatures' or locale_pattern.match(name)):
327 yield "Found non-file at %s" % path
331 used = {'signatures', }
332 for build in app.builds:
333 for fname in build.patch:
334 if fname not in files:
335 yield "Unknown file %s in build '%s'" % (fname, build.versionName)
339 for name in files.difference(used):
340 if locale_pattern.match(name):
342 yield "Unused file at %s" % os.path.join(dir_path, name)
345 def check_format(app):
346 if options.format and not rewritemeta.proper_format(app):
347 yield "Run rewritemeta to fix formatting"
350 def check_license_tag(app):
351 '''Ensure all license tags are in https://spdx.org/license-list'''
352 if app.License.rstrip('+') not in SPDX:
353 yield 'Invalid license tag "%s"! Use only tags from https://spdx.org/license-list' \
357 def check_extlib_dir(apps):
358 dir_path = os.path.join('build', 'extlib')
360 for root, dirs, names in os.walk(dir_path):
362 files.add(os.path.join(root, name)[len(dir_path) + 1:])
366 for build in app.builds:
367 for path in build.extlibs:
368 if path not in files:
369 yield "%s: Unknown extlib %s in build '%s'" % (app.id, path, build.versionName)
373 for path in files.difference(used):
374 if any(path.endswith(s) for s in [
376 'source.txt', 'origin.txt', 'md5.txt',
377 'LICENSE', 'LICENSE.txt',
378 'COPYING', 'COPYING.txt',
379 'NOTICE', 'NOTICE.txt',
382 yield "Unused extlib at %s" % os.path.join(dir_path, path)
387 global config, options
389 # Parse command line...
390 parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
391 common.setup_global_opts(parser)
392 parser.add_argument("-f", "--format", action="store_true", default=False,
393 help="Also warn about formatting issues, like rewritemeta -l")
394 parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
395 metadata.add_metadata_arguments(parser)
396 options = parser.parse_args()
397 metadata.warnings_action = options.W
399 config = common.read_config(options)
402 allapps = metadata.read_metadata(xref=True)
403 apps = common.read_app_args(options.appid, allapps, False)
407 apps_check_funcs = []
408 if len(options.appid) == 0:
409 # otherwise it finds tons of unused extlibs
410 apps_check_funcs.append(check_extlib_dir)
411 for check_func in apps_check_funcs:
412 for warn in check_func(apps.values()):
416 for appid, app in apps.items():
425 check_checkupdates_ran,
426 check_useless_fields,
430 check_mediawiki_links,
431 check_bulleted_lists,
438 for check_func in app_check_funcs:
439 for warn in check_func(app):
441 print("%s: %s" % (appid, warn))
447 # A compiled, public domain list of official SPDX license tags from:
448 # https://github.com/sindresorhus/spdx-license-list/blob/v3.0.1/spdx-simple.json
449 # The deprecated license tags have been removed from the list, they are at the
450 # bottom, starting after the last license tags that start with Z.
451 # This is at the bottom, since its a long list of data
453 "PublicDomain", # an F-Droid addition, until we can enforce a better option
493 "BSD-2-Clause-FreeBSD",
494 "BSD-2-Clause-NetBSD",
496 "BSD-3-Clause-Clear",
497 "BSD-3-Clause-No-Nuclear-License",
498 "BSD-3-Clause-No-Nuclear-License-2014",
499 "BSD-3-Clause-No-Nuclear-Warranty",
503 "BSD-3-Clause-Attribution",
519 "CNRI-Python-GPL-Compatible",
653 "MPL-2.0-no-copyleft-exception",
777 "zlib-acknowledgement",
783 if __name__ == "__main__":