Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Side by Side Diff: third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp.py

Issue 1981763002: check-webkit-style: Add checks for deprecated wtf/Assertions.h macros. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 # 2 #
3 # Copyright (C) 2009, 2010, 2012 Google Inc. All rights reserved. 3 # Copyright (C) 2009, 2010, 2012 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 _CHECK_REPLACEMENT['ASSERT_TRUE_M'][op] = 'ASSERT_%s_M' % replacement 101 _CHECK_REPLACEMENT['ASSERT_TRUE_M'][op] = 'ASSERT_%s_M' % replacement
102 102
103 for op, inv_replacement in [('==', 'NE'), ('!=', 'EQ'), 103 for op, inv_replacement in [('==', 'NE'), ('!=', 'EQ'),
104 ('>=', 'LT'), ('>', 'LE'), 104 ('>=', 'LT'), ('>', 'LE'),
105 ('<=', 'GT'), ('<', 'GE')]: 105 ('<=', 'GT'), ('<', 'GE')]:
106 _CHECK_REPLACEMENT['EXPECT_FALSE'][op] = 'EXPECT_%s' % inv_replacement 106 _CHECK_REPLACEMENT['EXPECT_FALSE'][op] = 'EXPECT_%s' % inv_replacement
107 _CHECK_REPLACEMENT['ASSERT_FALSE'][op] = 'ASSERT_%s' % inv_replacement 107 _CHECK_REPLACEMENT['ASSERT_FALSE'][op] = 'ASSERT_%s' % inv_replacement
108 _CHECK_REPLACEMENT['EXPECT_FALSE_M'][op] = 'EXPECT_%s_M' % inv_replacement 108 _CHECK_REPLACEMENT['EXPECT_FALSE_M'][op] = 'EXPECT_%s_M' % inv_replacement
109 _CHECK_REPLACEMENT['ASSERT_FALSE_M'][op] = 'ASSERT_%s_M' % inv_replacement 109 _CHECK_REPLACEMENT['ASSERT_FALSE_M'][op] = 'ASSERT_%s_M' % inv_replacement
110 110
111 _DEPRECATED_MACROS = [
112 ['ASSERT', 'DCHECK or its variants'],
113 ['ASSERT_UNUSED', 'DCHECK or its variants'],
114 ['ASSERT_NOT_REACHED', 'NOTREACHED'],
115 ['ASSERT_WITH_SECURITY_IMPLICATION', 'SECURITY_DCHECK'],
116 ['WTF_LOG', 'DVLOG']
117 ]
111 118
112 # These constants define types of headers for use with 119 # These constants define types of headers for use with
113 # _IncludeState.check_next_include_order(). 120 # _IncludeState.check_next_include_order().
114 _PRIMARY_HEADER = 0 121 _PRIMARY_HEADER = 0
115 _OTHER_HEADER = 1 122 _OTHER_HEADER = 1
116 _MOC_HEADER = 2 123 _MOC_HEADER = 2
117 124
118 125
119 # The regexp compilation caching is inlined in all regexp functions for 126 # The regexp compilation caching is inlined in all regexp functions for
120 # performance reasons; factoring it out into a separate function turns out 127 # performance reasons; factoring it out into a separate function turns out
(...skipping 2490 matching lines...) Expand 10 before | Expand all | Expand 10 after
2611 # Encourage replacing plain CHECKs with CHECK_EQ/CHECK_NE/etc. 2618 # Encourage replacing plain CHECKs with CHECK_EQ/CHECK_NE/etc.
2612 for operator in ['==', '!=', '>=', '>', '<=', '<']: 2619 for operator in ['==', '!=', '>=', '>', '<=', '<']:
2613 if replaceable_check(operator, current_macro, line): 2620 if replaceable_check(operator, current_macro, line):
2614 error(line_number, 'readability/check', 2, 2621 error(line_number, 'readability/check', 2,
2615 'Consider using %s instead of %s(a %s b)' % ( 2622 'Consider using %s instead of %s(a %s b)' % (
2616 _CHECK_REPLACEMENT[current_macro][operator], 2623 _CHECK_REPLACEMENT[current_macro][operator],
2617 current_macro, operator)) 2624 current_macro, operator))
2618 break 2625 break
2619 2626
2620 2627
2628 def check_deprecated_macros(clean_lines, line_number, error):
2629 """Checks the use of obsolete macros.
2630
2631 Args:
2632 clean_lines: A CleansedLines instance containing the file.
2633 line_number: The number of the line to check.
2634 error: The function to call with any errors found.
2635 """
2636
2637 line = clean_lines.elided[line_number]
2638 for pair in _DEPRECATED_MACROS:
2639 if search(r'\b' + pair[0] + r'\(', line):
2640 error(line_number, 'build/deprecated', 5,
2641 '%s is deprecated. Use %s instead.' % (pair[0], pair[1]))
2642
2643
2621 def check_for_comparisons_to_boolean(clean_lines, line_number, error): 2644 def check_for_comparisons_to_boolean(clean_lines, line_number, error):
2622 # Get the line without comments and strings. 2645 # Get the line without comments and strings.
2623 line = clean_lines.elided[line_number] 2646 line = clean_lines.elided[line_number]
2624 2647
2625 # Must include NULL here, as otherwise users will convert NULL to 0 and 2648 # Must include NULL here, as otherwise users will convert NULL to 0 and
2626 # then we can't catch it, since it looks like a valid integer comparison. 2649 # then we can't catch it, since it looks like a valid integer comparison.
2627 if search(r'[=!]=\s*(NULL|nullptr|true|false)[^\w.]', line) or search(r'[^\w .](NULL|nullptr|true|false)\s*[=!]=', line): 2650 if search(r'[=!]=\s*(NULL|nullptr|true|false)[^\w.]', line) or search(r'[^\w .](NULL|nullptr|true|false)\s*[=!]=', line):
2628 if not search('LIKELY', line) and not search('UNLIKELY', line): 2651 if not search('LIKELY', line) and not search('UNLIKELY', line):
2629 error(line_number, 'readability/comparison_to_boolean', 5, 2652 error(line_number, 'readability/comparison_to_boolean', 5,
2630 'Tests for true/false and null/non-null should be done without equality comparisons.') 2653 'Tests for true/false and null/non-null should be done without equality comparisons.')
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
2967 check_namespace_indentation(clean_lines, line_number, file_extension, file_s tate, error) 2990 check_namespace_indentation(clean_lines, line_number, file_extension, file_s tate, error)
2968 check_directive_indentation(clean_lines, line_number, file_state, error) 2991 check_directive_indentation(clean_lines, line_number, file_state, error)
2969 check_using_std(clean_lines, line_number, file_state, error) 2992 check_using_std(clean_lines, line_number, file_state, error)
2970 check_max_min_macros(clean_lines, line_number, file_state, error) 2993 check_max_min_macros(clean_lines, line_number, file_state, error)
2971 check_ctype_functions(clean_lines, line_number, file_state, error) 2994 check_ctype_functions(clean_lines, line_number, file_state, error)
2972 check_switch_indentation(clean_lines, line_number, error) 2995 check_switch_indentation(clean_lines, line_number, error)
2973 check_braces(clean_lines, line_number, error) 2996 check_braces(clean_lines, line_number, error)
2974 check_exit_statement_simplifications(clean_lines, line_number, error) 2997 check_exit_statement_simplifications(clean_lines, line_number, error)
2975 check_spacing(file_extension, clean_lines, line_number, error) 2998 check_spacing(file_extension, clean_lines, line_number, error)
2976 check_check(clean_lines, line_number, error) 2999 check_check(clean_lines, line_number, error)
3000 check_deprecated_macros(clean_lines, line_number, error)
2977 check_for_comparisons_to_boolean(clean_lines, line_number, error) 3001 check_for_comparisons_to_boolean(clean_lines, line_number, error)
2978 check_for_null(clean_lines, line_number, file_state, error) 3002 check_for_null(clean_lines, line_number, file_state, error)
2979 check_indentation_amount(clean_lines, line_number, error) 3003 check_indentation_amount(clean_lines, line_number, error)
2980 check_enum_casing(clean_lines, line_number, enum_state, error) 3004 check_enum_casing(clean_lines, line_number, enum_state, error)
2981 3005
2982 3006
2983 _RE_PATTERN_INCLUDE_NEW_STYLE = re.compile(r'#include +"[^/]+\.h"') 3007 _RE_PATTERN_INCLUDE_NEW_STYLE = re.compile(r'#include +"[^/]+\.h"')
2984 _RE_PATTERN_INCLUDE = re.compile(r'^\s*#\s*include\s*([<"])([^>"]*)[>"].*$') 3008 _RE_PATTERN_INCLUDE = re.compile(r'^\s*#\s*include\s*([<"])([^>"]*)[>"].*$')
2985 # Matches the first component of a filename delimited by -s and _s. That is: 3009 # Matches the first component of a filename delimited by -s and _s. That is:
2986 # _RE_FIRST_COMPONENT.match('foo').group(0) == 'foo' 3010 # _RE_FIRST_COMPONENT.match('foo').group(0) == 'foo'
(...skipping 1202 matching lines...) Expand 10 before | Expand all | Expand 10 after
4189 4213
4190 def check(self, lines): 4214 def check(self, lines):
4191 _process_lines(self.file_path, self.file_extension, lines, 4215 _process_lines(self.file_path, self.file_extension, lines,
4192 self.handle_style_error, self.min_confidence) 4216 self.handle_style_error, self.min_confidence)
4193 4217
4194 4218
4195 # FIXME: Remove this function (requires refactoring unit tests). 4219 # FIXME: Remove this function (requires refactoring unit tests).
4196 def process_file_data(filename, file_extension, lines, error, min_confidence, fs =None): 4220 def process_file_data(filename, file_extension, lines, error, min_confidence, fs =None):
4197 checker = CppChecker(filename, file_extension, error, min_confidence, fs) 4221 checker = CppChecker(filename, file_extension, error, min_confidence, fs)
4198 checker.check(lines) 4222 checker.check(lines)
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698