| OLD | NEW |
| 1 # -*- coding: utf-8; -*- | 1 # -*- coding: utf-8; -*- |
| 2 # | 2 # |
| 3 # Copyright (C) 2011 Google Inc. All rights reserved. | 3 # Copyright (C) 2011 Google Inc. All rights reserved. |
| 4 # Copyright (C) 2009 Torch Mobile Inc. | 4 # Copyright (C) 2009 Torch Mobile Inc. |
| 5 # Copyright (C) 2009 Apple Inc. All rights reserved. | 5 # Copyright (C) 2009 Apple Inc. All rights reserved. |
| 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 7 # | 7 # |
| 8 # Redistribution and use in source and binary forms, with or without | 8 # Redistribution and use in source and binary forms, with or without |
| 9 # modification, are permitted provided that the following conditions are | 9 # modification, are permitted provided that the following conditions are |
| 10 # met: | 10 # met: |
| (...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 Foo(int f); | 1185 Foo(int f); |
| 1186 };''', | 1186 };''', |
| 1187 'Single-argument constructors should be marked explicit.' | 1187 'Single-argument constructors should be marked explicit.' |
| 1188 ' [runtime/explicit] [5]') | 1188 ' [runtime/explicit] [5]') |
| 1189 # missing explicit is bad, even with whitespace | 1189 # missing explicit is bad, even with whitespace |
| 1190 self.assert_multi_line_lint( | 1190 self.assert_multi_line_lint( |
| 1191 '''\ | 1191 '''\ |
| 1192 class Foo { | 1192 class Foo { |
| 1193 Foo (int f); | 1193 Foo (int f); |
| 1194 };''', | 1194 };''', |
| 1195 ['Extra space before ( in function call [whitespace/parens] [4]', | 1195 'Single-argument constructors should be marked explicit.' |
| 1196 'Single-argument constructors should be marked explicit.' | 1196 ' [runtime/explicit] [5]') |
| 1197 ' [runtime/explicit] [5]']) | |
| 1198 # missing explicit, with distracting comment, is still bad | 1197 # missing explicit, with distracting comment, is still bad |
| 1199 self.assert_multi_line_lint( | 1198 self.assert_multi_line_lint( |
| 1200 '''\ | 1199 '''\ |
| 1201 class Foo { | 1200 class Foo { |
| 1202 Foo(int f); // simpler than Foo(blargh, blarg) | 1201 Foo(int f); // simpler than Foo(blargh, blarg) |
| 1203 };''', | 1202 };''', |
| 1204 'Single-argument constructors should be marked explicit.' | 1203 'Single-argument constructors should be marked explicit.' |
| 1205 ' [runtime/explicit] [5]') | 1204 ' [runtime/explicit] [5]') |
| 1206 # missing explicit, with qualified classname | 1205 # missing explicit, with qualified classname |
| 1207 self.assert_multi_line_lint( | 1206 self.assert_multi_line_lint( |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1434 self.assert_lint('char buf[somenamespace::kBufSize];', '') | 1433 self.assert_lint('char buf[somenamespace::kBufSize];', '') |
| 1435 self.assert_lint('int arrayName[ALL_CAPS];', '') | 1434 self.assert_lint('int arrayName[ALL_CAPS];', '') |
| 1436 self.assert_lint('AClass array1[foo::bar::ALL_CAPS];', '') | 1435 self.assert_lint('AClass array1[foo::bar::ALL_CAPS];', '') |
| 1437 self.assert_lint('int a[kMaxStrLen + 1];', '') | 1436 self.assert_lint('int a[kMaxStrLen + 1];', '') |
| 1438 self.assert_lint('int a[sizeof(foo)];', '') | 1437 self.assert_lint('int a[sizeof(foo)];', '') |
| 1439 self.assert_lint('int a[sizeof(*foo)];', '') | 1438 self.assert_lint('int a[sizeof(*foo)];', '') |
| 1440 self.assert_lint('int a[sizeof foo];', '') | 1439 self.assert_lint('int a[sizeof foo];', '') |
| 1441 self.assert_lint('int a[sizeof(struct Foo)];', '') | 1440 self.assert_lint('int a[sizeof(struct Foo)];', '') |
| 1442 self.assert_lint('int a[128 - sizeof(const bar)];', '') | 1441 self.assert_lint('int a[128 - sizeof(const bar)];', '') |
| 1443 self.assert_lint('int a[(sizeof(foo) * 4)];', '') | 1442 self.assert_lint('int a[(sizeof(foo) * 4)];', '') |
| 1444 self.assert_lint('int a[(arraysize(fixed_size_array)/2) << 1];', 'Missin
g spaces around / [whitespace/operators] [3]') | |
| 1445 self.assert_lint('delete a[some_var];', '') | 1443 self.assert_lint('delete a[some_var];', '') |
| 1446 self.assert_lint('return a[some_var];', '') | 1444 self.assert_lint('return a[some_var];', '') |
| 1447 | 1445 |
| 1448 # Brace usage | 1446 # Brace usage |
| 1449 def test_braces(self): | 1447 def test_braces(self): |
| 1450 # Braces shouldn't be followed by a ; unless they're defining a struct | 1448 # Braces shouldn't be followed by a ; unless they're defining a struct |
| 1451 # or initializing an array | 1449 # or initializing an array |
| 1452 self.assert_lint('int a[3] = { 1, 2, 3 };', '') | 1450 self.assert_lint('int a[3] = { 1, 2, 3 };', '') |
| 1453 self.assert_lint( | 1451 self.assert_lint( |
| 1454 '''\ | 1452 '''\ |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 ' [readability/check] [2]') | 1563 ' [readability/check] [2]') |
| 1566 | 1564 |
| 1567 self.assert_lint('CHECK(some_iterator == obj.end())', '') | 1565 self.assert_lint('CHECK(some_iterator == obj.end())', '') |
| 1568 self.assert_lint('EXPECT_TRUE(some_iterator == obj.end())', '') | 1566 self.assert_lint('EXPECT_TRUE(some_iterator == obj.end())', '') |
| 1569 self.assert_lint('EXPECT_FALSE(some_iterator == obj.end())', '') | 1567 self.assert_lint('EXPECT_FALSE(some_iterator == obj.end())', '') |
| 1570 | 1568 |
| 1571 self.assert_lint('CHECK(CreateTestFile(dir, (1 << 20)));', '') | 1569 self.assert_lint('CHECK(CreateTestFile(dir, (1 << 20)));', '') |
| 1572 self.assert_lint('CHECK(CreateTestFile(dir, (1 >> 20)));', '') | 1570 self.assert_lint('CHECK(CreateTestFile(dir, (1 >> 20)));', '') |
| 1573 | 1571 |
| 1574 self.assert_lint('CHECK(x<42)', | 1572 self.assert_lint('CHECK(x<42)', |
| 1575 ['Missing spaces around <' | 1573 'Consider using CHECK_LT instead of CHECK(a < b)' |
| 1576 ' [whitespace/operators] [3]', | 1574 ' [readability/check] [2]') |
| 1577 'Consider using CHECK_LT instead of CHECK(a < b)' | |
| 1578 ' [readability/check] [2]']) | |
| 1579 self.assert_lint('CHECK(x>42)', | 1575 self.assert_lint('CHECK(x>42)', |
| 1580 'Consider using CHECK_GT instead of CHECK(a > b)' | 1576 'Consider using CHECK_GT instead of CHECK(a > b)' |
| 1581 ' [readability/check] [2]') | 1577 ' [readability/check] [2]') |
| 1582 | 1578 |
| 1583 self.assert_lint( | 1579 self.assert_lint( |
| 1584 ' EXPECT_TRUE(42 < x) // Random comment.', | 1580 ' EXPECT_TRUE(42 < x) // Random comment.', |
| 1585 'Consider using EXPECT_LT instead of EXPECT_TRUE(a < b)' | 1581 'Consider using EXPECT_LT instead of EXPECT_TRUE(a < b)' |
| 1586 ' [readability/check] [2]') | 1582 ' [readability/check] [2]') |
| 1587 self.assert_lint( | 1583 self.assert_lint( |
| 1588 'EXPECT_TRUE( 42 < x )', | 1584 'EXPECT_TRUE( 42 < x )', |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1609 self.assert_lint('ASSERT_WITH_SECURITY_IMPLICATION(foo)', | 1605 self.assert_lint('ASSERT_WITH_SECURITY_IMPLICATION(foo)', |
| 1610 'ASSERT_WITH_SECURITY_IMPLICATION is deprecated. Use ' | 1606 'ASSERT_WITH_SECURITY_IMPLICATION is deprecated. Use ' |
| 1611 'SECURITY_DCHECK instead. [build/deprecated] [5]') | 1607 'SECURITY_DCHECK instead. [build/deprecated] [5]') |
| 1612 self.assert_lint('WTF_LOG(foo)', 'WTF_LOG is deprecated. Use DVLOG ' | 1608 self.assert_lint('WTF_LOG(foo)', 'WTF_LOG is deprecated. Use DVLOG ' |
| 1613 'instead. [build/deprecated] [5]') | 1609 'instead. [build/deprecated] [5]') |
| 1614 | 1610 |
| 1615 self.assert_lint('FOO_BAR_ASSERT()', '') | 1611 self.assert_lint('FOO_BAR_ASSERT()', '') |
| 1616 self.assert_lint('ASSERT_NO_EXCEPTIONS', '') | 1612 self.assert_lint('ASSERT_NO_EXCEPTIONS', '') |
| 1617 | 1613 |
| 1618 def test_brace_at_begin_of_line(self): | 1614 def test_brace_at_begin_of_line(self): |
| 1619 self.assert_lint('{', | |
| 1620 'This { should be at the end of the previous line' | |
| 1621 ' [whitespace/braces] [4]') | |
| 1622 self.assert_multi_line_lint( | 1615 self.assert_multi_line_lint( |
| 1623 '#endif\n' | 1616 '#endif\n' |
| 1624 '{\n' | 1617 '{\n' |
| 1625 '}\n', | 1618 '}\n', |
| 1626 '') | 1619 '') |
| 1627 self.assert_multi_line_lint( | 1620 self.assert_multi_line_lint( |
| 1628 'if (condition) {', | 1621 'if (condition) {', |
| 1629 '') | 1622 '') |
| 1630 self.assert_multi_line_lint( | 1623 self.assert_multi_line_lint( |
| 1631 ' MACRO1(macroArg) {', | 1624 ' MACRO1(macroArg) {', |
| 1632 '') | 1625 '') |
| 1633 self.assert_multi_line_lint( | 1626 self.assert_multi_line_lint( |
| 1634 'ACCESSOR_GETTER(MessageEventPorts) {', | |
| 1635 'Place brace on its own line for function definitions. [whitespace/
braces] [4]') | |
| 1636 self.assert_multi_line_lint( | |
| 1637 'int foo() {', | |
| 1638 'Place brace on its own line for function definitions. [whitespace/
braces] [4]') | |
| 1639 self.assert_multi_line_lint( | |
| 1640 'int foo() const {', | |
| 1641 'Place brace on its own line for function definitions. [whitespace/
braces] [4]') | |
| 1642 self.assert_multi_line_lint( | |
| 1643 'int foo() override {', | |
| 1644 'Place brace on its own line for function definitions. [whitespace/
braces] [4]') | |
| 1645 self.assert_multi_line_lint( | |
| 1646 'int foo() final {', | |
| 1647 'Place brace on its own line for function definitions. [whitespace/
braces] [4]') | |
| 1648 self.assert_multi_line_lint( | |
| 1649 'int foo() const\n' | 1627 'int foo() const\n' |
| 1650 '{\n' | 1628 '{\n' |
| 1651 '}\n', | 1629 '}\n', |
| 1652 '') | 1630 '') |
| 1653 self.assert_multi_line_lint( | 1631 self.assert_multi_line_lint( |
| 1654 'int foo() override\n' | 1632 'int foo() override\n' |
| 1655 '{\n' | 1633 '{\n' |
| 1656 '}\n', | 1634 '}\n', |
| 1657 '') | 1635 '') |
| 1658 self.assert_multi_line_lint( | 1636 self.assert_multi_line_lint( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1722 self.assert_lint('while (foo) {', '') | 1700 self.assert_lint('while (foo) {', '') |
| 1723 self.assert_lint('switch (foo) {', '') | 1701 self.assert_lint('switch (foo) {', '') |
| 1724 self.assert_lint('new (RenderArena()) RenderInline(document())', '') | 1702 self.assert_lint('new (RenderArena()) RenderInline(document())', '') |
| 1725 self.assert_lint('foo( bar)', 'Extra space after ( in function call' | 1703 self.assert_lint('foo( bar)', 'Extra space after ( in function call' |
| 1726 ' [whitespace/parens] [4]') | 1704 ' [whitespace/parens] [4]') |
| 1727 self.assert_lint('foobar( \\', '') | 1705 self.assert_lint('foobar( \\', '') |
| 1728 self.assert_lint('foobar( \\', '') | 1706 self.assert_lint('foobar( \\', '') |
| 1729 self.assert_lint('( a + b)', 'Extra space after (' | 1707 self.assert_lint('( a + b)', 'Extra space after (' |
| 1730 ' [whitespace/parens] [2]') | 1708 ' [whitespace/parens] [2]') |
| 1731 self.assert_lint('((a+b))', '') | 1709 self.assert_lint('((a+b))', '') |
| 1732 self.assert_lint('foo (foo)', 'Extra space before ( in function call' | |
| 1733 ' [whitespace/parens] [4]') | |
| 1734 self.assert_lint('#elif (foo(bar))', '') | 1710 self.assert_lint('#elif (foo(bar))', '') |
| 1735 self.assert_lint('#elif (foo(bar) && foo(baz))', '') | 1711 self.assert_lint('#elif (foo(bar) && foo(baz))', '') |
| 1736 self.assert_lint('typedef foo (*foo)(foo)', '') | 1712 self.assert_lint('typedef foo (*foo)(foo)', '') |
| 1737 self.assert_lint('typedef foo (*foo12bar_)(foo)', '') | 1713 self.assert_lint('typedef foo (*foo12bar_)(foo)', '') |
| 1738 self.assert_lint('typedef foo (Foo::*bar)(foo)', '') | 1714 self.assert_lint('typedef foo (Foo::*bar)(foo)', '') |
| 1739 self.assert_lint('foo (Foo::*bar)(', | |
| 1740 'Extra space before ( in function call' | |
| 1741 ' [whitespace/parens] [4]') | |
| 1742 self.assert_lint('typedef foo (Foo::*bar)(', '') | 1715 self.assert_lint('typedef foo (Foo::*bar)(', '') |
| 1743 self.assert_lint('(foo)(bar)', '') | 1716 self.assert_lint('(foo)(bar)', '') |
| 1744 self.assert_lint('Foo (*foo)(bar)', '') | 1717 self.assert_lint('Foo (*foo)(bar)', '') |
| 1745 self.assert_lint('Foo (*foo)(Bar bar,', '') | 1718 self.assert_lint('Foo (*foo)(Bar bar,', '') |
| 1746 self.assert_lint('char (*p)[sizeof(foo)] = &foo', '') | 1719 self.assert_lint('char (*p)[sizeof(foo)] = &foo', '') |
| 1747 self.assert_lint('char (&ref)[sizeof(foo)] = &foo', '') | 1720 self.assert_lint('char (&ref)[sizeof(foo)] = &foo', '') |
| 1748 self.assert_lint('const char32 (*table[])[6];', '') | 1721 self.assert_lint('const char32 (*table[])[6];', '') |
| 1749 | 1722 |
| 1750 def test_spacing_before_braces(self): | 1723 def test_spacing_before_braces(self): |
| 1751 self.assert_lint('if (foo){', 'Missing space before {' | |
| 1752 ' [whitespace/braces] [5]') | |
| 1753 self.assert_lint('for{', 'Missing space before {' | |
| 1754 ' [whitespace/braces] [5]') | |
| 1755 self.assert_lint('for {', '') | 1724 self.assert_lint('for {', '') |
| 1756 self.assert_lint('EXPECT_DEBUG_DEATH({', '') | 1725 self.assert_lint('EXPECT_DEBUG_DEATH({', '') |
| 1757 | 1726 |
| 1758 def test_spacing_between_braces(self): | 1727 def test_spacing_between_braces(self): |
| 1759 self.assert_lint(' { }', '') | 1728 self.assert_lint(' { }', '') |
| 1760 self.assert_lint(' {}', '') | 1729 self.assert_lint(' {}', '') |
| 1761 self.assert_lint(' { }', 'Too many spaces inside { }. [whitespace/
braces] [5]') | 1730 self.assert_lint(' { }', 'Too many spaces inside { }. [whitespace/
braces] [5]') |
| 1762 | 1731 |
| 1763 def test_spacing_around_else(self): | 1732 def test_spacing_around_else(self): |
| 1764 self.assert_lint('}else {', 'Missing space before else' | 1733 self.assert_lint('}else {', 'Missing space before else' |
| 1765 ' [whitespace/braces] [5]') | 1734 ' [whitespace/braces] [5]') |
| 1766 self.assert_lint('} else{', 'Missing space before {' | |
| 1767 ' [whitespace/braces] [5]') | |
| 1768 self.assert_lint('} else {', '') | 1735 self.assert_lint('} else {', '') |
| 1769 self.assert_lint('} else if', '') | 1736 self.assert_lint('} else if', '') |
| 1770 | 1737 |
| 1771 def test_spacing_for_binary_ops(self): | |
| 1772 self.assert_lint('if (foo<=bar) {', 'Missing spaces around <=' | |
| 1773 ' [whitespace/operators] [3]') | |
| 1774 self.assert_lint('if (foo<bar) {', 'Missing spaces around <' | |
| 1775 ' [whitespace/operators] [3]') | |
| 1776 self.assert_lint('if (foo<bar->baz) {', 'Missing spaces around <' | |
| 1777 ' [whitespace/operators] [3]') | |
| 1778 self.assert_lint('if (foo<bar->bar) {', 'Missing spaces around <' | |
| 1779 ' [whitespace/operators] [3]') | |
| 1780 self.assert_lint('typedef hash_map<Foo, Bar', 'Missing spaces around <' | |
| 1781 ' [whitespace/operators] [3]') | |
| 1782 self.assert_lint('typedef hash_map<FoooooType, BaaaaarType,', '') | |
| 1783 self.assert_lint('a<Foo> t+=b;', 'Missing spaces around +=' | |
| 1784 ' [whitespace/operators] [3]') | |
| 1785 self.assert_lint('a<Foo> t-=b;', 'Missing spaces around -=' | |
| 1786 ' [whitespace/operators] [3]') | |
| 1787 self.assert_lint('a<Foo*> t*=b;', 'Missing spaces around *=' | |
| 1788 ' [whitespace/operators] [3]') | |
| 1789 self.assert_lint('a<Foo*> t/=b;', 'Missing spaces around /=' | |
| 1790 ' [whitespace/operators] [3]') | |
| 1791 self.assert_lint('a<Foo*> t|=b;', 'Missing spaces around |=' | |
| 1792 ' [whitespace/operators] [3]') | |
| 1793 self.assert_lint('a<Foo*> t&=b;', 'Missing spaces around &=' | |
| 1794 ' [whitespace/operators] [3]') | |
| 1795 self.assert_lint('a<Foo*> t<<=b;', 'Missing spaces around <<=' | |
| 1796 ' [whitespace/operators] [3]') | |
| 1797 self.assert_lint('a<Foo*> t>>=b;', 'Missing spaces around >>=' | |
| 1798 ' [whitespace/operators] [3]') | |
| 1799 self.assert_lint('a<Foo*> t>>=&b|c;', 'Missing spaces around >>=' | |
| 1800 ' [whitespace/operators] [3]') | |
| 1801 self.assert_lint('a<Foo*> t<<=*b/c;', 'Missing spaces around <<=' | |
| 1802 ' [whitespace/operators] [3]') | |
| 1803 self.assert_lint('a<Foo> t -= b;', '') | |
| 1804 self.assert_lint('a<Foo> t += b;', '') | |
| 1805 self.assert_lint('a<Foo*> t *= b;', '') | |
| 1806 self.assert_lint('a<Foo*> t /= b;', '') | |
| 1807 self.assert_lint('a<Foo*> t |= b;', '') | |
| 1808 self.assert_lint('a<Foo*> t &= b;', '') | |
| 1809 self.assert_lint('a<Foo*> t <<= b;', '') | |
| 1810 self.assert_lint('a<Foo*> t >>= b;', '') | |
| 1811 self.assert_lint('a<Foo*>&& t = &b;', '') | |
| 1812 self.assert_lint('a<Foo*> t >>= &b|c;', 'Missing spaces around |' | |
| 1813 ' [whitespace/operators] [3]') | |
| 1814 self.assert_lint('a<Foo*> t <<= *b/c;', 'Missing spaces around /' | |
| 1815 ' [whitespace/operators] [3]') | |
| 1816 self.assert_lint('a<Foo*> t <<= b/c; //Test', [ | |
| 1817 'Should have a space between // and comment ' | |
| 1818 '[whitespace/comments] [4]', 'Missing' | |
| 1819 ' spaces around / [whitespace/operators] [3]']) | |
| 1820 self.assert_lint('a<Foo*> t <<= b||c; //Test', ['One space before end' | |
| 1821 ' of line comments [wh
itespace/comments] [5]', | |
| 1822 'Should have a space be
tween // and comment ' | |
| 1823 '[whitespace/comments]
[4]', | |
| 1824 'Missing spaces around
|| [whitespace/operators] [3]']) | |
| 1825 self.assert_lint('a<Foo*> t <<= b && *c; // Test', '') | |
| 1826 self.assert_lint('a<Foo*> t <<= b && &c; // Test', '') | |
| 1827 self.assert_lint('a<Foo*> t <<= b || &c; /*Test', 'Complex multi-line ' | |
| 1828 '/*...*/-style comment found. Lint may give bogus ' | |
| 1829 'warnings. Consider replacing these with //-style' | |
| 1830 ' comments, with #if 0...#endif, or with more clearly' | |
| 1831 ' structured multi-line comments. [readability/multili
ne_comment] [5]') | |
| 1832 self.assert_lint('a<Foo&> t <<= &b | &c;', '') | |
| 1833 self.assert_lint('a<Foo*> t <<= &b & &c; // Test', '') | |
| 1834 self.assert_lint('a<Foo*> t <<= *b / &c; // Test', '') | |
| 1835 self.assert_lint('if (a=b == 1)', 'Missing spaces around = [whitespace/
operators] [4]') | |
| 1836 self.assert_lint('a = 1<<20', 'Missing spaces around << [whitespace/ope
rators] [3]') | |
| 1837 self.assert_lint('a = 1>> 20', 'Missing spaces around >> [whitespace/op
erators] [3]') | |
| 1838 self.assert_lint('a = 1 >>20', 'Missing spaces around >> [whitespace/op
erators] [3]') | |
| 1839 self.assert_lint('a = 1>>20', 'Missing spaces around >> [whitespace/ope
rators] [3]') | |
| 1840 self.assert_lint('func(OwnPtr<Vector<Foo>>)', '') | |
| 1841 self.assert_lint('func(OwnPtr<Vector<Foo>> foo)', '') | |
| 1842 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar>>>)', '') | |
| 1843 self.assert_lint('func(OwnPtr<Vector<Foo> >)', | |
| 1844 'Use >> for ending template instead of > >. [readabili
ty/templatebrackets] [3]') | |
| 1845 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar>> >)', | |
| 1846 'Use >> for ending template instead of > >. [readabili
ty/templatebrackets] [3]') | |
| 1847 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar> >>)', | |
| 1848 'Use >> for ending template instead of > >. [readabili
ty/templatebrackets] [3]') | |
| 1849 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar> > >)', | |
| 1850 'Use >> for ending template instead of > >. [readabili
ty/templatebrackets] [3]') | |
| 1851 self.assert_lint('Vector< ::Foo>)', 'Use <:: for template start instead
of < ::. [readability/templatebrackets] [3]') | |
| 1852 self.assert_lint('Vector<Vector< ::Foo>>)', | |
| 1853 'Use <:: for template start instead of < ::. [readabil
ity/templatebrackets] [3]') | |
| 1854 # FIXME: The following test should not show any error. | |
| 1855 self.assert_lint('func(OwnPtr<HashMap<Foo, Member<Bar\n >>>)', | |
| 1856 'Missing spaces around < [whitespace/operators] [3]') | |
| 1857 self.assert_lint('if (a = b == 1)', '') | |
| 1858 self.assert_lint('a = 1 << 20', '') | |
| 1859 self.assert_multi_line_lint('#include <sys/io.h>\n', '') | |
| 1860 self.assert_multi_line_lint('#import <foo/bar.h>\n', '') | |
| 1861 | |
| 1862 def test_operator_methods(self): | 1738 def test_operator_methods(self): |
| 1863 self.assert_lint('String operator+(const String&, const String&);', '') | 1739 self.assert_lint('String operator+(const String&, const String&);', '') |
| 1864 self.assert_lint('String operator/(const String&, const String&);', '') | 1740 self.assert_lint('String operator/(const String&, const String&);', '') |
| 1865 self.assert_lint('bool operator==(const String&, const String&);', '') | 1741 self.assert_lint('bool operator==(const String&, const String&);', '') |
| 1866 self.assert_lint('String& operator-=(const String&, const String&);', ''
) | 1742 self.assert_lint('String& operator-=(const String&, const String&);', ''
) |
| 1867 self.assert_lint('String& operator+=(const String&, const String&);', ''
) | 1743 self.assert_lint('String& operator+=(const String&, const String&);', ''
) |
| 1868 self.assert_lint('String& operator*=(const String&, const String&);', ''
) | 1744 self.assert_lint('String& operator*=(const String&, const String&);', ''
) |
| 1869 self.assert_lint('String& operator%=(const String&, const String&);', ''
) | 1745 self.assert_lint('String& operator%=(const String&, const String&);', ''
) |
| 1870 self.assert_lint('String& operator&=(const String&, const String&);', ''
) | 1746 self.assert_lint('String& operator&=(const String&, const String&);', ''
) |
| 1871 self.assert_lint('String& operator<<=(const String&, const String&);', '
') | 1747 self.assert_lint('String& operator<<=(const String&, const String&);', '
') |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1947 self.assert_lint('TellStory(1, 3);', | 1823 self.assert_lint('TellStory(1, 3);', |
| 1948 '') | 1824 '') |
| 1949 self.assert_lint('TellStory(1, 3 );', | 1825 self.assert_lint('TellStory(1, 3 );', |
| 1950 'Extra space before )' | 1826 'Extra space before )' |
| 1951 ' [whitespace/parens] [2]') | 1827 ' [whitespace/parens] [2]') |
| 1952 self.assert_lint('TellStory(1 /* wolf */, 3 /* pigs */);', | 1828 self.assert_lint('TellStory(1 /* wolf */, 3 /* pigs */);', |
| 1953 '') | 1829 '') |
| 1954 self.assert_multi_line_lint('#endif\n );', | 1830 self.assert_multi_line_lint('#endif\n );', |
| 1955 '') | 1831 '') |
| 1956 | 1832 |
| 1957 def test_one_spaces_between_code_and_comments(self): | |
| 1958 self.assert_lint('} // namespace foo', | |
| 1959 '') | |
| 1960 self.assert_lint('}// namespace foo', | |
| 1961 'One space before end of line comments' | |
| 1962 ' [whitespace/comments] [5]') | |
| 1963 self.assert_lint('printf("foo"); // Outside quotes.', | |
| 1964 '') | |
| 1965 self.assert_lint('int i = 0; // Having one space is fine.', '') | |
| 1966 self.assert_lint('int i = 0; // Having two spaces is bad.', | |
| 1967 'One space before end of line comments' | |
| 1968 ' [whitespace/comments] [5]') | |
| 1969 self.assert_lint('int i = 0; // Having three spaces is bad.', | |
| 1970 'One space before end of line comments' | |
| 1971 ' [whitespace/comments] [5]') | |
| 1972 self.assert_lint('// Top level comment', '') | |
| 1973 self.assert_lint(' // Line starts with four spaces.', '') | |
| 1974 self.assert_lint('foo();\n' | |
| 1975 '{ // A scope is opening.', '') | |
| 1976 self.assert_lint(' foo();\n' | |
| 1977 ' { // An indented scope is opening.', '') | |
| 1978 self.assert_lint('if (foo) { // not a pure scope', | |
| 1979 '') | |
| 1980 self.assert_lint('printf("// In quotes.")', '') | |
| 1981 self.assert_lint('printf("\\"%s // In quotes.")', '') | |
| 1982 self.assert_lint('printf("%s", "// In quotes.")', '') | |
| 1983 | |
| 1984 def test_line_ending_in_whitespace(self): | 1833 def test_line_ending_in_whitespace(self): |
| 1985 self.assert_lint('int a; // This is a sentence.', | 1834 self.assert_lint('int a; // This is a sentence.', |
| 1986 '') | 1835 '') |
| 1987 self.assert_lint('int a; // This is a sentence. ', | 1836 self.assert_lint('int a; // This is a sentence. ', |
| 1988 'Line ends in whitespace. Consider deleting these extr
a spaces. [whitespace/end_of_line] [4]') | 1837 'Line ends in whitespace. Consider deleting these extr
a spaces. [whitespace/end_of_line] [4]') |
| 1989 | 1838 |
| 1990 def test_space_after_comment_marker(self): | |
| 1991 self.assert_lint('//', '') | |
| 1992 self.assert_lint('//x', 'Should have a space between // and comment' | |
| 1993 ' [whitespace/comments] [4]') | |
| 1994 self.assert_lint('// x', '') | |
| 1995 self.assert_lint('//----', '') | |
| 1996 self.assert_lint('//====', '') | |
| 1997 self.assert_lint('//////', '') | |
| 1998 self.assert_lint('////// x', '') | |
| 1999 self.assert_lint('/// x', '') | |
| 2000 self.assert_lint('////x', 'Should have a space between // and comment' | |
| 2001 ' [whitespace/comments] [4]') | |
| 2002 | |
| 2003 def test_newline_at_eof(self): | 1839 def test_newline_at_eof(self): |
| 2004 def do_test(self, data, is_missing_eof): | 1840 def do_test(self, data, is_missing_eof): |
| 2005 error_collector = ErrorCollector(self.assertTrue) | 1841 error_collector = ErrorCollector(self.assertTrue) |
| 2006 self.process_file_data('foo.cpp', 'cpp', data.split('\n'), | 1842 self.process_file_data('foo.cpp', 'cpp', data.split('\n'), |
| 2007 error_collector) | 1843 error_collector) |
| 2008 # The warning appears only once. | 1844 # The warning appears only once. |
| 2009 self.assertEqual( | 1845 self.assertEqual( |
| 2010 int(is_missing_eof), | 1846 int(is_missing_eof), |
| 2011 error_collector.results().count( | 1847 error_collector.results().count( |
| 2012 'Could not find a newline character at the end of the file.' | 1848 'Could not find a newline character at the end of the file.' |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 def test_else_on_same_line_as_closing_braces(self): | 1916 def test_else_on_same_line_as_closing_braces(self): |
| 2081 error_collector = ErrorCollector(self.assertTrue) | 1917 error_collector = ErrorCollector(self.assertTrue) |
| 2082 self.process_file_data('foo.cpp', 'cpp', | 1918 self.process_file_data('foo.cpp', 'cpp', |
| 2083 ['if (hoge) {', | 1919 ['if (hoge) {', |
| 2084 '', | 1920 '', |
| 2085 '}', | 1921 '}', |
| 2086 ' else {' # Warning on this line | 1922 ' else {' # Warning on this line |
| 2087 '', | 1923 '', |
| 2088 '}'], | 1924 '}'], |
| 2089 error_collector) | 1925 error_collector) |
| 2090 self.assertEqual(1, error_collector.results().count( | |
| 2091 'An else should appear on the same line as the preceding }' | |
| 2092 ' [whitespace/newline] [4]')) | |
| 2093 | 1926 |
| 2094 def test_else_clause_not_on_same_line_as_else(self): | 1927 def test_else_clause_not_on_same_line_as_else(self): |
| 2095 self.assert_lint(' else DoSomethingElse();', | |
| 2096 'Else clause should never be on same line as else ' | |
| 2097 '(use 2 lines) [whitespace/newline] [4]') | |
| 2098 self.assert_lint(' else ifDoSomethingElse();', | |
| 2099 'Else clause should never be on same line as else ' | |
| 2100 '(use 2 lines) [whitespace/newline] [4]') | |
| 2101 self.assert_lint(' else if (blah) {', '') | 1928 self.assert_lint(' else if (blah) {', '') |
| 2102 self.assert_lint(' variable_ends_in_else = true;', '') | 1929 self.assert_lint(' variable_ends_in_else = true;', '') |
| 2103 | 1930 |
| 2104 def test_comma(self): | 1931 def test_comma(self): |
| 2105 self.assert_lint('a = f(1,2);', | 1932 self.assert_lint('a = f(1,2);', |
| 2106 'Missing space after , [whitespace/comma] [3]') | 1933 'Missing space after , [whitespace/comma] [3]') |
| 2107 self.assert_lint('int tmp=a,a=b,b=tmp;', | 1934 self.assert_lint('int tmp=a,a=b,b=tmp;', |
| 2108 ['Missing spaces around = [whitespace/operators] [4]', | 1935 ['Missing spaces around = [whitespace/operators] [4]', |
| 2109 'Missing space after , [whitespace/comma] [3]']) | 1936 'Missing space after , [whitespace/comma] [3]']) |
| 2110 self.assert_lint('f(a, /* name */ b);', '') | 1937 self.assert_lint('f(a, /* name */ b);', '') |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2127 self.assert_lint('int *b;', '', 'foo.c') | 1954 self.assert_lint('int *b;', '', 'foo.c') |
| 2128 self.assert_lint('int* b;', | 1955 self.assert_lint('int* b;', |
| 2129 'Declaration has space between * and variable name in i
nt* b [whitespace/declaration] [3]', | 1956 'Declaration has space between * and variable name in i
nt* b [whitespace/declaration] [3]', |
| 2130 'foo.c') | 1957 'foo.c') |
| 2131 self.assert_lint('int& b;', '', 'foo.cpp') | 1958 self.assert_lint('int& b;', '', 'foo.cpp') |
| 2132 self.assert_lint('int &b;', | 1959 self.assert_lint('int &b;', |
| 2133 'Declaration has space between type name and & in int &
b [whitespace/declaration] [3]', | 1960 'Declaration has space between type name and & in int &
b [whitespace/declaration] [3]', |
| 2134 'foo.cpp') | 1961 'foo.cpp') |
| 2135 self.assert_lint('return &b;', '', 'foo.cpp') | 1962 self.assert_lint('return &b;', '', 'foo.cpp') |
| 2136 | 1963 |
| 2137 def test_indent(self): | |
| 2138 self.assert_lint('static int noindent;', '') | |
| 2139 self.assert_lint(' int fourSpaceIndent;', '') | |
| 2140 self.assert_lint(' int oneSpaceIndent;', | |
| 2141 'Weird number of spaces at line-start. ' | |
| 2142 'Are you using a 4-space indent? [whitespace/indent] [
3]') | |
| 2143 self.assert_lint(' int threeSpaceIndent;', | |
| 2144 'Weird number of spaces at line-start. ' | |
| 2145 'Are you using a 4-space indent? [whitespace/indent] [
3]') | |
| 2146 self.assert_lint(' char* oneSpaceIndent = "public:";', | |
| 2147 'Weird number of spaces at line-start. ' | |
| 2148 'Are you using a 4-space indent? [whitespace/indent] [
3]') | |
| 2149 self.assert_lint(' public:', | |
| 2150 'Weird number of spaces at line-start. ' | |
| 2151 'Are you using a 4-space indent? [whitespace/indent] [
3]') | |
| 2152 self.assert_lint(' public:', | |
| 2153 'Weird number of spaces at line-start. ' | |
| 2154 'Are you using a 4-space indent? [whitespace/indent] [
3]') | |
| 2155 self.assert_lint(' public:', | |
| 2156 'Weird number of spaces at line-start. ' | |
| 2157 'Are you using a 4-space indent? [whitespace/indent] [
3]') | |
| 2158 self.assert_multi_line_lint( | |
| 2159 'class Foo {\n' | |
| 2160 'public:\n' | |
| 2161 ' enum Bar {\n' | |
| 2162 ' Alpha,\n' | |
| 2163 ' Beta,\n' | |
| 2164 '#if ENABLED_BETZ\n' | |
| 2165 ' Charlie,\n' | |
| 2166 '#endif\n' | |
| 2167 ' };\n' | |
| 2168 '};', | |
| 2169 '') | |
| 2170 self.assert_multi_line_lint( | |
| 2171 'if (true) {\n' | |
| 2172 ' myFunction(reallyLongParam1, reallyLongParam2,\n' | |
| 2173 ' reallyLongParam3);\n' | |
| 2174 '}\n', | |
| 2175 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') | |
| 2176 | |
| 2177 self.assert_multi_line_lint( | |
| 2178 'if (true) {\n' | |
| 2179 ' myFunction(reallyLongParam1, reallyLongParam2,\n' | |
| 2180 ' reallyLongParam3);\n' | |
| 2181 '}\n', | |
| 2182 'When wrapping a line, only indent 4 spaces. [whitespace/indent] [3
]') | |
| 2183 | |
| 2184 def test_not_alabel(self): | 1964 def test_not_alabel(self): |
| 2185 self.assert_lint('MyVeryLongNamespace::MyVeryLongClassName::', '') | 1965 self.assert_lint('MyVeryLongNamespace::MyVeryLongClassName::', '') |
| 2186 | 1966 |
| 2187 def test_tab(self): | 1967 def test_tab(self): |
| 2188 self.assert_lint('\tint a;', | 1968 self.assert_lint('\tint a;', |
| 2189 'Tab found; better to use spaces [whitespace/tab] [1]'
) | 1969 'Tab found; better to use spaces [whitespace/tab] [1]'
) |
| 2190 self.assert_lint('int a = 5;\t// set a to 5', | 1970 self.assert_lint('int a = 5;\t// set a to 5', |
| 2191 'Tab found; better to use spaces [whitespace/tab] [1]'
) | 1971 'Tab found; better to use spaces [whitespace/tab] [1]'
) |
| 2192 | 1972 |
| 2193 def test_unnamed_namespaces_in_headers(self): | 1973 def test_unnamed_namespaces_in_headers(self): |
| (...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3414 '') | 3194 '') |
| 3415 | 3195 |
| 3416 self.assert_multi_line_lint( | 3196 self.assert_multi_line_lint( |
| 3417 '''\ | 3197 '''\ |
| 3418 class Foo::Goo { | 3198 class Foo::Goo { |
| 3419 virtual ~Goo(); | 3199 virtual ~Goo(); |
| 3420 virtual void goo(); | 3200 virtual void goo(); |
| 3421 };''', | 3201 };''', |
| 3422 '') | 3202 '') |
| 3423 self.assert_multi_line_lint( | 3203 self.assert_multi_line_lint( |
| 3424 'class Foo { void foo(); };', | |
| 3425 'More than one command on the same line [whitespace/newline] [4]') | |
| 3426 self.assert_multi_line_lint( | |
| 3427 'class MyClass {\n' | 3204 'class MyClass {\n' |
| 3428 ' int getIntValue() { DCHECK(m_ptr); return *m_ptr; }\n' | 3205 ' int getIntValue() { DCHECK(m_ptr); return *m_ptr; }\n' |
| 3429 '};\n', | 3206 '};\n', |
| 3430 '') | 3207 '') |
| 3431 self.assert_multi_line_lint( | |
| 3432 'class MyClass {\n' | |
| 3433 ' int getIntValue()\n' | |
| 3434 ' {\n' | |
| 3435 ' DCHECK(m_ptr); return *m_ptr;\n' | |
| 3436 ' }\n' | |
| 3437 '};\n', | |
| 3438 'More than one command on the same line [whitespace/newline] [4]') | |
| 3439 | 3208 |
| 3440 self.assert_multi_line_lint( | 3209 self.assert_multi_line_lint( |
| 3441 '''\ | 3210 '''\ |
| 3442 class Qualified::Goo : public Foo { | 3211 class Qualified::Goo : public Foo { |
| 3443 virtual void goo(); | 3212 virtual void goo(); |
| 3444 };''', | 3213 };''', |
| 3445 '') | 3214 '') |
| 3446 | 3215 |
| 3447 def test_no_destructor_when_virtual_needed(self): | 3216 def test_no_destructor_when_virtual_needed(self): |
| 3448 self.assert_multi_line_lint_re( | 3217 self.assert_multi_line_lint_re( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3555 };''', | 3324 };''', |
| 3556 '') | 3325 '') |
| 3557 | 3326 |
| 3558 def test_multi_line_declaration_with_error(self): | 3327 def test_multi_line_declaration_with_error(self): |
| 3559 self.assert_multi_line_lint( | 3328 self.assert_multi_line_lint( |
| 3560 '''\ | 3329 '''\ |
| 3561 class Foo | 3330 class Foo |
| 3562 { | 3331 { |
| 3563 virtual void foo(); | 3332 virtual void foo(); |
| 3564 };''', | 3333 };''', |
| 3565 ['This { should be at the end of the previous line ' | 3334 'The class Foo probably needs a virtual destructor due to having ' |
| 3566 '[whitespace/braces] [4]', | 3335 'virtual method(s), one declared at line 3. [runtime/virtual] [4]') |
| 3567 'The class Foo probably needs a virtual destructor due to having ' | |
| 3568 'virtual method(s), one declared at line 3. [runtime/virtual] [4]'
]) | |
| 3569 | 3336 |
| 3570 | 3337 |
| 3571 class PassPtrTest(CppStyleTestBase): | 3338 class PassPtrTest(CppStyleTestBase): |
| 3572 # For http://webkit.org/coding/RefPtr.html | 3339 # For http://webkit.org/coding/RefPtr.html |
| 3573 | 3340 |
| 3574 def assert_pass_ptr_check(self, code, expected_message): | 3341 def assert_pass_ptr_check(self, code, expected_message): |
| 3575 """Check warnings for Pass*Ptr are as expected. | 3342 """Check warnings for Pass*Ptr are as expected. |
| 3576 | 3343 |
| 3577 Args: | 3344 Args: |
| 3578 code: C++ source code expected to generate a warning message. | 3345 code: C++ source code expected to generate a warning message. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3749 '\tint goo;\n' | 3516 '\tint goo;\n' |
| 3750 '};', | 3517 '};', |
| 3751 'Tab found; better to use spaces [whitespace/tab] [1]') | 3518 'Tab found; better to use spaces [whitespace/tab] [1]') |
| 3752 | 3519 |
| 3753 # 2. The indent size is 4 spaces. | 3520 # 2. The indent size is 4 spaces. |
| 3754 self.assert_multi_line_lint( | 3521 self.assert_multi_line_lint( |
| 3755 'class Foo {\n' | 3522 'class Foo {\n' |
| 3756 ' int goo;\n' | 3523 ' int goo;\n' |
| 3757 '};', | 3524 '};', |
| 3758 '') | 3525 '') |
| 3759 self.assert_multi_line_lint( | |
| 3760 'class Foo {\n' | |
| 3761 ' int goo;\n' | |
| 3762 '};', | |
| 3763 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') | |
| 3764 | 3526 |
| 3765 # 3. In a header, code inside a namespace should not be indented. | 3527 # 3. In a header, code inside a namespace should not be indented. |
| 3766 self.assert_multi_line_lint( | 3528 self.assert_multi_line_lint( |
| 3767 'namespace WebCore {\n\n' | 3529 'namespace WebCore {\n\n' |
| 3768 'class Document {\n' | 3530 'class Document {\n' |
| 3769 ' int myVariable;\n' | 3531 ' int myVariable;\n' |
| 3770 '};\n' | 3532 '};\n' |
| 3771 '}', | 3533 '}', |
| 3772 '', | 3534 '', |
| 3773 'foo.h') | 3535 'foo.h') |
| 3774 self.assert_multi_line_lint( | 3536 self.assert_multi_line_lint( |
| 3775 'namespace OuterNamespace {\n' | |
| 3776 ' namespace InnerNamespace {\n' | |
| 3777 ' class Document {\n' | |
| 3778 '};\n' | |
| 3779 '};\n' | |
| 3780 '}', | |
| 3781 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3782 'foo.h') | |
| 3783 self.assert_multi_line_lint( | |
| 3784 'namespace OuterNamespace {\n' | |
| 3785 ' class Document {\n' | |
| 3786 ' namespace InnerNamespace {\n' | |
| 3787 '};\n' | |
| 3788 '};\n' | |
| 3789 '}', | |
| 3790 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3791 'foo.h') | |
| 3792 self.assert_multi_line_lint( | |
| 3793 'namespace WebCore {\n' | |
| 3794 '#if 0\n' | |
| 3795 ' class Document {\n' | |
| 3796 '};\n' | |
| 3797 '#endif\n' | |
| 3798 '}', | |
| 3799 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3800 'foo.h') | |
| 3801 self.assert_multi_line_lint( | |
| 3802 'namespace WebCore {\n' | 3537 'namespace WebCore {\n' |
| 3803 'class Document {\n' | 3538 'class Document {\n' |
| 3804 '};\n' | 3539 '};\n' |
| 3805 '}', | 3540 '}', |
| 3806 '', | 3541 '', |
| 3807 'foo.h') | 3542 'foo.h') |
| 3808 | 3543 |
| 3809 # 4. In an implementation file (files with the extension .cpp, .c | 3544 # 4. In an implementation file (files with the extension .cpp, .c |
| 3810 # or .mm), code inside a namespace should not be indented. | 3545 # or .mm), code inside a namespace should not be indented. |
| 3811 self.assert_multi_line_lint( | 3546 self.assert_multi_line_lint( |
| 3812 'namespace WebCore {\n\n' | 3547 'namespace WebCore {\n\n' |
| 3813 'Document::Foo()\n' | 3548 'Document::Foo()\n' |
| 3814 ' : foo(bar)\n' | 3549 ' : foo(bar)\n' |
| 3815 ' , boo(far)\n' | 3550 ' , boo(far)\n' |
| 3816 '{\n' | 3551 '{\n' |
| 3817 ' stuff();\n' | 3552 ' stuff();\n' |
| 3818 '}', | 3553 '}', |
| 3819 '', | 3554 '', |
| 3820 'foo.cpp') | 3555 'foo.cpp') |
| 3821 self.assert_multi_line_lint( | 3556 self.assert_multi_line_lint( |
| 3822 'namespace OuterNamespace {\n' | |
| 3823 'namespace InnerNamespace {\n' | |
| 3824 'Document::Foo() { }\n' | |
| 3825 ' void* p;\n' | |
| 3826 '}\n' | |
| 3827 '}\n', | |
| 3828 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3829 'foo.cpp') | |
| 3830 self.assert_multi_line_lint( | |
| 3831 'namespace OuterNamespace {\n' | |
| 3832 'namespace InnerNamespace {\n' | |
| 3833 'Document::Foo() { }\n' | |
| 3834 '}\n' | |
| 3835 ' void* p;\n' | |
| 3836 '}\n', | |
| 3837 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3838 'foo.cpp') | |
| 3839 self.assert_multi_line_lint( | |
| 3840 'namespace WebCore {\n\n' | |
| 3841 ' const char* foo = "start:;"\n' | |
| 3842 ' "dfsfsfs";\n' | |
| 3843 '}\n', | |
| 3844 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3845 'foo.cpp') | |
| 3846 self.assert_multi_line_lint( | |
| 3847 'namespace WebCore {\n\n' | |
| 3848 'const char* foo(void* a = ";", // ;\n' | |
| 3849 ' void* b);\n' | |
| 3850 ' void* p;\n' | |
| 3851 '}\n', | |
| 3852 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3853 'foo.cpp') | |
| 3854 self.assert_multi_line_lint( | |
| 3855 'namespace WebCore {\n\n' | |
| 3856 'const char* foo[] = {\n' | |
| 3857 ' "void* b);", // ;\n' | |
| 3858 ' "asfdf",\n' | |
| 3859 ' }\n' | |
| 3860 ' void* p;\n' | |
| 3861 '}\n', | |
| 3862 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3863 'foo.cpp') | |
| 3864 self.assert_multi_line_lint( | |
| 3865 'namespace WebCore {\n\n' | 3557 'namespace WebCore {\n\n' |
| 3866 'const char* foo[] = {\n' | 3558 'const char* foo[] = {\n' |
| 3867 ' "void* b);", // }\n' | 3559 ' "void* b);", // }\n' |
| 3868 ' "asfdf",\n' | 3560 ' "asfdf",\n' |
| 3869 ' }\n' | 3561 ' }\n' |
| 3870 '}\n', | 3562 '}\n', |
| 3871 '', | 3563 '', |
| 3872 'foo.cpp') | 3564 'foo.cpp') |
| 3873 self.assert_multi_line_lint( | 3565 self.assert_multi_line_lint( |
| 3874 ' namespace WebCore {\n\n' | 3566 ' namespace WebCore {\n\n' |
| 3875 ' void Document::Foo()\n' | 3567 ' void Document::Foo()\n' |
| 3876 ' {\n' | 3568 ' {\n' |
| 3877 'start: // infinite loops are fun!\n' | 3569 'start: // infinite loops are fun!\n' |
| 3878 ' goto start;\n' | 3570 ' goto start;\n' |
| 3879 ' }', | 3571 ' }', |
| 3880 'namespace should never be indented. [whitespace/indent] [4]', | 3572 'namespace should never be indented. [whitespace/indent] [4]', |
| 3881 'foo.cpp') | 3573 'foo.cpp') |
| 3882 self.assert_multi_line_lint( | 3574 self.assert_multi_line_lint( |
| 3883 'namespace WebCore {\n' | 3575 'namespace WebCore {\n' |
| 3884 ' Document::Foo() { }\n' | |
| 3885 '}', | |
| 3886 'Code inside a namespace should not be indented.' | |
| 3887 ' [whitespace/indent] [4]', | |
| 3888 'foo.cpp') | |
| 3889 self.assert_multi_line_lint( | |
| 3890 'namespace WebCore {\n' | |
| 3891 '#define abc(x) x; \\\n' | 3576 '#define abc(x) x; \\\n' |
| 3892 ' x\n' | 3577 ' x\n' |
| 3893 '}', | 3578 '}', |
| 3894 '', | 3579 '', |
| 3895 'foo.cpp') | 3580 'foo.cpp') |
| 3896 self.assert_multi_line_lint( | |
| 3897 'namespace WebCore {\n' | |
| 3898 '#define abc(x) x; \\\n' | |
| 3899 ' x\n' | |
| 3900 ' void* x;' | |
| 3901 '}', | |
| 3902 'Code inside a namespace should not be indented. [whitespace/indent
] [4]', | |
| 3903 'foo.cpp') | |
| 3904 | 3581 |
| 3905 # 5. A case label should line up with its switch statement. The | 3582 # 5. A case label should line up with its switch statement. The |
| 3906 # case statement is indented. | 3583 # case statement is indented. |
| 3907 self.assert_multi_line_lint( | 3584 self.assert_multi_line_lint( |
| 3908 ' switch (condition) {\n' | 3585 ' switch (condition) {\n' |
| 3909 ' case fooCondition:\n' | 3586 ' case fooCondition:\n' |
| 3910 ' case barCondition:\n' | 3587 ' case barCondition:\n' |
| 3911 ' i++;\n' | 3588 ' i++;\n' |
| 3912 ' break;\n' | 3589 ' break;\n' |
| 3913 ' default:\n' | 3590 ' default:\n' |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3924 ' default:\n' | 3601 ' default:\n' |
| 3925 ' i--;\n' | 3602 ' i--;\n' |
| 3926 ' }\n', | 3603 ' }\n', |
| 3927 '') | 3604 '') |
| 3928 self.assert_multi_line_lint( | 3605 self.assert_multi_line_lint( |
| 3929 ' switch (condition) {\n' | 3606 ' switch (condition) {\n' |
| 3930 ' case fooCondition: break;\n' | 3607 ' case fooCondition: break;\n' |
| 3931 ' default: return;\n' | 3608 ' default: return;\n' |
| 3932 ' }\n', | 3609 ' }\n', |
| 3933 '') | 3610 '') |
| 3934 self.assert_multi_line_lint( | |
| 3935 ' switch (condition) {\n' | |
| 3936 ' case fooCondition:\n' | |
| 3937 ' case barCondition:\n' | |
| 3938 ' i++;\n' | |
| 3939 ' break;\n' | |
| 3940 ' default:\n' | |
| 3941 ' i--;\n' | |
| 3942 ' }\n', | |
| 3943 'A case label should not be indented, but line up with its switch st
atement.' | |
| 3944 ' [whitespace/indent] [4]') | |
| 3945 self.assert_multi_line_lint( | |
| 3946 ' switch (condition) {\n' | |
| 3947 ' case fooCondition:\n' | |
| 3948 ' break;\n' | |
| 3949 ' default:\n' | |
| 3950 ' i--;\n' | |
| 3951 ' }\n', | |
| 3952 'A case label should not be indented, but line up with its switch st
atement.' | |
| 3953 ' [whitespace/indent] [4]') | |
| 3954 self.assert_multi_line_lint( | |
| 3955 ' switch (condition) {\n' | |
| 3956 ' case fooCondition:\n' | |
| 3957 ' case barCondition:\n' | |
| 3958 ' switch (otherCondition) {\n' | |
| 3959 ' default:\n' | |
| 3960 ' return;\n' | |
| 3961 ' }\n' | |
| 3962 ' default:\n' | |
| 3963 ' i--;\n' | |
| 3964 ' }\n', | |
| 3965 'A case label should not be indented, but line up with its switch st
atement.' | |
| 3966 ' [whitespace/indent] [4]') | |
| 3967 self.assert_multi_line_lint( | |
| 3968 ' switch (condition) {\n' | |
| 3969 ' case fooCondition:\n' | |
| 3970 ' case barCondition:\n' | |
| 3971 ' i++;\n' | |
| 3972 ' break;\n\n' | |
| 3973 ' default:\n' | |
| 3974 ' i--;\n' | |
| 3975 ' }\n', | |
| 3976 'Non-label code inside switch statements should be indented.' | |
| 3977 ' [whitespace/indent] [4]') | |
| 3978 self.assert_multi_line_lint( | |
| 3979 ' switch (condition) {\n' | |
| 3980 ' case fooCondition:\n' | |
| 3981 ' case barCondition:\n' | |
| 3982 ' switch (otherCondition) {\n' | |
| 3983 ' default:\n' | |
| 3984 ' return;\n' | |
| 3985 ' }\n' | |
| 3986 ' default:\n' | |
| 3987 ' i--;\n' | |
| 3988 ' }\n', | |
| 3989 'Non-label code inside switch statements should be indented.' | |
| 3990 ' [whitespace/indent] [4]') | |
| 3991 | 3611 |
| 3992 # 6. Boolean expressions at the same nesting level that span | 3612 # 6. Boolean expressions at the same nesting level that span |
| 3993 # multiple lines should have their operators on the left side of | 3613 # multiple lines should have their operators on the left side of |
| 3994 # the line instead of the right side. | 3614 # the line instead of the right side. |
| 3995 self.assert_multi_line_lint( | 3615 self.assert_multi_line_lint( |
| 3996 ' return attr->name() == srcAttr\n' | 3616 ' return attr->name() == srcAttr\n' |
| 3997 ' || attr->name() == lowsrcAttr;\n', | 3617 ' || attr->name() == lowsrcAttr;\n', |
| 3998 '') | 3618 '') |
| 3999 self.assert_multi_line_lint( | |
| 4000 ' return attr->name() == srcAttr ||\n' | |
| 4001 ' attr->name() == lowsrcAttr;\n', | |
| 4002 'Boolean expressions that span multiple lines should have their ' | |
| 4003 'operators on the left side of the line instead of the right side.' | |
| 4004 ' [whitespace/operators] [4]') | |
| 4005 | 3619 |
| 4006 def test_spacing(self): | 3620 def test_spacing(self): |
| 4007 # 1. Do not place spaces around unary operators. | 3621 # 1. Do not place spaces around unary operators. |
| 4008 self.assert_multi_line_lint( | 3622 self.assert_multi_line_lint( |
| 4009 'i++;', | 3623 'i++;', |
| 4010 '') | 3624 '') |
| 4011 self.assert_multi_line_lint( | 3625 self.assert_multi_line_lint( |
| 4012 'i ++;', | 3626 'i ++;', |
| 4013 'Extra space for operator ++; [whitespace/operators] [4]') | 3627 'Extra space for operator ++; [whitespace/operators] [4]') |
| 4014 | 3628 |
| 4015 # 2. Do place spaces around binary and ternary operators. | 3629 # 2. Do place spaces around binary and ternary operators. |
| 4016 self.assert_multi_line_lint( | 3630 self.assert_multi_line_lint( |
| 4017 'y = m * x + b;', | 3631 'y = m * x + b;', |
| 4018 '') | 3632 '') |
| 4019 self.assert_multi_line_lint( | 3633 self.assert_multi_line_lint( |
| 4020 'f(a, b);', | 3634 'f(a, b);', |
| 4021 '') | 3635 '') |
| 4022 self.assert_multi_line_lint( | 3636 self.assert_multi_line_lint( |
| 4023 'c = a | b;', | 3637 'c = a | b;', |
| 4024 '') | 3638 '') |
| 4025 self.assert_multi_line_lint( | 3639 self.assert_multi_line_lint( |
| 4026 'return condition ? 1 : 0;', | 3640 'return condition ? 1 : 0;', |
| 4027 '') | 3641 '') |
| 4028 self.assert_multi_line_lint( | 3642 self.assert_multi_line_lint( |
| 4029 'y=m*x+b;', | 3643 'y=m*x+b;', |
| 4030 'Missing spaces around = [whitespace/operators] [4]') | 3644 'Missing spaces around = [whitespace/operators] [4]') |
| 4031 self.assert_multi_line_lint( | 3645 self.assert_multi_line_lint( |
| 4032 'f(a,b);', | 3646 'f(a,b);', |
| 4033 'Missing space after , [whitespace/comma] [3]') | 3647 'Missing space after , [whitespace/comma] [3]') |
| 4034 self.assert_multi_line_lint( | |
| 4035 'c = a|b;', | |
| 4036 'Missing spaces around | [whitespace/operators] [3]') | |
| 4037 # FIXME: We cannot catch this lint error. | 3648 # FIXME: We cannot catch this lint error. |
| 4038 # self.assert_multi_line_lint( | 3649 # self.assert_multi_line_lint( |
| 4039 # 'return condition ? 1:0;', | 3650 # 'return condition ? 1:0;', |
| 4040 # '') | 3651 # '') |
| 4041 | 3652 |
| 4042 # 3. Place spaces between control statements and their parentheses. | 3653 # 3. Place spaces between control statements and their parentheses. |
| 4043 self.assert_multi_line_lint( | 3654 self.assert_multi_line_lint( |
| 4044 ' if (condition)\n' | 3655 ' if (condition)\n' |
| 4045 ' doIt();\n', | 3656 ' doIt();\n', |
| 4046 '') | 3657 '') |
| 4047 self.assert_multi_line_lint( | 3658 self.assert_multi_line_lint( |
| 4048 ' if(condition)\n' | 3659 ' if(condition)\n' |
| 4049 ' doIt();\n', | 3660 ' doIt();\n', |
| 4050 'Missing space before ( in if( [whitespace/parens] [5]') | 3661 'Missing space before ( in if( [whitespace/parens] [5]') |
| 4051 | 3662 |
| 4052 # 4. Do not place spaces between a function and its parentheses, | 3663 # 4. Do not place spaces between a function and its parentheses, |
| 4053 # or between a parenthesis and its content. | 3664 # or between a parenthesis and its content. |
| 4054 self.assert_multi_line_lint( | 3665 self.assert_multi_line_lint( |
| 4055 'f(a, b);', | 3666 'f(a, b);', |
| 4056 '') | 3667 '') |
| 4057 self.assert_multi_line_lint( | 3668 self.assert_multi_line_lint( |
| 4058 'f (a, b);', | |
| 4059 'Extra space before ( in function call [whitespace/parens] [4]') | |
| 4060 self.assert_multi_line_lint( | |
| 4061 'f( a, b );', | 3669 'f( a, b );', |
| 4062 ['Extra space after ( in function call [whitespace/parens] [4]', | 3670 ['Extra space after ( in function call [whitespace/parens] [4]', |
| 4063 'Extra space before ) [whitespace/parens] [2]']) | 3671 'Extra space before ) [whitespace/parens] [2]']) |
| 4064 | 3672 |
| 4065 def test_line_breaking(self): | 3673 def test_line_breaking(self): |
| 4066 # 1. Each statement should get its own line. | 3674 # 1. Each statement should get its own line. |
| 4067 self.assert_multi_line_lint( | 3675 self.assert_multi_line_lint( |
| 4068 ' x++;\n' | 3676 ' x++;\n' |
| 4069 ' y++;\n' | 3677 ' y++;\n' |
| 4070 ' if (condition);\n' | 3678 ' if (condition);\n' |
| 4071 ' doIt();\n', | 3679 ' doIt();\n', |
| 4072 '') | 3680 '') |
| 4073 self.assert_multi_line_lint( | 3681 self.assert_multi_line_lint( |
| 4074 ' if (condition) \\\n' | 3682 ' if (condition) \\\n' |
| 4075 ' doIt();\n', | 3683 ' doIt();\n', |
| 4076 '') | 3684 '') |
| 4077 self.assert_multi_line_lint( | 3685 self.assert_multi_line_lint( |
| 4078 ' x++; y++;', | |
| 4079 'More than one command on the same line [whitespace/newline] [4]') | |
| 4080 self.assert_multi_line_lint( | |
| 4081 ' if (condition) doIt();\n', | 3686 ' if (condition) doIt();\n', |
| 4082 'More than one command on the same line in if [whitespace/parens] [
4]') | 3687 'More than one command on the same line in if [whitespace/parens] [
4]') |
| 4083 # Ensure that having a # in the line doesn't hide the error. | |
| 4084 self.assert_multi_line_lint( | |
| 4085 ' x++; char a[] = "#";', | |
| 4086 'More than one command on the same line [whitespace/newline] [4]') | |
| 4087 # Ignore preprocessor if's. | 3688 # Ignore preprocessor if's. |
| 4088 self.assert_multi_line_lint( | 3689 self.assert_multi_line_lint( |
| 4089 '#if (condition) || (condition2)\n', | 3690 '#if (condition) || (condition2)\n', |
| 4090 '') | 3691 '') |
| 4091 | 3692 |
| 4092 # 2. An else statement should go on the same line as a preceding | 3693 # 2. An else statement should go on the same line as a preceding |
| 4093 # close brace if one is present, else it should line up with the | 3694 # close brace if one is present, else it should line up with the |
| 4094 # if statement. | 3695 # if statement. |
| 4095 self.assert_multi_line_lint( | 3696 self.assert_multi_line_lint( |
| 4096 'if (condition) {\n' | 3697 'if (condition) {\n' |
| (...skipping 26 matching lines...) Expand all Loading... |
| 4123 self.assert_multi_line_lint( | 3724 self.assert_multi_line_lint( |
| 4124 '#define TEST_ASSERT(expression) do { if ( !(expression)) { ' | 3725 '#define TEST_ASSERT(expression) do { if ( !(expression)) { ' |
| 4125 'TestsController::shared().testFailed(__FILE__, __LINE__, #expressio
n); ' | 3726 'TestsController::shared().testFailed(__FILE__, __LINE__, #expressio
n); ' |
| 4126 'return; } } while (0)\n', | 3727 'return; } } while (0)\n', |
| 4127 'Extra space after ( in if [whitespace/parens] [5]') | 3728 'Extra space after ( in if [whitespace/parens] [5]') |
| 4128 # FIXME: currently we only check first conditional, so we cannot detect
errors in next ones. | 3729 # FIXME: currently we only check first conditional, so we cannot detect
errors in next ones. |
| 4129 self.assert_multi_line_lint( | 3730 self.assert_multi_line_lint( |
| 4130 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n', | 3731 'WTF_MAKE_NONCOPYABLE(ClassName); WTF_MAKE_FAST_ALLOCATED;\n', |
| 4131 '') | 3732 '') |
| 4132 self.assert_multi_line_lint( | 3733 self.assert_multi_line_lint( |
| 4133 'if (condition) {\n' | |
| 4134 ' doSomething();\n' | |
| 4135 ' doSomethingAgain();\n' | |
| 4136 '}\n' | |
| 4137 'else {\n' | |
| 4138 ' doSomethingElse();\n' | |
| 4139 ' doSomethingElseAgain();\n' | |
| 4140 '}\n', | |
| 4141 'An else should appear on the same line as the preceding } [whitesp
ace/newline] [4]') | |
| 4142 self.assert_multi_line_lint( | |
| 4143 'if (condition) doSomething(); else doSomethingElse();\n', | 3734 'if (condition) doSomething(); else doSomethingElse();\n', |
| 4144 ['More than one command on the same line [whitespace/newline] [4]', | 3735 'More than one command on the same line in if [whitespace/parens] [
4]') |
| 4145 'Else clause should never be on same line as else (use 2 lines) [w
hitespace/newline] [4]', | |
| 4146 'More than one command on the same line in if [whitespace/parens]
[4]']) | |
| 4147 self.assert_multi_line_lint( | 3736 self.assert_multi_line_lint( |
| 4148 'if (condition) doSomething(); else {\n' | 3737 'if (condition) doSomething(); else {\n' |
| 4149 ' doSomethingElse();\n' | 3738 ' doSomethingElse();\n' |
| 4150 '}\n', | 3739 '}\n', |
| 4151 ['More than one command on the same line in if [whitespace/parens]
[4]', | 3740 ['More than one command on the same line in if [whitespace/parens]
[4]', |
| 4152 'If one part of an if-else statement uses curly braces, the other p
art must too. [whitespace/braces] [4]']) | 3741 'If one part of an if-else statement uses curly braces, the other p
art must too. [whitespace/braces] [4]']) |
| 4153 self.assert_multi_line_lint( | 3742 self.assert_multi_line_lint( |
| 4154 'void func()\n' | 3743 'void func()\n' |
| 4155 '{\n' | 3744 '{\n' |
| 4156 ' while (condition) { }\n' | 3745 ' while (condition) { }\n' |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4232 ' [readability/control_flow] [4]']) | 3821 ' [readability/control_flow] [4]']) |
| 4233 self.assert_multi_line_lint( | 3822 self.assert_multi_line_lint( |
| 4234 'if (liquid)\n' | 3823 'if (liquid)\n' |
| 4235 '{\n' | 3824 '{\n' |
| 4236 ' prepare();\n' | 3825 ' prepare();\n' |
| 4237 ' return money;\n' | 3826 ' return money;\n' |
| 4238 '}\n' | 3827 '}\n' |
| 4239 'else if (greedy)\n' | 3828 'else if (greedy)\n' |
| 4240 ' keep();\n', | 3829 ' keep();\n', |
| 4241 ['If one part of an if-else statement uses curly braces, the other p
art must too. [whitespace/braces] [4]', | 3830 ['If one part of an if-else statement uses curly braces, the other p
art must too. [whitespace/braces] [4]', |
| 4242 'This { should be at the end of the previous line [whitespace/brac
es] [4]', | |
| 4243 'An else should appear on the same line as the preceding } [whites
pace/newline] [4]', | |
| 4244 'An else if statement should be written as an if statement when the
' | 3831 'An else if statement should be written as an if statement when the
' |
| 4245 'prior "if" concludes with a return, break, continue or goto statem
ent.' | 3832 'prior "if" concludes with a return, break, continue or goto statem
ent.' |
| 4246 ' [readability/control_flow] [4]']) | 3833 ' [readability/control_flow] [4]']) |
| 4247 self.assert_multi_line_lint( | 3834 self.assert_multi_line_lint( |
| 4248 'if (gone)\n' | 3835 'if (gone)\n' |
| 4249 ' return;\n' | 3836 ' return;\n' |
| 4250 'else if (here)\n' | 3837 'else if (here)\n' |
| 4251 ' go();\n', | 3838 ' go();\n', |
| 4252 'An else if statement should be written as an if statement when the
' | 3839 'An else if statement should be written as an if statement when the
' |
| 4253 'prior "if" concludes with a return, break, continue or goto stateme
nt.' | 3840 'prior "if" concludes with a return, break, continue or goto stateme
nt.' |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4284 ' [readability/control_flow] [4]']) | 3871 ' [readability/control_flow] [4]']) |
| 4285 | 3872 |
| 4286 def test_braces(self): | 3873 def test_braces(self): |
| 4287 # 1. Function definitions: place each brace on its own line. | 3874 # 1. Function definitions: place each brace on its own line. |
| 4288 self.assert_multi_line_lint( | 3875 self.assert_multi_line_lint( |
| 4289 'int main()\n' | 3876 'int main()\n' |
| 4290 '{\n' | 3877 '{\n' |
| 4291 ' doSomething();\n' | 3878 ' doSomething();\n' |
| 4292 '}\n', | 3879 '}\n', |
| 4293 '') | 3880 '') |
| 4294 self.assert_multi_line_lint( | |
| 4295 'int main() {\n' | |
| 4296 ' doSomething();\n' | |
| 4297 '}\n', | |
| 4298 'Place brace on its own line for function definitions. [whitespace/
braces] [4]') | |
| 4299 | 3881 |
| 4300 # 2. Other braces: place the open brace on the line preceding the | 3882 # 2. Other braces: place the open brace on the line preceding the |
| 4301 # code block; place the close brace on its own line. | 3883 # code block; place the close brace on its own line. |
| 4302 self.assert_multi_line_lint( | 3884 self.assert_multi_line_lint( |
| 4303 'class MyClass {\n' | 3885 'class MyClass {\n' |
| 4304 ' int foo;\n' | 3886 ' int foo;\n' |
| 4305 '};\n', | 3887 '};\n', |
| 4306 '') | 3888 '') |
| 4307 self.assert_multi_line_lint( | 3889 self.assert_multi_line_lint( |
| 4308 'namespace WebCore {\n' | 3890 'namespace WebCore {\n' |
| 4309 'int foo;\n' | 3891 'int foo;\n' |
| 4310 '};\n', | 3892 '};\n', |
| 4311 '') | 3893 '') |
| 4312 self.assert_multi_line_lint( | 3894 self.assert_multi_line_lint( |
| 4313 'for (int i = 0; i < 10; i++) {\n' | 3895 'for (int i = 0; i < 10; i++) {\n' |
| 4314 ' DoSomething();\n' | 3896 ' DoSomething();\n' |
| 4315 '};\n', | 3897 '};\n', |
| 4316 '') | 3898 '') |
| 4317 self.assert_multi_line_lint( | |
| 4318 'class MyClass\n' | |
| 4319 '{\n' | |
| 4320 ' int foo;\n' | |
| 4321 '};\n', | |
| 4322 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4323 self.assert_multi_line_lint( | |
| 4324 'if (condition)\n' | |
| 4325 '{\n' | |
| 4326 ' int foo;\n' | |
| 4327 '}\n', | |
| 4328 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4329 self.assert_multi_line_lint( | |
| 4330 'for (int i = 0; i < 10; i++)\n' | |
| 4331 '{\n' | |
| 4332 ' int foo;\n' | |
| 4333 '}\n', | |
| 4334 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4335 self.assert_multi_line_lint( | |
| 4336 'while (true)\n' | |
| 4337 '{\n' | |
| 4338 ' int foo;\n' | |
| 4339 '}\n', | |
| 4340 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4341 self.assert_multi_line_lint( | |
| 4342 'foreach (Foo* foo, foos)\n' | |
| 4343 '{\n' | |
| 4344 ' int bar;\n' | |
| 4345 '}\n', | |
| 4346 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4347 self.assert_multi_line_lint( | |
| 4348 'switch (type)\n' | |
| 4349 '{\n' | |
| 4350 'case foo: return;\n' | |
| 4351 '}\n', | |
| 4352 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4353 self.assert_multi_line_lint( | |
| 4354 'if (condition)\n' | |
| 4355 '{\n' | |
| 4356 ' int foo;\n' | |
| 4357 '}\n', | |
| 4358 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4359 self.assert_multi_line_lint( | |
| 4360 'for (int i = 0; i < 10; i++)\n' | |
| 4361 '{\n' | |
| 4362 ' int foo;\n' | |
| 4363 '}\n', | |
| 4364 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4365 self.assert_multi_line_lint( | |
| 4366 'while (true)\n' | |
| 4367 '{\n' | |
| 4368 ' int foo;\n' | |
| 4369 '}\n', | |
| 4370 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4371 self.assert_multi_line_lint( | |
| 4372 'switch (type)\n' | |
| 4373 '{\n' | |
| 4374 'case foo: return;\n' | |
| 4375 '}\n', | |
| 4376 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4377 self.assert_multi_line_lint( | |
| 4378 'else if (type)\n' | |
| 4379 '{\n' | |
| 4380 'case foo: return;\n' | |
| 4381 '}\n', | |
| 4382 'This { should be at the end of the previous line [whitespace/brace
s] [4]') | |
| 4383 | 3899 |
| 4384 # 3. Curly braces are not required for single-line conditionals and | 3900 # 3. Curly braces are not required for single-line conditionals and |
| 4385 # loop bodies, but are required for single-statement bodies that | 3901 # loop bodies, but are required for single-statement bodies that |
| 4386 # span multiple lines. | 3902 # span multiple lines. |
| 4387 | 3903 |
| 4388 # | 3904 # |
| 4389 # Positive tests | 3905 # Positive tests |
| 4390 # | 3906 # |
| 4391 self.assert_multi_line_lint( | 3907 self.assert_multi_line_lint( |
| 4392 'if (condition1)\n' | 3908 'if (condition1)\n' |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4612 ' doSomething3();\n' | 4128 ' doSomething3();\n' |
| 4613 ' doSomething3_2();\n' | 4129 ' doSomething3_2();\n' |
| 4614 '}\n', | 4130 '}\n', |
| 4615 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') | 4131 'If one part of an if-else statement uses curly braces, the other pa
rt must too. [whitespace/braces] [4]') |
| 4616 | 4132 |
| 4617 # 5. Control clauses without a body should use empty braces. | 4133 # 5. Control clauses without a body should use empty braces. |
| 4618 self.assert_multi_line_lint( | 4134 self.assert_multi_line_lint( |
| 4619 'for ( ; current; current = current->next) { }\n', | 4135 'for ( ; current; current = current->next) { }\n', |
| 4620 '') | 4136 '') |
| 4621 self.assert_multi_line_lint( | 4137 self.assert_multi_line_lint( |
| 4622 'for ( ; current;\n' | |
| 4623 ' current = current->next) { }\n', | |
| 4624 'Weird number of spaces at line-start. Are you using a 4-space inde
nt? [whitespace/indent] [3]') | |
| 4625 self.assert_multi_line_lint( | |
| 4626 'for ( ; current; current = current->next);\n', | 4138 'for ( ; current; current = current->next);\n', |
| 4627 'Semicolon defining empty statement for this loop. Use { } instead.
[whitespace/semicolon] [5]') | 4139 'Semicolon defining empty statement for this loop. Use { } instead.
[whitespace/semicolon] [5]') |
| 4628 self.assert_multi_line_lint( | 4140 self.assert_multi_line_lint( |
| 4629 'while (true);\n', | 4141 'while (true);\n', |
| 4630 'Semicolon defining empty statement for this loop. Use { } instead.
[whitespace/semicolon] [5]') | 4142 'Semicolon defining empty statement for this loop. Use { } instead.
[whitespace/semicolon] [5]') |
| 4631 self.assert_multi_line_lint( | 4143 self.assert_multi_line_lint( |
| 4632 '} while (true);\n', | 4144 '} while (true);\n', |
| 4633 '') | 4145 '') |
| 4634 | 4146 |
| 4635 def test_null_false_zero(self): | 4147 def test_null_false_zero(self): |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4819 self.assert_lint( | 4331 self.assert_lint( |
| 4820 'if (0.5 == (a - b))', | 4332 'if (0.5 == (a - b))', |
| 4821 '') | 4333 '') |
| 4822 self.assert_lint( | 4334 self.assert_lint( |
| 4823 'if (LIKELY(foo == NULL))', | 4335 'if (LIKELY(foo == NULL))', |
| 4824 'Use 0 instead of NULL. [readability/null] [5]') | 4336 'Use 0 instead of NULL. [readability/null] [5]') |
| 4825 self.assert_lint( | 4337 self.assert_lint( |
| 4826 'if (UNLIKELY(foo == NULL))', | 4338 'if (UNLIKELY(foo == NULL))', |
| 4827 'Use 0 instead of NULL. [readability/null] [5]') | 4339 'Use 0 instead of NULL. [readability/null] [5]') |
| 4828 | 4340 |
| 4829 def test_directive_indentation(self): | |
| 4830 self.assert_lint( | |
| 4831 " #if FOO", | |
| 4832 "preprocessor directives (e.g., #ifdef, #define, #import) should nev
er be indented." | |
| 4833 " [whitespace/indent] [4]", | |
| 4834 "foo.cpp") | |
| 4835 | |
| 4836 def test_using_std(self): | 4341 def test_using_std(self): |
| 4837 self.assert_lint( | 4342 self.assert_lint( |
| 4838 'using std::min;', | 4343 'using std::min;', |
| 4839 "Use 'using namespace std;' instead of 'using std::min;'." | 4344 "Use 'using namespace std;' instead of 'using std::min;'." |
| 4840 " [build/using_std] [4]", | 4345 " [build/using_std] [4]", |
| 4841 'foo.cpp') | 4346 'foo.cpp') |
| 4842 | 4347 |
| 4843 def test_using_std_swap_ignored(self): | 4348 def test_using_std_swap_ignored(self): |
| 4844 self.assert_lint( | 4349 self.assert_lint( |
| 4845 'using std::swap;', | 4350 'using std::swap;', |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5143 self.perform_lint('void setNateLateCount(size_t elate);', 'test.cpp'
, parameter_error_rules)) | 4648 self.perform_lint('void setNateLateCount(size_t elate);', 'test.cpp'
, parameter_error_rules)) |
| 5144 self.assertEqual( | 4649 self.assertEqual( |
| 5145 '', | 4650 '', |
| 5146 self.perform_lint('void funct(NateLate elate);', 'test.cpp', paramet
er_error_rules)) | 4651 self.perform_lint('void funct(NateLate elate);', 'test.cpp', paramet
er_error_rules)) |
| 5147 | 4652 |
| 5148 # Don't have generate warnings for functions (only declarations). | 4653 # Don't have generate warnings for functions (only declarations). |
| 5149 self.assertEqual( | 4654 self.assertEqual( |
| 5150 '', | 4655 '', |
| 5151 self.perform_lint('void funct(PassRefPtr<ScriptExecutionContext> con
text)\n{\n}\n', 'test.cpp', parameter_error_rules)) | 4656 self.perform_lint('void funct(PassRefPtr<ScriptExecutionContext> con
text)\n{\n}\n', 'test.cpp', parameter_error_rules)) |
| 5152 | 4657 |
| 5153 def test_comments(self): | |
| 5154 # A comment at the beginning of a line is ok. | |
| 5155 self.assert_lint('// comment', '') | |
| 5156 self.assert_lint(' // comment', '') | |
| 5157 | |
| 5158 self.assert_lint('} // namespace WebCore', | |
| 5159 'One space before end of line comments' | |
| 5160 ' [whitespace/comments] [5]') | |
| 5161 | |
| 5162 def test_redundant_virtual(self): | 4658 def test_redundant_virtual(self): |
| 5163 self.assert_lint('virtual void fooMethod() override;', | 4659 self.assert_lint('virtual void fooMethod() override;', |
| 5164 '"virtual" is redundant since function is already decla
red as "override" [readability/inheritance] [4]') | 4660 '"virtual" is redundant since function is already decla
red as "override" [readability/inheritance] [4]') |
| 5165 self.assert_lint('virtual void fooMethod(\n) override {}', | 4661 self.assert_lint('virtual void fooMethod(\n) override {}', |
| 5166 '"virtual" is redundant since function is already decla
red as "override" [readability/inheritance] [4]') | 4662 '"virtual" is redundant since function is already decla
red as "override" [readability/inheritance] [4]') |
| 5167 self.assert_lint('virtual void fooMethod() final;', | 4663 self.assert_lint('virtual void fooMethod() final;', |
| 5168 '"virtual" is redundant since function is already decla
red as "final" [readability/inheritance] [4]') | 4664 '"virtual" is redundant since function is already decla
red as "final" [readability/inheritance] [4]') |
| 5169 self.assert_lint('virtual void fooMethod(\n) final {}', | 4665 self.assert_lint('virtual void fooMethod(\n) final {}', |
| 5170 '"virtual" is redundant since function is already decla
red as "final" [readability/inheritance] [4]') | 4666 '"virtual" is redundant since function is already decla
red as "final" [readability/inheritance] [4]') |
| 5171 | 4667 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5270 def test_ne(self): | 4766 def test_ne(self): |
| 5271 """Test __ne__ inequality function.""" | 4767 """Test __ne__ inequality function.""" |
| 5272 checker1 = self._checker() | 4768 checker1 = self._checker() |
| 5273 checker2 = self._checker() | 4769 checker2 = self._checker() |
| 5274 | 4770 |
| 5275 # != calls __ne__. | 4771 # != calls __ne__. |
| 5276 # By default, __ne__ always returns true on different objects. | 4772 # By default, __ne__ always returns true on different objects. |
| 5277 # Thus, just check the distinguishing case to verify that the | 4773 # Thus, just check the distinguishing case to verify that the |
| 5278 # code defines __ne__. | 4774 # code defines __ne__. |
| 5279 self.assertFalse(checker1 != checker2) | 4775 self.assertFalse(checker1 != checker2) |
| OLD | NEW |