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

Proposed by Adi Roiban
Status: Merged
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 Pending
Review via email: mp+90617@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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'pocketlint/formatcheck.py'
2--- pocketlint/formatcheck.py 2012-01-29 18:30:41 +0000
3+++ pocketlint/formatcheck.py 2012-01-29 20:25:27 +0000
4@@ -215,7 +215,6 @@
5
6 The Decedent must provide self.file_name and self.base_dir
7 """
8-
9 def __init__(self, file_path, text, reporter=None):
10 self.file_path = file_path
11 self.base_dir = os.path.dirname(file_path)
12@@ -244,6 +243,13 @@
13 """Check the content."""
14 raise NotImplementedError
15
16+ def check_length_filter(self):
17+ '''Default filter used by default for checking line lengt.'''
18+ if '/lib/lp/' in self.file_path:
19+ return 78
20+ else:
21+ return 80
22+
23
24 class UniversalChecker(BaseChecker):
25 """Check and reformat doctests."""
26@@ -288,11 +294,10 @@
27
28 def check_length(self, line_no, line):
29 """Check the length of the line."""
30- if '/lib/lp/' in self.file_path:
31- max_length = 78
32- else:
33- max_length = 80
34- if len(line) > max_length:
35+
36+ max_length = self.check_length_filter()
37+
38+ if max_length and len(line) > max_length:
39 self.message(
40 line_no, 'Line exceeds %s characters.' % max_length,
41 icon='info')
42@@ -546,8 +551,7 @@
43 self.check_pdb(line_no, line)
44 self.check_conflicts(line_no, line)
45 self.check_ascii(line_no, line)
46- if '/lib/lp/' in self.file_path:
47- self.check_length(line_no, line)
48+ self.check_length(line_no, line)
49
50 def check_pdb(self, line_no, line):
51 """Check the length of the line."""
52@@ -565,6 +569,12 @@
53 line = line.decode('utf-8')
54 super(PythonChecker, self).check_length(line_no, line)
55
56+ def check_length_filter(self):
57+ '''Default filter used by default for checking line lengt.'''
58+ if '/lib/lp/' not in self.file_path:
59+ return False
60+ return super(PythonChecker, self).check_length_filter()
61+
62 def check_ascii(self, line_no, line):
63 """Check that the line is ascii."""
64 if self.encoding != 'ascii':

Subscribers

People subscribed via source and target branches

to all changes: