Add --select option.
authorflorentx <florent.xicluna@gmail.com>
Sat, 24 Oct 2009 21:42:46 +0000 (23:42 +0200)
committerflorentx <florent.xicluna@gmail.com>
Sat, 24 Oct 2009 21:42:46 +0000 (23:42 +0200)
CHANGES.txt
README.rst
pep8.py

index dfd416344ef500f78a3a1f698f74ffc2dbf3be9c..3ca6a6f9b4ac693f25c3bc670421ee1772962d7c 100644 (file)
@@ -5,6 +5,8 @@ Changelog
 0.5 (unreleased)
 ----------------
 
+* Add --select option which is mirror of --ignore
+
 * New check W603 warns about the deprecated operator ``<>``
 
 * Performance improvement, due to rewriting of E225
index a03717bf41f96cbf0e196e2a00f315bfa308f298..582cb6f9e01e6f46a29553e87737dc66c6748420 100644 (file)
@@ -82,6 +82,7 @@ Quick help is available on the command line::
                          separated patterns (default: .svn,CVS,.bzr,.hg,.git)
     --filename=patterns  when parsing directories, only check filenames matching
                          these comma separated patterns (default: *.py)
+    --select=errors      select errors and warnings (e.g. E,W6)
     --ignore=errors      skip errors and warnings (e.g. E4,W)
     --repeat             show all occurrences of the same error
     --show-source        show source code for each error
diff --git a/pep8.py b/pep8.py
index ad4c762675aa6d6cad67c726a9d683ffab7635b4..a33e09ce3341bc4da8a3c602923638dd40d42f32 100755 (executable)
--- a/pep8.py
+++ b/pep8.py
@@ -981,7 +981,11 @@ def filename_match(filename):
 def ignore_code(code):
     """
     Check if options.ignore contains a prefix of the error code.
+    If options.select contains a prefix of the error code, do not ignore it.
     """
+    for select in options.select:
+        if code.startswith(select):
+            return False
     for ignore in options.ignore:
         if code.startswith(ignore):
             return True
@@ -1114,6 +1118,8 @@ def process_options(arglist=None):
                       help="when parsing directories, only check filenames "
                         "matching these comma separated patterns (default: "
                         "*.py)")
+    parser.add_option('--select', metavar='errors', default='',
+                      help="select errors and warnings (e.g. E,W6)")
     parser.add_option('--ignore', metavar='errors', default='',
                       help="skip errors and warnings (e.g. E4,W)")
     parser.add_option('--repeat', action='store_true',
@@ -1143,9 +1149,17 @@ def process_options(arglist=None):
         options.exclude[index] = options.exclude[index].rstrip('/')
     if options.filename:
         options.filename = options.filename.split(',')
+    if options.select:
+        options.select = options.select.split(',')
+    else:
+        options.select = []
     if options.ignore:
         options.ignore = options.ignore.split(',')
+    elif options.select:
+        # Ignore all checks which are not explicitly selected
+        options.ignore = ['']
     else:
+        # The default choice: all checks are required
         options.ignore = []
     options.physical_checks = find_checks('physical_line')
     options.logical_checks = find_checks('logical_line')