Merge lp:~diego-biurrun/bzr-text-checker/dos-linebreaks into lp:bzr-text-checker

Proposed by Diego Biurrun
Status: Merged
Merged at revision: 47
Proposed branch: lp:~diego-biurrun/bzr-text-checker/dos-linebreaks
Merge into: lp:bzr-text-checker
Diff against target: 58 lines (+12/-1)
1 file modified
text_checker.py (+12/-1)
To merge this branch: bzr merge lp:~diego-biurrun/bzr-text-checker/dos-linebreaks
Reviewer Review Type Date Requested Status
Marius Kruger Approve
Review via email: mp+43519@code.launchpad.net

Description of the change

I stumbled across this plugin and extended it to cover DOS linebreaks, which are things that I like to avoid getting added to non-Windows projects.

I tested this branch, it works and performs as expected. However, this is my very first stab at hacking Python and was done as a quick hack by using copy and paste with (hopefully) appropriate changes. Please review it thoroughly.

To post a comment you must log in.
Revision history for this message
Marius Kruger (amanica) wrote :

Thanks for the patch, I'll look at it soon.
I'd like to add a test and make sure the configuration key names are
consistent with the core line-end filtering options before merging.

Revision history for this message
Diego Biurrun (diego-biurrun) wrote :

... ping ...

Could you look at this patch again and merge it or tell me what to fix please?

Revision history for this message
Marius Kruger (amanica) wrote :

I'm approving this since I did merge it into trunk for completeness, but I changed the workings quite a bit afterwards. The rule options are now more generic and is more like the core eol rules:
check_eol={ignore|warn|fail}
check_eol_type={crlf|lf} (fails if a line doesn't match)
I also added tests.
Any comments/suggestions welcome.
I intend to add some more minor features and release 0.4 .

review: Approve
Revision history for this message
Marius Kruger (amanica) wrote :

btw. thanks for the ping again, sorry for the delay, I'm just a bit busy

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'text_checker.py'
2--- text_checker.py 2009-05-04 22:10:53 +0000
3+++ text_checker.py 2010-12-13 14:45:14 +0000
4@@ -41,6 +41,7 @@
5 self.tabs = {}
6 self.long_lines = {}
7 self.no_newline_at_eof = []
8+ self.dos_linebreaks = {}
9 self.problems = {'warn':[], 'fail':[]}
10
11 def _reset_actions(self):
12@@ -50,6 +51,7 @@
13 self.no_newline_at_eof_action = 'ignore'
14 self.long_lines_action = 'ignore'
15 self.long_line_length = DEFAULT_LONGLINE_LENGTH
16+ self.dos_linebreaks_action = 'ignore'
17
18 def _push_file_line(self, dict_, fname, line_no):
19 if fname not in dict_:
20@@ -77,7 +79,7 @@
21 self._reset_actions()
22 rules_seq = tuple(tree.iter_search_rules((path,),
23 pref_names=('trailing_whitespace', 'tabs', 'newline_at_eof',
24- 'long_lines', 'long_line_length'), **kwargs))[0]
25+ 'long_lines', 'long_line_length', 'dos_linebreaks'), **kwargs))[0]
26 if len(rules_seq) >= 3:
27 self._set_action_val(rules_seq, 0, 'trailing_whitespace_action')
28 self._set_action_val(rules_seq, 1, 'tabs_action')
29@@ -85,6 +87,7 @@
30 self._set_action_val(rules_seq, 3, 'long_lines_action')
31 self._set_action_val(rules_seq, 4, 'long_line_length',
32 convertion_function=int)
33+ self._set_action_val(rules_seq, 5, 'dos_linebreaks_action')
34 return len(rules_seq) >= 3
35
36 def check_coding_style(self, old_filename, oldlines, new_filename,
37@@ -105,6 +108,8 @@
38 line)
39 if '\t' in line:
40 self._push_file_line(self.tabs, new_filename, line_no)
41+ if '\r' in line:
42+ self._push_file_line(self.dos_linebreaks, new_filename, line_no)
43 if trailing_ws_match:
44 line_content = trailing_ws_match.group(1)
45 has_trailing_whitespace = bool(trailing_ws_match.group(3))
46@@ -154,6 +159,12 @@
47 "newline at the end:"
48 '\n %s'
49 % ('\n '.join(self.no_newline_at_eof)))
50+ if self.dos_linebreaks:
51+ self._append_problem(self.dos_linebreaks_action,
52+ self._format_message(self.dos_linebreaks,
53+ 'DOS linebreaks was found in the following files:'
54+ )
55+ )
56 if _text_check_warn_only:
57 self.problems['warn'].extend(self.problems['fail'])
58 self.problems['fail'] = []

Subscribers

People subscribed via source and target branches

to all changes: