From b8265f103a9aad943d6250fc55f18203175dfe47 Mon Sep 17 00:00:00 2001 From: Derek Morris Date: Thu, 16 Apr 2020 18:40:27 +0000 Subject: [PATCH] Add cpplint support for space before [[attributes]] Cpplint.py supports checking for spaces in front of square brackets; this is a style violation in most cases (with the typical case being arrays), but there are already situations where this rule is skipped for the square bracket used for lambda captures. We add another such exclusion here for the case of c++ attributes. Change-Id: I2d4f972be29f5427cb8d855787c90dfa5d610e86 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2151125 Commit-Queue: Derek Morris Reviewed-by: Edward Lesmes --- cpplint.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cpplint.py b/cpplint.py index 3aa06b0e6..f7ad8d8b7 100755 --- a/cpplint.py +++ b/cpplint.py @@ -3161,8 +3161,11 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error): line = clean_lines.elided[linenum] # You shouldn't have spaces before your brackets, except maybe after - # 'delete []' or 'return []() {};' - if Search(r'\w\s+\[', line) and not Search(r'(?:delete|return)\s+\[', line): + # 'delete []' or 'return []() {};', or in the case of c++ attributes + # like 'class [[clang::lto_visibility_public]] MyClass'. + if (Search(r'\w\s+\[', line) + and not Search(r'(?:delete|return)\s+\[', line) + and not Search(r'\s+\[\[', line)): error(filename, linenum, 'whitespace/braces', 5, 'Extra space before [')