~ubuntu-branches/ubuntu/vivid/pylint/vivid-proposed

« back to all changes in this revision

Viewing changes to lint.py

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2009-12-19 21:38:49 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20091219213849-kcax3214c3mmucox
Tags: 0.19.0-1
* New upstream release
* debian/pylint.docs
  - removed 'TODO', no more shipped
* debian/copyright
  - updated copyright information, also adding new files with different info
* debian/{rules, TODO}
  - run tests at build-time
* debian/pylint.postrm
  - use 'set -e' instead of calling shell with '-e'

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
import re
36
36
import tokenize
37
37
 
38
 
from logilab.common.configuration import UnsupportedAction, OptionsManagerMixIn, check_csv
 
38
from logilab.common.configuration import UnsupportedAction, OptionsManagerMixIn
 
39
from logilab.common.optik_ext import check_csv
39
40
from logilab.common.modutils import load_module_from_name
40
41
from logilab.common.interface import implements
41
42
from logilab.common.textutils import splitstrip
70
71
 
71
72
MSGS = {
72
73
    'F0001': ('%s',
73
 
              'Used when an error occured preventing the analysis of a \
 
74
              'Used when an error occurred preventing the analysis of a \
74
75
              module (unable to find it for instance).'),
75
76
    'F0002': ('%s: %s',
76
 
              'Used when an unexpected error occured while building the ASTNG \
 
77
              'Used when an unexpected error occurred while building the ASTNG \
77
78
              representation. This is usually accompanied by a traceback. \
78
79
              Please report such errors !'),
79
80
    'F0003': ('ignored builtin module %s',
80
81
              'Used to indicate that the user asked to analyze a builtin module\
81
82
              which has been skipped.'),
82
 
    'F0004': ('unexpected infered value %s',
 
83
    'F0004': ('unexpected inferred value %s',
83
84
              'Used to indicate that some value of an unexpected type has been \
84
 
              infered.'),
 
85
              inferred.'),
85
86
 
86
87
    'I0001': ('Unable to run raw checkers on built-in module %s',
87
88
              'Used to inform that a built-in module has not been checked \
185
186
                {'default': 1, 'type' : 'yn', 'metavar' : '<y_or_n>',
186
187
                 'short': 'r',
187
188
                 'group': 'Reports',
188
 
                 'help' : 'Tells wether to display a full report or only the\
 
189
                 'help' : 'Tells whether to display a full report or only the\
189
190
 messages'}),
190
191
 
191
192
               ('evaluation',
195
196
convention) / statement) * 10)',
196
197
                 'help' : 'Python expression which should return a note less \
197
198
than 10 (10 is the highest note). You have access to the variables errors \
198
 
warning, statement which respectivly contain the number of errors / warnings\
 
199
warning, statement which respectively contain the number of errors / warnings\
199
200
 messages and the total number of statements analyzed. This is used by the \
200
201
 global evaluation report (R0004).'}),
201
202
 
430
431
            self.collect_block_lines(child, msg_state)
431
432
        first = node.fromlineno
432
433
        last = node.tolineno
433
 
        # first child line number used to distinguate between disable-msg
 
434
        # first child line number used to distinguish between disable-msg
434
435
        # which are the first child of scoped node with those defined later.
435
436
        # For instance in the code below:
436
437
        #
635
636
        try:
636
637
            note = eval(evaluation, {}, self.stats)
637
638
        except Exception, ex:
638
 
            msg = 'An exception occured while rating: %s' % ex
 
639
            msg = 'An exception occurred while rating: %s' % ex
639
640
        else:
640
641
            stats['global_note'] = note
641
642
            msg = 'Your code has been rated at %.2f/10' % note
665
666
                if not msg_id.startswith('I')]
666
667
    in_order.sort()
667
668
    in_order.reverse()
668
 
    lines = ('message id', 'occurences')
 
669
    lines = ('message id', 'occurrences')
669
670
    for value, msg_id in in_order:
670
671
        lines += (msg_id, str(value))
671
672
    sect.append(Table(children=lines, cols=2, rheaders=1))
786
787
             {'action' : 'callback', 'metavar': '<msg-id>',
787
788
              'callback' : self.cb_list_messages,
788
789
              'group': 'Commands',
 
790
              'help' : "Generate pylint's messages."}),
 
791
 
 
792
            ('full-documentation',
 
793
             {'action' : 'callback', 'metavar': '<msg-id>',
 
794
              'callback' : self.cb_full_documentation,
 
795
              'group': 'Commands',
789
796
              'help' : "Generate pylint's full documentation."}),
790
797
 
791
798
            ('generate-rcfile',
831
838
    * (R) refactor, for bad code smell                                          
832
839
    * (W) warning, for python specific problems                                 
833
840
    * (E) error, for probable bugs in the code                                  
834
 
    * (F) fatal, if an error occured which prevented pylint from doing further
 
841
    * (F) fatal, if an error occurred which prevented pylint from doing further
835
842
processing.
836
843
        ''')
837
844
        linter.add_help_section('Output status code', '''
838
845
Pylint should leave with following status code:                                 
839
846
    * 0 if everything went fine                                                 
840
 
    * 1 if some fatal message issued                                            
841
 
    * 2 if some error message issued                                            
842
 
    * 4 if some warning message issued                                          
843
 
    * 8 if some refactor message issued                                         
844
 
    * 16 if some convention message issued                                      
 
847
    * 1 if a fatal message was issued                                           
 
848
    * 2 if an error message was issued                                          
 
849
    * 4 if a warning message was issued                                         
 
850
    * 8 if a refactor message was issued                                        
 
851
    * 16 if a convention message was issued                                     
845
852
    * 32 on usage error                                                         
846
853
                                                                                
847
854
status 1 to 16 will be bit-ORed so you can know which different categories has
859
866
        # provide options) have been registered
860
867
        linter.load_config_file()
861
868
        if reporter:
862
 
            # if a custom reporter is provided as argument, it may be overriden
 
869
            # if a custom reporter is provided as argument, it may be overridden
863
870
            # by file parameters, so re-set it here, but before command line
864
871
            # parsing so it's still overrideable by command line option
865
872
            linter.set_reporter(reporter)
886
893
        sys.exit(self.linter.msg_status)
887
894
 
888
895
    def cb_set_rcfile(self, name, value):
889
 
        """callback for option preprocessing (ie before optik parsing)"""
 
896
        """callback for option preprocessing (i.e. before optik parsing)"""
890
897
        self._rcfile = value
891
898
 
892
899
    def cb_add_plugins(self, name, value):
893
 
        """callback for option preprocessing (ie before optik parsing)"""
 
900
        """callback for option preprocessing (i.e. before optik parsing)"""
894
901
        self._plugins.extend(splitstrip(value))
895
902
 
896
903
    def cb_error_mode(self, *args, **kwargs):
901
908
        * do not save execution information
902
909
        """
903
910
        self.linter.disable_noerror_checkers()
904
 
        self.linter.set_option('disable-msg-cat', 'WCRFI')
 
911
        self.linter.set_option('disable-msg-cat', 'WCRI')
905
912
        self.linter.set_option('reports', False)
906
913
        self.linter.set_option('persistent', False)
907
914
 
921
928
        self.linter.help_message(splitstrip(value))
922
929
        sys.exit(0)
923
930
 
924
 
    def cb_list_messages(self, option, opt_name, value, parser):
 
931
    def cb_full_documentation(self, option, opt_name, value, parser):
 
932
        """optik callback for printing full documentation"""
 
933
        self.linter.print_full_documentation()
 
934
        sys.exit(0)
 
935
 
 
936
    def cb_list_messages(self, option, opt_name, value, parser): # FIXME
925
937
        """optik callback for printing available messages"""
926
 
        self.linter.list_messages()
 
938
        self.linter.list_sorted_messages()
927
939
        sys.exit(0)
928
940
 
929
941
def cb_init_hook(option, opt_name, value, parser):