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
=== modified file 'text_checker.py'
--- text_checker.py 2009-05-04 22:10:53 +0000
+++ text_checker.py 2010-12-13 14:45:14 +0000
@@ -41,6 +41,7 @@
41 self.tabs = {}41 self.tabs = {}
42 self.long_lines = {}42 self.long_lines = {}
43 self.no_newline_at_eof = []43 self.no_newline_at_eof = []
44 self.dos_linebreaks = {}
44 self.problems = {'warn':[], 'fail':[]}45 self.problems = {'warn':[], 'fail':[]}
4546
46 def _reset_actions(self):47 def _reset_actions(self):
@@ -50,6 +51,7 @@
50 self.no_newline_at_eof_action = 'ignore'51 self.no_newline_at_eof_action = 'ignore'
51 self.long_lines_action = 'ignore'52 self.long_lines_action = 'ignore'
52 self.long_line_length = DEFAULT_LONGLINE_LENGTH53 self.long_line_length = DEFAULT_LONGLINE_LENGTH
54 self.dos_linebreaks_action = 'ignore'
5355
54 def _push_file_line(self, dict_, fname, line_no):56 def _push_file_line(self, dict_, fname, line_no):
55 if fname not in dict_:57 if fname not in dict_:
@@ -77,7 +79,7 @@
77 self._reset_actions()79 self._reset_actions()
78 rules_seq = tuple(tree.iter_search_rules((path,),80 rules_seq = tuple(tree.iter_search_rules((path,),
79 pref_names=('trailing_whitespace', 'tabs', 'newline_at_eof',81 pref_names=('trailing_whitespace', 'tabs', 'newline_at_eof',
80 'long_lines', 'long_line_length'), **kwargs))[0]82 'long_lines', 'long_line_length', 'dos_linebreaks'), **kwargs))[0]
81 if len(rules_seq) >= 3:83 if len(rules_seq) >= 3:
82 self._set_action_val(rules_seq, 0, 'trailing_whitespace_action')84 self._set_action_val(rules_seq, 0, 'trailing_whitespace_action')
83 self._set_action_val(rules_seq, 1, 'tabs_action')85 self._set_action_val(rules_seq, 1, 'tabs_action')
@@ -85,6 +87,7 @@
85 self._set_action_val(rules_seq, 3, 'long_lines_action')87 self._set_action_val(rules_seq, 3, 'long_lines_action')
86 self._set_action_val(rules_seq, 4, 'long_line_length',88 self._set_action_val(rules_seq, 4, 'long_line_length',
87 convertion_function=int)89 convertion_function=int)
90 self._set_action_val(rules_seq, 5, 'dos_linebreaks_action')
88 return len(rules_seq) >= 391 return len(rules_seq) >= 3
8992
90 def check_coding_style(self, old_filename, oldlines, new_filename,93 def check_coding_style(self, old_filename, oldlines, new_filename,
@@ -105,6 +108,8 @@
105 line)108 line)
106 if '\t' in line:109 if '\t' in line:
107 self._push_file_line(self.tabs, new_filename, line_no)110 self._push_file_line(self.tabs, new_filename, line_no)
111 if '\r' in line:
112 self._push_file_line(self.dos_linebreaks, new_filename, line_no)
108 if trailing_ws_match:113 if trailing_ws_match:
109 line_content = trailing_ws_match.group(1)114 line_content = trailing_ws_match.group(1)
110 has_trailing_whitespace = bool(trailing_ws_match.group(3))115 has_trailing_whitespace = bool(trailing_ws_match.group(3))
@@ -154,6 +159,12 @@
154 "newline at the end:"159 "newline at the end:"
155 '\n %s'160 '\n %s'
156 % ('\n '.join(self.no_newline_at_eof)))161 % ('\n '.join(self.no_newline_at_eof)))
162 if self.dos_linebreaks:
163 self._append_problem(self.dos_linebreaks_action,
164 self._format_message(self.dos_linebreaks,
165 'DOS linebreaks was found in the following files:'
166 )
167 )
157 if _text_check_warn_only:168 if _text_check_warn_only:
158 self.problems['warn'].extend(self.problems['fail'])169 self.problems['warn'].extend(self.problems['fail'])
159 self.problems['fail'] = []170 self.problems['fail'] = []

Subscribers

People subscribed via source and target branches

to all changes: