chiark / gitweb /
lint: also check for trailing spaces in names
[fdroidserver.git] / fdroidserver / lint.py
index e3ca9ea3b812b4b7406f932b9a74b4d585d6dba1..ee4381c0f10c4a4a73adad3a71be4ebc9b6aa281 100644 (file)
 
 from argparse import ArgumentParser
 import re
-import common
-import metadata
 import sys
 from sets import Set
 
+import common
+import metadata
+import rewritemeta
+
 config = None
 options = None
 
@@ -72,6 +74,12 @@ regex_checks = {
          "Flattr donation methods belong in the FlattrID flag"),
     ],
     'Changelog': http_checks,
+    'Author Name': [
+        (re.compile(r'^\s'),
+         "Unnecessary leading space"),
+        (re.compile(r'.*\s$'),
+         "Unnecessary trailing space"),
+    ],
     'License': [
         (re.compile(r'^(|None|Unknown)$'),
          "No license specified"),
@@ -85,6 +93,10 @@ regex_checks = {
          "No need to specify that the app is for Android"),
         (re.compile(r'.*[a-z0-9][.!?]( |$)'),
          "Punctuation should be avoided"),
+        (re.compile(r'^\s'),
+         "Unnecessary leading space"),
+        (re.compile(r'.*\s$'),
+         "Unnecessary trailing space"),
     ],
     'Description': [
         (re.compile(r'^No description available$'),
@@ -107,15 +119,16 @@ def check_regexes(app):
     for f, checks in regex_checks.iteritems():
         for m, r in checks:
             v = app.get_field(f)
-            if type(v) == str:
+            t = metadata.fieldtype(f)
+            if t == metadata.TYPE_MULTILINE:
+                for l in v.splitlines():
+                    if m.match(l):
+                        yield "%s at line '%s': %s" % (f, l, r)
+            else:
                 if v is None:
                     continue
                 if m.match(v):
                     yield "%s '%s': %s" % (f, v, r)
-            elif type(v) == list:
-                for l in v:
-                    if m.match(l):
-                        yield "%s at line '%s': %s" % (f, l, r)
 
 
 def get_lastbuild(builds):
@@ -147,15 +160,13 @@ def check_ucm_tags(app):
 def check_char_limits(app):
     limits = config['char_limits']
 
-    summ_chars = len(app.Summary)
-    if summ_chars > limits['Summary']:
+    if len(app.Summary) > limits['Summary']:
         yield "Summary of length %s is over the %i char limit" % (
-            summ_chars, limits['Summary'])
+            len(app.Summary), limits['Summary'])
 
-    desc_charcount = sum(len(l) for l in app.Description)
-    if desc_charcount > limits['Description']:
+    if len(app.Description) > limits['Description']:
         yield "Description of length %s is over the %i char limit" % (
-            desc_charcount, limits['Description'])
+            len(app.Description), limits['Description'])
 
 
 def check_old_links(app):
@@ -244,7 +255,7 @@ def check_duplicates(app):
             yield "Description '%s' is just the app's summary" % app.Summary
 
     seenlines = set()
-    for l in app.Description:
+    for l in app.Description.splitlines():
         if len(l) < 1:
             continue
         if l in seenlines:
@@ -268,7 +279,7 @@ def check_bulleted_lists(app):
     validchars = ['*', '#']
     lchar = ''
     lcount = 0
-    for l in app.Description:
+    for l in app.Description.splitlines():
         if len(l) < 1:
             lcount = 0
             continue
@@ -294,6 +305,8 @@ def check_builds(app):
                 ref = srclib.split('@')[1].split('/')[0]
                 if ref.startswith(s):
                     yield "Branch '%s' used as commit in srclib '%s'" % (s, srclib)
+        if build.target and build.method() == 'gradle':
+            yield "target= has no gradle support"
 
 
 def main():
@@ -305,6 +318,8 @@ def main():
     # Parse command line...
     parser = ArgumentParser(usage="%(prog)s [options] [APPID [APPID ...]]")
     common.setup_global_opts(parser)
+    parser.add_argument("-f", "--format", action="store_true", default=False,
+                        help="Also warn about formatting issues, like rewritemeta -l")
     parser.add_argument("appid", nargs='*', help="app-id in the form APPID")
     options = parser.parse_args()
 
@@ -336,10 +351,14 @@ def main():
                 ]:
             warns += check_func(app)
 
+        if options.format:
+            if not rewritemeta.proper_format(app):
+                warns.append("Run rewritemeta to fix formatting")
+
         if warns:
             anywarns = True
             for warn in warns:
-                print "%s: %s" % (appid, warn)
+                print("%s: %s" % (appid, warn))
 
     if anywarns:
         sys.exit(1)