Changeset 160319 in webkit


Ignore:
Timestamp:
Dec 9, 2013 11:01:09 AM (10 years ago)
Author:
commit-queue@webkit.org
Message:

check-webkit-style should check for extra newlines at EOF
https://bugs.webkit.org/show_bug.cgi?id=125424

Patch by Brian J. Burg <Brian Burg> on 2013-12-09
Reviewed by Darin Adler.

Report a style violation if extraneous newlines are added
to the end of a C++ file. There should only be one newline at EOF.

  • Scripts/webkitpy/style/checkers/cpp.py:

(check_for_missing_new_line_at_eof): Renamed from check_for_new_line_at_eof.
(check_for_extra_new_line_at_eof): Added.
(_process_lines): Added new check and renamed existing EOF check.

  • Scripts/webkitpy/style/checkers/cpp_unittest.py:

(CppStyleTest.test_extra_newlines_at_eof): Added.
(CppStyleTest.test_extra_newlines_at_eof.do_test): Added.

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r160318 r160319  
     12013-12-09  Brian J. Burg  <burg@cs.washington.edu>
     2
     3        check-webkit-style should check for extra newlines at EOF
     4        https://bugs.webkit.org/show_bug.cgi?id=125424
     5
     6        Reviewed by Darin Adler.
     7
     8        Report a style violation if extraneous newlines are added
     9        to the end of a C++ file. There should only be one newline at EOF.
     10
     11        * Scripts/webkitpy/style/checkers/cpp.py:
     12        (check_for_missing_new_line_at_eof): Renamed from check_for_new_line_at_eof.
     13        (check_for_extra_new_line_at_eof): Added.
     14        (_process_lines): Added new check and renamed existing EOF check.
     15        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
     16        (CppStyleTest.test_extra_newlines_at_eof): Added.
     17        (CppStyleTest.test_extra_newlines_at_eof.do_test): Added.
     18
    1192013-12-09  Laszlo Vidacs  <lac@inf.u-szeged.hu>
    220
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py

    r160318 r160319  
    958958
    959959
    960 def check_for_new_line_at_eof(lines, error):
    961     """Logs an error if there is no newline char at the end of the file.
     960def check_for_missing_new_line_at_eof(lines, error):
     961    """Logs an error if there is not a newline character at the end of the file.
    962962
    963963    Args:
     
    973973        error(len(lines) - 2, 'whitespace/ending_newline', 5,
    974974              'Could not find a newline character at the end of the file.')
     975
     976
     977def check_for_extra_new_line_at_eof(lines, error):
     978    """Logs an error if there is not a single newline at the end of the file.
     979
     980    Args:
     981      lines: An array of strings, each representing a line of the file.
     982      error: The function to call with any errors found.
     983    """
     984    # The array lines() was created by adding two newlines to the
     985    # original file (go figure), then splitting on \n.
     986    if len(lines) > 3 and not lines[-3]:
     987        error(len(lines) - 2, 'whitespace/ending_newline', 5,
     988              'There was more than one newline at the end of the file.')
    975989
    976990
     
    36363650    check_for_unicode_replacement_characters(lines, error)
    36373651
    3638     check_for_new_line_at_eof(lines, error)
     3652    check_for_missing_new_line_at_eof(lines, error)
     3653    check_for_extra_new_line_at_eof(lines, error)
    36393654
    36403655
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

    r160318 r160319  
    19381938        do_test(self, '// No newline\n// at EOF', True)
    19391939
     1940    def test_extra_newlines_at_eof(self):
     1941        def do_test(self, data, too_many_newlines):
     1942            error_collector = ErrorCollector(self.assertTrue)
     1943            self.process_file_data('foo.cpp', 'cpp', data.split('\n'),
     1944                                   error_collector)
     1945            # The warning appears only once.
     1946            self.assertEqual(
     1947                int(too_many_newlines),
     1948                error_collector.results().count(
     1949                    'There was more than one newline at the end of the file.'
     1950                    '  [whitespace/ending_newline] [5]'))
     1951
     1952        do_test(self, '// No Newline\n// at EOF', False)
     1953        do_test(self, '// One Newline\n// at EOF\n', False)
     1954        do_test(self, '// Two Newlines\n// at EOF\n\n', True)
     1955        do_test(self, '// Three Newlines\n// at EOF\n\n\n', True)
     1956
    19401957    def test_invalid_utf8(self):
    19411958        def do_test(self, raw_bytes, has_invalid_utf8):
Note: See TracChangeset for help on using the changeset viewer.