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'^(|None|Unknown)$'),
92 "No license specified"),
96 "Summary yet to be filled"),
97 (re.compile(r'.*\b(free software|open source)\b.*', re.IGNORECASE),
98 "No need to specify that the app is Free Software"),
99 (re.compile(r'.*((your|for).*android|android.*(app|device|client|port|version))', re.IGNORECASE),
100 "No need to specify that the app is for Android"),
101 (re.compile(r'.*[a-z0-9][.!?]( |$)'),
102 "Punctuation should be avoided"),
104 "Unnecessary leading space"),
105 (re.compile(r'.*\s$'),
106 "Unnecessary trailing space"),
109 (re.compile(r'^No description available$'),
110 "Description yet to be filled"),
111 (re.compile(r'\s*[*#][^ .]'),
112 "Invalid bulleted list"),
114 "Unnecessary leading space"),
115 (re.compile(r'.*\s$'),
116 "Unnecessary trailing space"),
117 (re.compile(r'.*([^[]|^)\[[^:[\]]+( |\]|$)'),
118 "Invalid link - use [http://foo.bar Link title] or [http://foo.bar]"),
119 (re.compile(r'(^|.* )https?://[^ ]+'),
120 "Unlinkified link - use [http://foo.bar Link title] or [http://foo.bar]"),
124 locale_pattern = re.compile(r'^[a-z]{2,3}(-[A-Z][A-Z])?$')
127 def check_regexes(app):
128 for f, checks in regex_checks.items():
131 t = metadata.fieldtype(f)
132 if t == metadata.TYPE_MULTILINE:
133 for l in v.splitlines():
135 yield "%s at line '%s': %s" % (f, l, r)
140 yield "%s '%s': %s" % (f, v, r)
143 def get_lastbuild(builds):
147 if not build.disable:
148 vercode = int(build.versionCode)
149 if lowest_vercode == -1 or vercode < lowest_vercode:
150 lowest_vercode = vercode
151 if not lastbuild or int(build.versionCode) > int(lastbuild.versionCode):
156 def check_ucm_tags(app):
157 lastbuild = get_lastbuild(app.builds)
158 if (lastbuild is not None
160 and app.UpdateCheckMode == 'RepoManifest'
161 and not lastbuild.commit.startswith('unknown')
162 and lastbuild.versionCode == app.CurrentVersionCode
163 and not lastbuild.forcevercode
164 and any(s in lastbuild.commit for s in '.,_-/')):
165 yield "Last used commit '%s' looks like a tag, but Update Check Mode is '%s'" % (
166 lastbuild.commit, app.UpdateCheckMode)
169 def check_char_limits(app):
170 limits = config['char_limits']
172 if len(app.Summary) > limits['summary']:
173 yield "Summary of length %s is over the %i char limit" % (
174 len(app.Summary), limits['summary'])
176 if len(app.Description) > limits['description']:
177 yield "Description of length %s is over the %i char limit" % (
178 len(app.Description), limits['description'])
181 def check_old_links(app):
191 if any(s in app.Repo for s in usual_sites):
192 for f in ['WebSite', 'SourceCode', 'IssueTracker', 'Changelog']:
194 if any(s in v for s in old_sites):
195 yield "App is in '%s' but has a link to '%s'" % (app.Repo, v)
198 def check_useless_fields(app):
199 if app.UpdateCheckName == app.id:
200 yield "Update Check Name is set to the known app id - it can be removed"
203 filling_ucms = re.compile(r'^(Tags.*|RepoManifest.*)')
206 def check_checkupdates_ran(app):
207 if filling_ucms.match(app.UpdateCheckMode):
208 if not app.AutoName and not app.CurrentVersion and app.CurrentVersionCode == '0':
209 yield "UCM is set but it looks like checkupdates hasn't been run yet"
212 def check_empty_fields(app):
213 if not app.Categories:
214 yield "Categories are not set"
217 all_categories = set([
228 "Science & Education",
238 def check_categories(app):
239 for categ in app.Categories:
240 if categ not in all_categories:
241 yield "Category '%s' is not valid" % categ
244 def check_duplicates(app):
245 if app.Name and app.Name == app.AutoName:
246 yield "Name '%s' is just the auto name - remove it" % app.Name
249 for f in ['Source Code', 'Web Site', 'Issue Tracker', 'Changelog']:
255 yield "Duplicate link in '%s': %s" % (f, v)
259 name = app.Name or app.AutoName
260 if app.Summary and name:
261 if app.Summary.lower() == name.lower():
262 yield "Summary '%s' is just the app's name" % app.Summary
264 if app.Summary and app.Description and len(app.Description) == 1:
265 if app.Summary.lower() == app.Description[0].lower():
266 yield "Description '%s' is just the app's summary" % app.Summary
269 for l in app.Description.splitlines():
273 yield "Description has a duplicate line"
277 desc_url = re.compile(r'(^|[^[])\[([^ ]+)( |\]|$)')
280 def check_mediawiki_links(app):
281 wholedesc = ' '.join(app.Description)
282 for um in desc_url.finditer(wholedesc):
284 for m, r in http_checks:
286 yield "URL '%s' in Description: %s" % (url, r)
289 def check_bulleted_lists(app):
290 validchars = ['*', '#']
293 for l in app.Description.splitlines():
298 if l[0] == lchar and l[1] == ' ':
300 if lcount > 2 and lchar not in validchars:
301 yield "Description has a list (%s) but it isn't bulleted (*) nor numbered (#)" % lchar
308 def check_builds(app):
309 for build in app.builds:
311 if build.disable.startswith('Generated by import.py'):
312 yield "Build generated by `fdroid import` - remove disable line once ready"
314 for s in ['master', 'origin', 'HEAD', 'default', 'trunk']:
315 if build.commit and build.commit.startswith(s):
316 yield "Branch '%s' used as commit in build '%s'" % (s, build.versionName)
317 for srclib in build.srclibs:
318 ref = srclib.split('@')[1].split('/')[0]
319 if ref.startswith(s):
320 yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
323 def check_files_dir(app):
324 dir_path = os.path.join('metadata', app.id)
325 if not os.path.isdir(dir_path):
328 for name in os.listdir(dir_path):
329 path = os.path.join(dir_path, name)
330 if not (os.path.isfile(path) or name == 'signatures' or locale_pattern.match(name)):
331 yield "Found non-file at %s" % path
335 used = {'signatures', }
336 for build in app.builds:
337 for fname in build.patch:
338 if fname not in files:
339 yield "Unknown file %s in build '%s'" % (fname, build.versionName)
343 for name in files.difference(used):
344 if locale_pattern.match(name):
346 yield "Unused file at %s" % os.path.join(dir_path, name)
349 def check_format(app):
350 if options.format and not rewritemeta.proper_format(app):
351 yield "Run rewritemeta to fix formatting"
354 def check_extlib_dir(apps):
355 dir_path = os.path.join('build', 'extlib')
357 for root, dirs, names in os.walk(dir_path):
359 files.add(os.path.join(root, name)[len(dir_path) + 1:])
363 for build in app.builds:
364 for path in build.extlibs:
365 if path not in files:
366 yield "%s: Unknown extlib %s in build '%s'" % (app.id, path, build.versionName)
370 for path in files.difference(used):
371 if any(path.endswith(s) for s in [
373 'source.txt', 'origin.txt', 'md5.txt',
374 'LICENSE', 'LICENSE.txt',
375 'COPYING', 'COPYING.txt',
376 'NOTICE', 'NOTICE.txt',
379 yield "Unused extlib at %s" % os.path.join(dir_path, path)
384 global config, options
386 # Parse command line...
387 parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
388 common.setup_global_opts(parser)
389 parser.add_argument("-f", "--format", action="store_true", default=False,
390 help="Also warn about formatting issues, like rewritemeta -l")
391 parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
392 metadata.add_metadata_arguments(parser)
393 options = parser.parse_args()
394 metadata.warnings_action = options.W
396 config = common.read_config(options)
399 allapps = metadata.read_metadata(xref=True)
400 apps = common.read_app_args(options.appid, allapps, False)
404 apps_check_funcs = []
405 if len(options.appid) == 0:
406 # otherwise it finds tons of unused extlibs
407 apps_check_funcs.append(check_extlib_dir)
408 for check_func in apps_check_funcs:
409 for warn in check_func(apps.values()):
413 for appid, app in apps.items():
422 check_checkupdates_ran,
423 check_useless_fields,
427 check_mediawiki_links,
428 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 if __name__ == "__main__":