Title: [161427] trunk/Tools
- Revision
- 161427
- Author
- commit-qu...@webkit.org
- Date
- 2014-01-07 08:59:16 -0800 (Tue, 07 Jan 2014)
Log Message
defined constants should use all uppercase names with words separated by underscores.
https://bugs.webkit.org/show_bug.cgi?id=126055
Patch by Gergo Balogh <gery...@inf.u-szeged.hu> on 2014-01-07
Reviewed by Alexey Proskuryakov.
* Scripts/webkitpy/style/checkers/cpp.py:
(check_style):
(CppChecker):
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_define_constants):
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (161426 => 161427)
--- trunk/Tools/ChangeLog 2014-01-07 15:29:17 UTC (rev 161426)
+++ trunk/Tools/ChangeLog 2014-01-07 16:59:16 UTC (rev 161427)
@@ -1,3 +1,16 @@
+2014-01-07 Gergo Balogh <gery...@inf.u-szeged.hu>
+
+ defined constants should use all uppercase names with words separated by underscores.
+ https://bugs.webkit.org/show_bug.cgi?id=126055
+
+ Reviewed by Alexey Proskuryakov.
+
+ * Scripts/webkitpy/style/checkers/cpp.py:
+ (check_style):
+ (CppChecker):
+ * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+ (WebKitStyleTest.test_define_constants):
+
2014-01-07 Brian Holt <brian.h...@samsung.com>
Unreviewed. Add myself as a committer.
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (161426 => 161427)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2014-01-07 15:29:17 UTC (rev 161426)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2014-01-07 16:59:16 UTC (rev 161427)
@@ -2719,7 +2719,15 @@
check_indentation_amount(clean_lines, line_number, error)
check_enum_casing(clean_lines, line_number, enum_state, error)
+ # #defined constants should use all uppercase names with words separated by underscores.
+ define_check = match(r'#define\s(?P<name>[\w_]+)(\s.*|\s?)$', line)
+ if define_check:
+ name = define_check.group('name')
+ if not match(r'^[0-9A-Z_]+$', name):
+ error(line_number, 'readability/naming/define/constants', 4,
+ name + " is incorrect. #defined constants should use all uppercase names with words separated by underscores.")
+
_RE_PATTERN_INCLUDE_NEW_STYLE = re.compile(r'#include +"[^/]+\.h"')
_RE_PATTERN_INCLUDE = re.compile(r'^\s*#\s*include\s*([<"])([^>"]*)[>"].*$')
# Matches the first component of a filename delimited by -s and _s. That is:
@@ -3700,6 +3708,7 @@
'readability/parameter_name',
'readability/naming',
'readability/naming/underscores',
+ 'readability/naming/define/constants',
'readability/null',
'readability/pass_ptr',
'readability/streams',
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (161426 => 161427)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2014-01-07 15:29:17 UTC (rev 161426)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2014-01-07 16:59:16 UTC (rev 161427)
@@ -5026,7 +5026,20 @@
# FIXME: Implement this.
pass
+ def test_define_constants(self):
+ bad_name_error = " is incorrect. #defined constants should use all uppercase names with words separated by underscores. [readability/naming/define/constants] [4]"
+ self.assert_lint('#define lower1case', 'lower1case' + bad_name_error)
+ self.assert_lint('#define UPPER1CASE', '')
+ self.assert_lint('#define mixed1CASE', 'mixed1CASE' + bad_name_error)
+ self.assert_lint('#define lower_1case', 'lower_1case' + bad_name_error)
+ self.assert_lint('#define UPPER_1CASE', '')
+ self.assert_lint('#define mixed_1CASE', 'mixed_1CASE' + bad_name_error)
+ self.assert_lint('#define dlower1case some(bla)', 'dlower1case' + bad_name_error)
+ self.assert_lint('#define DUPPER1CASE dd(foo)', '')
+ self.assert_lint('#define Dmixed1CASE dkjgh[sdf]', 'Dmixed1CASE' + bad_name_error)
+
+
class CppCheckerTest(unittest.TestCase):
"""Tests CppChecker class."""
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes