Merge lp:~adiroiban/pocket-lint/1085490-windows-new-lines into lp:pocket-lint

Proposed by Adi Roiban
Status: Merged
Approved by: Curtis Hovey
Approved revision: 473
Merged at revision: 472
Proposed branch: lp:~adiroiban/pocket-lint/1085490-windows-new-lines
Merge into: lp:pocket-lint
Diff against target: 95 lines (+28/-0)
2 files modified
pocketlint/formatcheck.py (+15/-0)
pocketlint/tests/test_text.py (+13/-0)
To merge this branch: bzr merge lp:~adiroiban/pocket-lint/1085490-windows-new-lines
Reviewer Review Type Date Requested Status
Curtis Hovey code Approve
Review via email: mp+137407@code.launchpad.net

Description of the change

Here are the changes for adding windows newline checks.

The windows endline checks were added for all types.

There is no option to turn off the ckeck for Windows newlines.

Please let me know if you think that this check should be disabled by default or requires command line options.

Thanks!

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

Thank you. I will merge the branch.

review: Approve (code)

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-04-25 13:09:13 +0000
3+++ pocketlint/formatcheck.py 2012-12-02 00:45:25 +0000
4@@ -346,6 +346,12 @@
5 self.message(
6 line_no, 'Line contains a tab character.', icon='info')
7
8+ def check_windows_endlines(self):
9+ """Check that file does not contains Windows newlines."""
10+ if self.text.find('\r\n') != -1:
11+ self.message(
12+ 0, 'File contains Windows new lines.', icon='info')
13+
14
15 class AnyTextChecker(BaseChecker, AnyTextMixin):
16 """Verify the text of the document."""
17@@ -358,6 +364,8 @@
18 self.check_trailing_whitespace(line_no, line)
19 self.check_conflicts(line_no, line)
20
21+ self.check_windows_endlines()
22+
23
24 class SQLChecker(BaseChecker, AnyTextMixin):
25 """Verify SQL style."""
26@@ -372,6 +380,8 @@
27 self.check_tab(line_no, line)
28 self.check_conflicts(line_no, line)
29
30+ self.check_windows_endlines()
31+
32
33 class XMLChecker(BaseChecker, AnyTextMixin):
34 """Check XML documents."""
35@@ -423,6 +433,7 @@
36 error_lineno = int(location.split(',')[0].split()[1]) - offset
37 self.message(error_lineno, error_message, icon='error')
38 self.check_text()
39+ self.check_windows_endlines()
40
41 def check_text(self):
42 for line_no, line in enumerate(self.text.splitlines()):
43@@ -477,6 +488,7 @@
44
45 self.check_cssutils()
46 self.check_text()
47+ self.check_windows_endlines()
48 # CSS coding conventoins checks should go last since they rely
49 # on previous checks.
50 self.check_css_coding_conventions()
51@@ -526,6 +538,7 @@
52 self.check_text()
53 self.check_flakes()
54 self.check_pep8()
55+ self.check_windows_endlines()
56
57 def check_flakes(self):
58 """Check compilation and syntax."""
59@@ -633,6 +646,7 @@
60 line_no -= 1
61 self.message(line_no, message, icon='error')
62 self.check_text()
63+ self.check_windows_endlines()
64
65 def check_debugger(self, line_no, line):
66 """Check the length of the line."""
67@@ -669,6 +683,7 @@
68 """Check the syntax of the reStructuredText code."""
69 self.check_lines()
70 self.check_empty_last_line()
71+ self.check_windows_endlines()
72
73 def check_lines(self):
74 """Call each line checker for each line in text."""
75
76=== modified file 'pocketlint/tests/test_text.py'
77--- pocketlint/tests/test_text.py 2012-01-29 21:24:20 +0000
78+++ pocketlint/tests/test_text.py 2012-12-02 00:45:25 +0000
79@@ -75,3 +75,16 @@
80 self.assertEqual(
81 [(1, 'Line exceeds 49 characters.')],
82 self.reporter.messages)
83+
84+ def test_windows_newlines(self):
85+ """
86+ Files with Windows newlines are reported with errors.
87+ """
88+ content = '\r\nbla\r\nbla\r\n'
89+ checker = AnyTextChecker(
90+ 'bogus', content, self.reporter)
91+ checker.check()
92+ self.assertEqual(
93+ [(0, 'File contains Windows new lines.')],
94+ self.reporter.messages)
95+ self.assertEqual(1, self.reporter.call_count)

Subscribers

People subscribed via source and target branches

to all changes: