Title: [260051] trunk/Tools
- Revision
- 260051
- Author
- [email protected]
- Date
- 2020-04-13 17:32:26 -0700 (Mon, 13 Apr 2020)
Log Message
check-webkit-style should warn about attributes that appear after function definitions
<https://webkit.org/b/210459>
Reviewed by Darin Adler.
* Scripts/webkitpy/style/checkers/cpp.py:
(_FunctionState.attributes_after_definition): Add.
- Return list of attributes that appear after a function
definition.
(check_function_definition):
- Add new check for attributes that appear after a function
definition.
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(CppStyleTest.test_decode_functions_missing_warn_unused_return):
- Update test to fix new warning.
(CppStyleTest.test_function_readability_for_attributes): Add.
- Add tests.
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (260050 => 260051)
--- trunk/Tools/ChangeLog 2020-04-13 23:48:09 UTC (rev 260050)
+++ trunk/Tools/ChangeLog 2020-04-14 00:32:26 UTC (rev 260051)
@@ -1,3 +1,24 @@
+2020-04-13 David Kilzer <[email protected]>
+
+ check-webkit-style should warn about attributes that appear after function definitions
+ <https://webkit.org/b/210459>
+
+ Reviewed by Darin Adler.
+
+ * Scripts/webkitpy/style/checkers/cpp.py:
+ (_FunctionState.attributes_after_definition): Add.
+ - Return list of attributes that appear after a function
+ definition.
+ (check_function_definition):
+ - Add new check for attributes that appear after a function
+ definition.
+
+ * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+ (CppStyleTest.test_decode_functions_missing_warn_unused_return):
+ - Update test to fix new warning.
+ (CppStyleTest.test_function_readability_for_attributes): Add.
+ - Add tests.
+
2020-04-13 Kate Cheney <[email protected]>
http/tests/in-app-browser-privacy/app-bound-domain.html is a constant failure on iOS
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (260050 => 260051)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2020-04-13 23:48:09 UTC (rev 260050)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py 2020-04-14 00:32:26 UTC (rev 260051)
@@ -596,6 +596,9 @@
elided = self._clean_lines.elided
return SingleLineView(elided, self.parameter_end_position, self.body_start_position).single_line.strip()
+ def attributes_after_definition(self, attribute_regex):
+ return re.findall(attribute_regex, self.post_modifiers())
+
def has_attribute(self, attribute_regex):
regex = r'\b{attribute_regex}\b'.format(attribute_regex=attribute_regex)
return bool(search(regex, self.modifiers_and_return_type())) or bool(search(regex, self.post_modifiers()))
@@ -1821,6 +1824,14 @@
error(line_number, 'security/missing_warn_unused_return', 5,
'decode() function returning a value is missing WARN_UNUSED_RETURN attribute')
+ attributes = function_state.attributes_after_definition(r'(\bWARN_[0-9A-Z_]+\b|__attribute__\(\(__[a-z_]+__\)\))')
+ if len(attributes) > 0:
+ attribute_text = ', '.join(attributes)
+ plural = 's' if len(attributes) > 1 else ''
+ error(line_number, 'readability/function', 5,
+ 'Function attribute{plural} ({attributes}) should appear before the function definition'.
+ format(attributes=attribute_text, plural=plural))
+
parameter_list = function_state.parameter_list()
for parameter in parameter_list:
# Do checks specific to function declarations and parameter names.
Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (260050 => 260051)
--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2020-04-13 23:48:09 UTC (rev 260050)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py 2020-04-14 00:32:26 UTC (rev 260051)
@@ -3000,7 +3000,7 @@
warning_expected)
self.perform_function_definition_check(
'Source/WTF/wtf/foo.h',
- 'WTF_EXPORT_PRIVATE static bool decode(Decoder&, AtomString&) WARN_UNUSED_RETURN;',
+ 'WTF_EXPORT_PRIVATE static WARN_UNUSED_RETURN bool decode(Decoder&, AtomString&);',
warning_none)
self.perform_function_definition_check(
@@ -3045,7 +3045,25 @@
' static WARN_UNUSED_RETURN bool platformDecode(IPC::Decoder&, WebHitTestResultData&);',
warning_none)
+ def test_function_readability_for_attributes(self):
+ self.perform_function_definition_check(
+ 'Source/WTF/wtf/foo.h',
+ 'WTF_EXPORT_PRIVATE static bool decode(Decoder&, AtomString&) WARN_UNUSED_RETURN;',
+ 'Function attribute (WARN_UNUSED_RETURN) should appear before the function definition'
+ ' [readability/function] [5]')
+ self.perform_function_definition_check(
+ 'foo.h',
+ 'static __attribute__((__warn_unused_result__)) bool check(Decoder&, AtomString&);',
+ '')
+
+ self.perform_function_definition_check(
+ 'foo.h',
+ 'static bool check(Decoder&, AtomString&) __attribute__((__warn_unused_result__));',
+ 'Function attribute (__attribute__((__warn_unused_result__))) should appear before the function definition'
+ ' [readability/function] [5]')
+
+
class CleansedLinesTest(unittest.TestCase):
def test_init(self):
lines = ['Line 1',
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes