Upstream useful lint check from WebKit's fork of cpplint.py.

Checks against "Foo *bar" and "Foo &bar" declarations.

WebKit patch was: http://trac.webkit.org/changeset/46856

Credit Torch Mobile, Inc. who have contributed the WebKit patch in question.

Patch committed for asvitkine@chromium.org.
This commit is contained in:
erg@google.com
2011-09-06 20:19:05 +00:00
parent 0249a38579
commit 5210aec6df
2 changed files with 41 additions and 3 deletions
+16 -2
View File
@@ -1,7 +1,8 @@
#!/usr/bin/python2.4
# -*- coding: utf-8; -*-
#
# Copyright (c) 2009 Google Inc. All rights reserved.
# Copyright (c) 2011 Google Inc. All rights reserved.
# Copyright (C) 2009 Torch Mobile Inc.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
@@ -348,7 +349,7 @@ class CpplintTest(CpplintTestBase):
'Using C-style cast. Use static_cast<int>(...) instead'
' [readability/casting] [4]')
self.TestLint(
'int *a = (int *)NULL;',
'int* a = (int *)NULL;',
'Using C-style cast. Use reinterpret_cast<int *>(...) instead'
' [readability/casting] [4]')
@@ -1646,6 +1647,19 @@ class CpplintTest(CpplintTestBase):
self.TestLint('f(a, /* name */ b);', '')
self.TestLint('f(a, /* name */b);', '')
def testPointerDeclarationWhitespace(self):
self.TestLint('int* b;', '')
self.TestLint('int *b;',
'Declaration has space between type name and * in int *b '
'[whitespace/declaration] [3]')
self.TestLint('return *b;', '')
self.TestLint('delete *b;', '')
self.TestLint('int& b;', '')
self.TestLint('int &b;',
'Declaration has space between type name and & in int &b '
'[whitespace/declaration] [3]')
self.TestLint('return &b;', '')
def testIndent(self):
self.TestLint('static int noindent;', '')
self.TestLint(' int two_space_indent;', '')