فهرست منبع

HUE-9371 [pylint] Add 3 rules to get started

C0326(bad-whitespace) --> avoid {'a':1} ...
W0311(bad-indentation) --> not 2 spaces
C0301(line-too-long) --> > 150 char

Only applies on modified files.
Romain 5 سال پیش
والد
کامیت
dd0100915b
2فایلهای تغییر یافته به همراه43 افزوده شده و 22 حذف شده
  1. 21 13
      desktop/.pylintrc
  2. 22 9
      desktop/core/src/desktop/management/commands/runpylint.py

+ 21 - 13
desktop/.pylintrc

@@ -40,7 +40,13 @@ confidence=
 # Enable the message, report, category or checker with the given id(s). You can
 # either give multiple identifier separated by comma (,) or put this option
 # multiple time. See also the "--disable" option for examples.
-enable=use-symbolic-message-instead,useless-supression,fixme
+
+# For some reason not picked-up, please keep in sync and see the `RULES` list in
+# https://github.com/cloudera/hue/blob/master/desktop/core/src/desktop/management/commands/runpylint.py#L30
+# enable=
+  # C0326(bad-whitespace)
+  # W0311(bad-indentation)
+  # C0301(line-too-long
 
 # Disable the message, report, category or checker with the given id(s). You
 # can either give multiple identifiers separated by comma (,) or put this
@@ -52,15 +58,16 @@ enable=use-symbolic-message-instead,useless-supression,fixme
 # no Warning level messages displayed, use"--disable=all --enable=classes
 # --disable=W"
 
-disable=
-    attribute-defined-outside-init,
-    duplicate-code,
-    invalid-name,
-    missing-docstring,
-    protected-access,
-    too-few-public-methods,
-    # handled by black
-    format
+disable=all
+
+  #attribute-defined-outside-init,
+  #duplicate-code,
+  #invalid-name,
+  #missing-docstring,
+  #protected-access,
+  #too-few-public-methods,
+  # handled by black
+  #format
 
 
 [REPORTS]
@@ -139,7 +146,7 @@ callbacks=cb_,_cb
 [FORMAT]
 
 # Maximum number of characters on a single line.
-max-line-length=100
+max-line-length=150
 
 # Regexp for a line that is allowed to be longer than the limit.
 ignore-long-lines=^\s*(# )?<?https?://\S+>?$
@@ -149,14 +156,15 @@ ignore-long-lines=^\s*(# )?<?https?://\S+>?$
 single-line-if-stmt=no
 
 # List of optional constructs for which whitespace checking is disabled
-no-space-check=trailing-comma,dict-separator
+# no-space-check=trailing-comma,dict-separator
+no-space-check=
 
 # Maximum number of lines in a module
 max-module-lines=2000
 
 # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
 # tab).
-indent-string='    '
+indent-string='  '
 
 # Number of spaces of indent required inside a hanging or continued line.
 indent-after-paren=4

+ 22 - 9
desktop/core/src/desktop/management/commands/runpylint.py

@@ -27,6 +27,13 @@ from django.utils.translation import ugettext as _
 from desktop.lib import paths
 
 
+RULES = [
+  'C0326(bad-whitespace)',
+  'W0311(bad-indentation)',
+  'C0301(line-too-long)'
+]
+
+
 class Command(BaseCommand):
   help = _("""
   Runs pylint on desktop and app code.
@@ -53,21 +60,20 @@ class Command(BaseCommand):
     parser.add_argument('-f', '--force', dest='force', default='true', action="store_true")
     parser.add_argument('--output-format', action='store', dest='outputformat', default='parseable')
     parser.add_argument('-a', '--app', dest='app', action='store', default='all', choices=self.valid_app())
-    parser.add_argument('-F', '--files', dest='files', action='store', default='')
+    parser.add_argument('-F', '--files', dest='files', action='store', default=None)
 
   def handle(self, *args, **options):
     """Check the source code using PyLint."""
 
     # Note that get_build_dir() is suitable for testing use only.
     pylint_prog = paths.get_build_dir('env', 'bin', 'pylint')
-    pylint_args = [pylint_prog, "--rcfile=" + settings.PYLINTRC, "--load-plugins", "pylint_django"]
-
-    if options['files']:
-      pylint_args.extend(options['files'].split(' '))
-    elif options['app'] == 'all':
-      pylint_args.extend(self.valid_app())
-    else:
-      pylint_args.append(options['app'])
+    pylint_args = [
+      pylint_prog,
+      "--rcfile=" + settings.PYLINTRC,
+      "--disable=all",
+      "--enable=%s" % ','.join([rule.split('(', 1)[0] for rule in RULES]),
+      "--load-plugins=pylint_django"
+    ]
 
     if options['force']:
       pylint_args.append('-f')
@@ -75,6 +81,13 @@ class Command(BaseCommand):
     if options['outputformat']:
       pylint_args.append(options['outputformat'])
 
+    if options['files'] is not None:
+      pylint_args.extend(options['files'].split())
+    elif options['app'] == 'all':
+      pylint_args.extend(self.valid_app())
+    else:
+      pylint_args.append(options['app'])
+
     if not os.path.exists(pylint_prog):
       msg = _("Cannot find pylint at '%(path)s'. Please install pylint first.") % {'path': pylint_prog}
       logging.error(msg)