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
=== modified file 'pocketlint/formatcheck.py'
--- pocketlint/formatcheck.py 2012-04-25 13:09:13 +0000
+++ pocketlint/formatcheck.py 2012-12-02 00:45:25 +0000
@@ -346,6 +346,12 @@
346 self.message(346 self.message(
347 line_no, 'Line contains a tab character.', icon='info')347 line_no, 'Line contains a tab character.', icon='info')
348348
349 def check_windows_endlines(self):
350 """Check that file does not contains Windows newlines."""
351 if self.text.find('\r\n') != -1:
352 self.message(
353 0, 'File contains Windows new lines.', icon='info')
354
349355
350class AnyTextChecker(BaseChecker, AnyTextMixin):356class AnyTextChecker(BaseChecker, AnyTextMixin):
351 """Verify the text of the document."""357 """Verify the text of the document."""
@@ -358,6 +364,8 @@
358 self.check_trailing_whitespace(line_no, line)364 self.check_trailing_whitespace(line_no, line)
359 self.check_conflicts(line_no, line)365 self.check_conflicts(line_no, line)
360366
367 self.check_windows_endlines()
368
361369
362class SQLChecker(BaseChecker, AnyTextMixin):370class SQLChecker(BaseChecker, AnyTextMixin):
363 """Verify SQL style."""371 """Verify SQL style."""
@@ -372,6 +380,8 @@
372 self.check_tab(line_no, line)380 self.check_tab(line_no, line)
373 self.check_conflicts(line_no, line)381 self.check_conflicts(line_no, line)
374382
383 self.check_windows_endlines()
384
375385
376class XMLChecker(BaseChecker, AnyTextMixin):386class XMLChecker(BaseChecker, AnyTextMixin):
377 """Check XML documents."""387 """Check XML documents."""
@@ -423,6 +433,7 @@
423 error_lineno = int(location.split(',')[0].split()[1]) - offset433 error_lineno = int(location.split(',')[0].split()[1]) - offset
424 self.message(error_lineno, error_message, icon='error')434 self.message(error_lineno, error_message, icon='error')
425 self.check_text()435 self.check_text()
436 self.check_windows_endlines()
426437
427 def check_text(self):438 def check_text(self):
428 for line_no, line in enumerate(self.text.splitlines()):439 for line_no, line in enumerate(self.text.splitlines()):
@@ -477,6 +488,7 @@
477488
478 self.check_cssutils()489 self.check_cssutils()
479 self.check_text()490 self.check_text()
491 self.check_windows_endlines()
480 # CSS coding conventoins checks should go last since they rely492 # CSS coding conventoins checks should go last since they rely
481 # on previous checks.493 # on previous checks.
482 self.check_css_coding_conventions()494 self.check_css_coding_conventions()
@@ -526,6 +538,7 @@
526 self.check_text()538 self.check_text()
527 self.check_flakes()539 self.check_flakes()
528 self.check_pep8()540 self.check_pep8()
541 self.check_windows_endlines()
529542
530 def check_flakes(self):543 def check_flakes(self):
531 """Check compilation and syntax."""544 """Check compilation and syntax."""
@@ -633,6 +646,7 @@
633 line_no -= 1646 line_no -= 1
634 self.message(line_no, message, icon='error')647 self.message(line_no, message, icon='error')
635 self.check_text()648 self.check_text()
649 self.check_windows_endlines()
636650
637 def check_debugger(self, line_no, line):651 def check_debugger(self, line_no, line):
638 """Check the length of the line."""652 """Check the length of the line."""
@@ -669,6 +683,7 @@
669 """Check the syntax of the reStructuredText code."""683 """Check the syntax of the reStructuredText code."""
670 self.check_lines()684 self.check_lines()
671 self.check_empty_last_line()685 self.check_empty_last_line()
686 self.check_windows_endlines()
672687
673 def check_lines(self):688 def check_lines(self):
674 """Call each line checker for each line in text."""689 """Call each line checker for each line in text."""
675690
=== modified file 'pocketlint/tests/test_text.py'
--- pocketlint/tests/test_text.py 2012-01-29 21:24:20 +0000
+++ pocketlint/tests/test_text.py 2012-12-02 00:45:25 +0000
@@ -75,3 +75,16 @@
75 self.assertEqual(75 self.assertEqual(
76 [(1, 'Line exceeds 49 characters.')],76 [(1, 'Line exceeds 49 characters.')],
77 self.reporter.messages)77 self.reporter.messages)
78
79 def test_windows_newlines(self):
80 """
81 Files with Windows newlines are reported with errors.
82 """
83 content = '\r\nbla\r\nbla\r\n'
84 checker = AnyTextChecker(
85 'bogus', content, self.reporter)
86 checker.check()
87 self.assertEqual(
88 [(0, 'File contains Windows new lines.')],
89 self.reporter.messages)
90 self.assertEqual(1, self.reporter.call_count)

Subscribers

People subscribed via source and target branches

to all changes: