[MERGE] rip off the trailing whitespace band-aid

Marius Kruger amanic at gmail.com
Tue Jan 27 19:24:02 GMT 2009


2009/1/27 John Arbash Meinel <john at arbash-meinel.com>

> John Arbash Meinel has voted tweak.
> Status is now: Conditionally approved
> Comment:
> I think we should merge this, though do we want to wait until right after a
> release?
>
> Anyway, I don't see a test change that makes sure all files don't have
> whitespace, so I presume the only one is the test that makes sure that newly
> merged changes don't have whitespace, but we should change it to just check
> everything.


The proper test is there, maybe you looked in the wrong diff, see below.

2009/1/27 Martin Pool <mbp at sourcefrog.net>
> I think the "band-aid" subject is well chosen,

thats a quote from jam :)

and we might as well
> just do it now.  I don't think there is any time in the cycle when
> it's particularly convenient to get conflicts - but at the moment the
> merge queue is relatively small, and we're not immediately close to a
> release.
>

I also think you should merge this sooner rather than later.

--
*20090117_2357-bzr.code_style_cleanup.sourcetest-and-doc-updates.diff:*
def test_coding_style(self):
-        """ Check if bazaar code conforms to some coding style conventions.
+        """Check if bazaar code conforms to some coding style conventions.

-        Currently we check all .py files for:
-         * new trailing white space
-         * new leading tabs
-         * new long lines (give warning only)
+        Currently we check for:
+         * any tab characters
+         * trailing white space
+         * non-unix newlines
          * no newline at end of files
+         * lines longer than 79 chars
+           (only print how many files and lines are in violation)
         """
-        bzr_dir = osutils.dirname(self.get_bzrlib_dir())
-        try:
-            wt = WorkingTree.open(bzr_dir)
-        except:
-            raise TestSkipped(
-                'Could not open bazaar working tree %s'
-                % bzr_dir)
-        diff_output = StringIO()
-        wt.lock_read()
-        try:
-            new_tree = wt
-            old_tree = new_tree.basis_tree()
-
-            old_tree.lock_read()
-            new_tree.lock_read()
-            try:
-                iterator = new_tree.iter_changes(old_tree)
-                for (file_id, paths, changed_content, versioned, parent,
-                    name, kind, executable) in iterator:
-                    if (changed_content and paths[1].endswith('.py')):
-                        if kind == ('file', 'file'):
-                            diff_text = diff.DiffText(old_tree, new_tree,
-                                to_file=diff_output,
-                                text_differ=check_coding_style)
-                            diff_text.diff(file_id, paths[0], paths[1],
-                                kind[0], kind[1])
-                        else:
-                            check_coding_style(name[0], (), name[1],
-                                new_tree.get_file(file_id).readlines(),
-                                diff_output)
-            finally:
-                old_tree.unlock()
-                new_tree.unlock()
-        finally:
-            wt.unlock()
-        if len(diff_output.getvalue()) > 0:
-            self.fail("Unacceptable coding style:\n" +
diff_output.getvalue())
+        tabs = {}
+        trailing_ws = {}
+        illegal_newlines = {}
+        long_lines = {}
+        no_newline_at_eof = []
+        for fname, text in self.get_source_file_contents():
+            if not self.is_our_code(fname):
+                continue
+            lines = text.splitlines(True)
+            last_line_no = len(lines) - 1
+            for line_no, line in enumerate(lines):
+                if '\t' in line:
+                    self._push_file(tabs, fname, line_no)
+                if not line.endswith('\n') or line.endswith('\r\n'):
+                    if line_no != last_line_no: # not no_newline_at_eof
+                        self._push_file(illegal_newlines, fname, line_no)
+                if line.endswith(' \n'):
+                    self._push_file(trailing_ws, fname, line_no)
+                if len(line) > 80:
+                    self._push_file(long_lines, fname, line_no)
+            if not lines[-1].endswith('\n'):
+                no_newline_at_eof.append(fname)
+        problems = []
+        if tabs:
+            problems.append(self._format_message(tabs,
+                'Tab characters were found in the following source files.'
+                '\nThey should either be replaced by "\\t" or by spaces:'))
+        if trailing_ws:
+            problems.append(self._format_message(trailing_ws,
+                'Trailing white space was found in the following source
files:'
+                ))
+        if illegal_newlines:
+            problems.append(self._format_message(illegal_newlines,
+                'Non-unix newlines were found in the following source
files:'))
+        if long_lines:
+            print ("There are %i lines longer than 79 characters in %i
files."
+                % (sum([len(lines) for f, lines in long_lines.items()]),
+                    len(long_lines)))
+        if no_newline_at_eof:
+            no_newline_at_eof.sort()
+            problems.append("The following source files doesn't have a "
+                "newline at the end:"
+               '\n\n    %s'
+               % ('\n    '.join(no_newline_at_eof)))
+        if problems:
+            self.fail('\n\n'.join(problems))

thanks
marius
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ubuntu.com/archives/bazaar/attachments/20090127/7d277952/attachment.htm 


More information about the bazaar mailing list