| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 # pylint: disable=W0511 | 
|  | 2 # This program is free software; you can redistribute it and/or modify it under | 
|  | 3 # the terms of the GNU General Public License as published by the Free Software | 
|  | 4 # Foundation; either version 2 of the License, or (at your option) any later | 
|  | 5 # version. | 
|  | 6 # | 
|  | 7 # This program is distributed in the hope that it will be useful, but WITHOUT | 
|  | 8 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
|  | 9 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | 
|  | 10 # | 
|  | 11 # You should have received a copy of the GNU General Public License along with | 
|  | 12 # this program; if not, write to the Free Software Foundation, Inc., | 
|  | 13 # 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
|  | 14 """ Copyright (c) 2000-2010 LOGILAB S.A. (Paris, FRANCE). | 
|  | 15  http://www.logilab.fr/ -- mailto:contact@logilab.fr | 
|  | 16 | 
|  | 17 Check source code is ascii only or has an encoding declaration (PEP 263) | 
|  | 18 """ | 
|  | 19 | 
|  | 20 import re, sys | 
|  | 21 | 
|  | 22 from pylint.interfaces import IRawChecker | 
|  | 23 from pylint.checkers import BaseChecker | 
|  | 24 | 
|  | 25 | 
|  | 26 MSGS = { | 
|  | 27     'W0511': ('%s', | 
|  | 28               'Used when a warning note as FIXME or XXX is detected.'), | 
|  | 29     } | 
|  | 30 | 
|  | 31 class EncodingChecker(BaseChecker): | 
|  | 32     """checks for: | 
|  | 33     * warning notes in the code like FIXME, XXX | 
|  | 34     * PEP 263: source code with non ascii character but no encoding declaration | 
|  | 35     """ | 
|  | 36     __implements__ = IRawChecker | 
|  | 37 | 
|  | 38     # configuration section name | 
|  | 39     name = 'miscellaneous' | 
|  | 40     msgs = MSGS | 
|  | 41 | 
|  | 42     options = (('notes', | 
|  | 43                 {'type' : 'csv', 'metavar' : '<comma separated values>', | 
|  | 44                  'default' : ('FIXME', 'XXX', 'TODO'), | 
|  | 45                  'help' : 'List of note tags to take in consideration, \ | 
|  | 46 separated by a comma.' | 
|  | 47                  }), | 
|  | 48                ) | 
|  | 49 | 
|  | 50     def __init__(self, linter=None): | 
|  | 51         BaseChecker.__init__(self, linter) | 
|  | 52 | 
|  | 53     def process_module(self, node): | 
|  | 54         """inspect the source file to found encoding problem or fixmes like | 
|  | 55         notes | 
|  | 56         """ | 
|  | 57         stream = node.file_stream | 
|  | 58         stream.seek(0) # XXX may be removed with astng > 0.23 | 
|  | 59         # warning notes in the code | 
|  | 60         notes = [] | 
|  | 61         for note in self.config.notes: | 
|  | 62             notes.append(re.compile(note)) | 
|  | 63         linenum = 1 | 
|  | 64         for line in stream.readlines(): | 
|  | 65             for note in notes: | 
|  | 66                 match = note.search(line) | 
|  | 67                 if match: | 
|  | 68                     self.add_message('W0511', args=line[match.start():-1], | 
|  | 69                                      line=linenum) | 
|  | 70                     break | 
|  | 71             linenum += 1 | 
|  | 72 | 
|  | 73 | 
|  | 74 | 
|  | 75 def register(linter): | 
|  | 76     """required method to auto register this checker""" | 
|  | 77     linter.register_checker(EncodingChecker(linter)) | 
| OLD | NEW | 
|---|