Merge lp:~adiroiban/pocket-lint/923309 into lp:pocket-lint

Proposed by Adi Roiban
Status: Merged
Approved by: Curtis Hovey
Approved revision: 448
Merged at revision: 449
Proposed branch: lp:~adiroiban/pocket-lint/923309
Merge into: lp:pocket-lint
Diff against target: 64 lines (+18/-8)
1 file modified
pocketlint/formatcheck.py (+18/-8)
To merge this branch: bzr merge lp:~adiroiban/pocket-lint/923309
Reviewer Review Type Date Requested Status
Curtis Hovey code Approve
Review via email: mp+90618@code.launchpad.net

Description of the change

This is my take on implementing a more flexible pocket-lint for checking line length.

Please let me know if you want this configuration to be implemented in a different way.

Maybe this will require a few lines in the documentation/README

I am currently using it in the following way:

    from pocketlint.formatcheck import (
        BaseChecker,
        check_sources,
        PythonChecker,
        )

    # Patch checkers.
    BaseChecker.check_length_filter = lambda self: 78
    PythonChecker.check_length_filter = lambda self: 78

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

I have already merged your changes in to my branch.

I then factored out the link_length check from the python checker because pep8. pep8 users the check_length_filter to determine if it needs to override the default. I am presently adding a command line arg (--max-length) that will be used by check_length_filter.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'pocketlint/formatcheck.py'
--- pocketlint/formatcheck.py 2012-01-29 18:30:41 +0000
+++ pocketlint/formatcheck.py 2012-01-29 20:25:28 +0000
@@ -215,7 +215,6 @@
215215
216 The Decedent must provide self.file_name and self.base_dir216 The Decedent must provide self.file_name and self.base_dir
217 """217 """
218
219 def __init__(self, file_path, text, reporter=None):218 def __init__(self, file_path, text, reporter=None):
220 self.file_path = file_path219 self.file_path = file_path
221 self.base_dir = os.path.dirname(file_path)220 self.base_dir = os.path.dirname(file_path)
@@ -244,6 +243,13 @@
244 """Check the content."""243 """Check the content."""
245 raise NotImplementedError244 raise NotImplementedError
246245
246 def check_length_filter(self):
247 '''Default filter used by default for checking line lengt.'''
248 if '/lib/lp/' in self.file_path:
249 return 78
250 else:
251 return 80
252
247253
248class UniversalChecker(BaseChecker):254class UniversalChecker(BaseChecker):
249 """Check and reformat doctests."""255 """Check and reformat doctests."""
@@ -288,11 +294,10 @@
288294
289 def check_length(self, line_no, line):295 def check_length(self, line_no, line):
290 """Check the length of the line."""296 """Check the length of the line."""
291 if '/lib/lp/' in self.file_path:297
292 max_length = 78298 max_length = self.check_length_filter()
293 else:299
294 max_length = 80300 if max_length and len(line) > max_length:
295 if len(line) > max_length:
296 self.message(301 self.message(
297 line_no, 'Line exceeds %s characters.' % max_length,302 line_no, 'Line exceeds %s characters.' % max_length,
298 icon='info')303 icon='info')
@@ -546,8 +551,7 @@
546 self.check_pdb(line_no, line)551 self.check_pdb(line_no, line)
547 self.check_conflicts(line_no, line)552 self.check_conflicts(line_no, line)
548 self.check_ascii(line_no, line)553 self.check_ascii(line_no, line)
549 if '/lib/lp/' in self.file_path:554 self.check_length(line_no, line)
550 self.check_length(line_no, line)
551555
552 def check_pdb(self, line_no, line):556 def check_pdb(self, line_no, line):
553 """Check the length of the line."""557 """Check the length of the line."""
@@ -565,6 +569,12 @@
565 line = line.decode('utf-8')569 line = line.decode('utf-8')
566 super(PythonChecker, self).check_length(line_no, line)570 super(PythonChecker, self).check_length(line_no, line)
567571
572 def check_length_filter(self):
573 '''Default filter used by default for checking line lengt.'''
574 if '/lib/lp/' not in self.file_path:
575 return False
576 return super(PythonChecker, self).check_length_filter()
577
568 def check_ascii(self, line_no, line):578 def check_ascii(self, line_no, line):
569 """Check that the line is ascii."""579 """Check that the line is ascii."""
570 if self.encoding != 'ascii':580 if self.encoding != 'ascii':

Subscribers

People subscribed via source and target branches

to all changes: