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

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

Issue 2307613002: Remove style checks which require the use of Pass*Ptr in return and parameter types. (Closed)
Patch Set: Created 4 years, 3 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 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 1715
1716 # Used to detect cases like ec for ExceptionCode. 1716 # Used to detect cases like ec for ExceptionCode.
1717 acronym = _create_acronym(text).lower() 1717 acronym = _create_acronym(text).lower()
1718 if canonical_text.find(canonical_parameter_name) != -1 or acronym.find(canon ical_parameter_name) != -1: 1718 if canonical_text.find(canonical_parameter_name) != -1 or acronym.find(canon ical_parameter_name) != -1:
1719 error(parameter.row, 'readability/parameter_name', 5, 1719 error(parameter.row, 'readability/parameter_name', 5,
1720 'The parameter name "%s" adds no information, so it should be remo ved.' % parameter.name) 1720 'The parameter name "%s" adds no information, so it should be remo ved.' % parameter.name)
1721 return False 1721 return False
1722 return True 1722 return True
1723 1723
1724 1724
1725 def check_function_definition_and_pass_ptr(type_text, row, location_description, error):
1726 """Check that function definitions for use Pass*Ptr instead of *Ptr.
1727
1728 Args:
1729 type_text: A string containing the type. (For return values, it may conta in more than the type.)
1730 row: The row number of the type.
1731 location_description: Used to indicate where the type is. This is either 'parameter' or 'return'.
1732 error: The function to call with any errors found.
1733 """
1734 match_ref_or_own_ptr = '(?=\W|^)(Ref|Own)Ptr(WillBeRawPtr)?(?=\W)'
1735 exceptions = '(?:&|\*|\*\s*=\s*(0|nullptr))$'
1736 bad_type_usage = search(match_ref_or_own_ptr, type_text)
1737 exception_usage = search(exceptions, type_text)
1738 if not bad_type_usage or exception_usage:
1739 return
1740 type_name = bad_type_usage.group(0)
1741 error(row, 'readability/pass_ptr', 5,
1742 'The %s type should use Pass%s instead of %s.' % (location_description , type_name, type_name))
1743
1744
1745 def check_function_definition(filename, file_extension, clean_lines, line_number , function_state, error): 1725 def check_function_definition(filename, file_extension, clean_lines, line_number , function_state, error):
1746 """Check that function definitions for style issues. 1726 """Check that function definitions for style issues.
1747 1727
1748 Specifically, check that parameter names in declarations add information. 1728 Specifically, check that parameter names in declarations add information.
1749 1729
1750 Args: 1730 Args:
1751 filename: Filename of the file that is being processed. 1731 filename: Filename of the file that is being processed.
1752 file_extension: The current file extension, without the leading dot. 1732 file_extension: The current file extension, without the leading dot.
1753 clean_lines: A CleansedLines instance containing the file. 1733 clean_lines: A CleansedLines instance containing the file.
1754 line_number: The number of the line to check. 1734 line_number: The number of the line to check.
(...skipping 12 matching lines...) Expand all
1767 elif not file_extension == "h": 1747 elif not file_extension == "h":
1768 error(function_state.function_name_start_position.row, 'readability/ webkit_export', 5, 1748 error(function_state.function_name_start_position.row, 'readability/ webkit_export', 5,
1769 'WEBKIT_EXPORT should only be used in header files.') 1749 'WEBKIT_EXPORT should only be used in header files.')
1770 elif not function_state.is_declaration or search(r'\binline\b', modifier s_and_return_type): 1750 elif not function_state.is_declaration or search(r'\binline\b', modifier s_and_return_type):
1771 error(function_state.function_name_start_position.row, 'readability/ webkit_export', 5, 1751 error(function_state.function_name_start_position.row, 'readability/ webkit_export', 5,
1772 'WEBKIT_EXPORT should not be used on a function with a body.') 1752 'WEBKIT_EXPORT should not be used on a function with a body.')
1773 elif function_state.is_pure: 1753 elif function_state.is_pure:
1774 error(function_state.function_name_start_position.row, 'readability/ webkit_export', 5, 1754 error(function_state.function_name_start_position.row, 'readability/ webkit_export', 5,
1775 'WEBKIT_EXPORT should not be used with a pure virtual function .') 1755 'WEBKIT_EXPORT should not be used with a pure virtual function .')
1776 1756
1777 check_function_definition_and_pass_ptr(
1778 modifiers_and_return_type, function_state.function_name_start_position.r ow, 'return', error)
1779
1780 parameter_list = function_state.parameter_list() 1757 parameter_list = function_state.parameter_list()
1781 for parameter in parameter_list: 1758 for parameter in parameter_list:
1782 check_function_definition_and_pass_ptr(parameter.type, parameter.row, 'p arameter', error)
1783
1784 # Do checks specific to function declarations and parameter names. 1759 # Do checks specific to function declarations and parameter names.
1785 if not function_state.is_declaration or not parameter.name: 1760 if not function_state.is_declaration or not parameter.name:
1786 continue 1761 continue
1787 1762
1788 # Check the parameter name against the function name for single paramete r set functions. 1763 # Check the parameter name against the function name for single paramete r set functions.
1789 if len(parameter_list) == 1 and match('set[A-Z]', function_state.current _function): 1764 if len(parameter_list) == 1 and match('set[A-Z]', function_state.current _function):
1790 trimmed_function_name = function_state.current_function[len('set'):] 1765 trimmed_function_name = function_state.current_function[len('set'):]
1791 if not _check_parameter_name_against_text(parameter, trimmed_functio n_name, error): 1766 if not _check_parameter_name_against_text(parameter, trimmed_functio n_name, error):
1792 continue # Since an error was noted for this name, move to the next parameter. 1767 continue # Since an error was noted for this name, move to the next parameter.
1793 1768
(...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after
4208 4183
4209 def check(self, lines): 4184 def check(self, lines):
4210 _process_lines(self.file_path, self.file_extension, lines, 4185 _process_lines(self.file_path, self.file_extension, lines,
4211 self.handle_style_error, self.min_confidence) 4186 self.handle_style_error, self.min_confidence)
4212 4187
4213 4188
4214 # FIXME: Remove this function (requires refactoring unit tests). 4189 # FIXME: Remove this function (requires refactoring unit tests).
4215 def process_file_data(filename, file_extension, lines, error, min_confidence, fs =None): 4190 def process_file_data(filename, file_extension, lines, error, min_confidence, fs =None):
4216 checker = CppChecker(filename, file_extension, error, min_confidence, fs) 4191 checker = CppChecker(filename, file_extension, error, min_confidence, fs)
4217 checker.check(lines) 4192 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