@@ -1326,11 +1326,10 @@ def IsInAlphabeticalOrder(self, clean_lines, linenum, header_path):
1326
1326
#
1327
1327
# If previous line was a blank line, assume that the headers are
1328
1328
# intentionally sorted the way they are.
1329
- if self ._last_header > header_path and re .match (
1330
- r"^\s*#\s*include\b" , clean_lines .elided [linenum - 1 ]
1331
- ):
1332
- return False
1333
- return True
1329
+ return not (
1330
+ self ._last_header > header_path
1331
+ and re .match (r"^\s*#\s*include\b" , clean_lines .elided [linenum - 1 ])
1332
+ )
1334
1333
1335
1334
def CheckNextIncludeOrder (self , header_type ):
1336
1335
"""Returns a non-empty error message if the next header is out of order.
@@ -1844,10 +1843,7 @@ def _ShouldPrintError(category, confidence, filename, linenum):
1844
1843
# should have been checked for in SetFilter.
1845
1844
msg = f"Invalid filter: { one_filter } "
1846
1845
raise ValueError (msg )
1847
- if is_filtered :
1848
- return False
1849
-
1850
- return True
1846
+ return not is_filtered
1851
1847
1852
1848
1853
1849
def Error (filename , linenum , category , confidence , message ):
@@ -2262,11 +2258,10 @@ def FindEndOfExpressionInLine(line, startpos, stack):
2262
2258
2263
2259
# Pop the stack if there is a matching '<'. Otherwise, ignore
2264
2260
# this '>' since it must be an operator.
2265
- if stack :
2266
- if stack [- 1 ] == "<" :
2267
- stack .pop ()
2268
- if not stack :
2269
- return (i + 1 , None )
2261
+ if stack and stack [- 1 ] == "<" :
2262
+ stack .pop ()
2263
+ if not stack :
2264
+ return (i + 1 , None )
2270
2265
elif char == ";" :
2271
2266
# Found something that look like end of statements. If we are currently
2272
2267
# expecting a '>', the matching '<' must have been an operator, since
@@ -2963,10 +2958,7 @@ def IsMacroDefinition(clean_lines, linenum):
2963
2958
if re .search (r"^#define" , clean_lines [linenum ]):
2964
2959
return True
2965
2960
2966
- if linenum > 0 and re .search (r"\\$" , clean_lines [linenum - 1 ]):
2967
- return True
2968
-
2969
- return False
2961
+ return bool (linenum > 0 and re .search (r"\\$" , clean_lines [linenum - 1 ]))
2970
2962
2971
2963
2972
2964
def IsForwardClassDeclaration (clean_lines , linenum ):
@@ -4352,20 +4344,19 @@ def CheckParenthesisSpacing(filename, clean_lines, linenum, error):
4352
4344
line ,
4353
4345
)
4354
4346
if match :
4355
- if len (match .group (2 )) != len (match .group (4 )):
4356
- if not (
4357
- match .group (3 ) == ";"
4358
- and len (match .group (2 )) == 1 + len (match .group (4 ))
4359
- or not match .group (2 )
4360
- and re .search (r"\bfor\s*\(.*; \)" , line )
4361
- ):
4362
- error (
4363
- filename ,
4364
- linenum ,
4365
- "whitespace/parens" ,
4366
- 5 ,
4367
- f"Mismatching spaces inside () in { match .group (1 )} " ,
4368
- )
4347
+ if len (match .group (2 )) != len (match .group (4 )) and not (
4348
+ match .group (3 ) == ";"
4349
+ and len (match .group (2 )) == 1 + len (match .group (4 ))
4350
+ or not match .group (2 )
4351
+ and re .search (r"\bfor\s*\(.*; \)" , line )
4352
+ ):
4353
+ error (
4354
+ filename ,
4355
+ linenum ,
4356
+ "whitespace/parens" ,
4357
+ 5 ,
4358
+ f"Mismatching spaces inside () in { match .group (1 )} " ,
4359
+ )
4369
4360
if len (match .group (2 )) not in [0 , 1 ]:
4370
4361
error (
4371
4362
filename ,
@@ -4586,9 +4577,7 @@ def IsDecltype(clean_lines, linenum, column):
4586
4577
(text , _ , start_col ) = ReverseCloseExpression (clean_lines , linenum , column )
4587
4578
if start_col < 0 :
4588
4579
return False
4589
- if re .search (r"\bdecltype\s*$" , text [0 :start_col ]):
4590
- return True
4591
- return False
4580
+ return bool (re .search (r"\bdecltype\s*$" , text [0 :start_col ]))
4592
4581
4593
4582
4594
4583
def CheckSectionSpacing (filename , clean_lines , class_info , linenum , error ):
@@ -4761,23 +4750,18 @@ def CheckBraces(filename, clean_lines, linenum, error):
4761
4750
# No control clauses with braces should have its contents on the same line
4762
4751
# Exclude } which will be covered by empty-block detect
4763
4752
# Exclude ; which may be used by while in a do-while
4764
- if keyword := re .search (
4765
- r"\b(else if|if|while|for|switch)" # These have parens
4766
- r"\s*\(.*\)\s*(?:\[\[(?:un)?likely\]\]\s*)?{\s*[^\s\\};]" ,
4767
- line ,
4768
- ):
4769
- error (
4770
- filename ,
4771
- linenum ,
4772
- "whitespace/newline" ,
4773
- 5 ,
4774
- f"Controlled statements inside brackets of { keyword .group (1 )} clause"
4775
- " should be on a separate line" ,
4753
+ if (
4754
+ keyword := re .search (
4755
+ r"\b(else if|if|while|for|switch)" # These have parens
4756
+ r"\s*\(.*\)\s*(?:\[\[(?:un)?likely\]\]\s*)?{\s*[^\s\\};]" ,
4757
+ line ,
4758
+ )
4759
+ ) or (
4760
+ keyword := re .search (
4761
+ r"\b(else|do|try)" # These don't have parens
4762
+ r"\s*(?:\[\[(?:un)?likely\]\]\s*)?{\s*[^\s\\}]" ,
4763
+ line ,
4776
4764
)
4777
- elif keyword := re .search (
4778
- r"\b(else|do|try)" # These don't have parens
4779
- r"\s*(?:\[\[(?:un)?likely\]\]\s*)?{\s*[^\s\\}]" ,
4780
- line ,
4781
4765
):
4782
4766
error (
4783
4767
filename ,
@@ -5430,10 +5414,9 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, er
5430
5414
)
5431
5415
5432
5416
# Check if the line is a header guard.
5433
- is_header_guard = False
5434
- if IsHeaderExtension (file_extension ):
5435
- if line .startswith ((f"#ifndef { cppvar } " , f"#define { cppvar } " , f"#endif // { cppvar } " )):
5436
- is_header_guard = True
5417
+ is_header_guard = IsHeaderExtension (file_extension ) and line .startswith (
5418
+ (f"#ifndef { cppvar } " , f"#define { cppvar } " , f"#endif // { cppvar } " )
5419
+ )
5437
5420
# #include lines and header guards can be long, since there's no clean way to
5438
5421
# split them.
5439
5422
#
@@ -5648,17 +5631,18 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error):
5648
5631
# We also make an exception for Lua headers, which follow google
5649
5632
# naming convention but not the include convention.
5650
5633
match = re .match (r'#include\s*"([^/]+\.(.*))"' , line )
5651
- if match :
5652
- if IsHeaderExtension (match .group (2 )) and not _THIRD_PARTY_HEADERS_PATTERN .match (
5653
- match .group (1 )
5654
- ):
5655
- error (
5656
- filename ,
5657
- linenum ,
5658
- "build/include_subdir" ,
5659
- 4 ,
5660
- "Include the directory when naming header files" ,
5661
- )
5634
+ if (
5635
+ match
5636
+ and IsHeaderExtension (match .group (2 ))
5637
+ and not _THIRD_PARTY_HEADERS_PATTERN .match (match .group (1 ))
5638
+ ):
5639
+ error (
5640
+ filename ,
5641
+ linenum ,
5642
+ "build/include_subdir" ,
5643
+ 4 ,
5644
+ "Include the directory when naming header files" ,
5645
+ )
5662
5646
5663
5647
# we shouldn't include a file more than once. actually, there are a
5664
5648
# handful of instances where doing so is okay, but in general it's
@@ -6326,8 +6310,7 @@ def CheckForNonConstReference(filename, clean_lines, linenum, nesting_state, err
6326
6310
# function body, including one that was just introduced by a trailing '{'.
6327
6311
# TODO(unknown): Doesn't account for 'catch(Exception& e)' [rare].
6328
6312
if nesting_state .previous_stack_top and not (
6329
- isinstance (nesting_state .previous_stack_top , _ClassInfo )
6330
- or isinstance (nesting_state .previous_stack_top , _NamespaceInfo )
6313
+ isinstance (nesting_state .previous_stack_top , (_ClassInfo , _NamespaceInfo ))
6331
6314
):
6332
6315
# Not at toplevel, not within a class, and not within a namespace
6333
6316
return
0 commit comments