Skip to content

Commit dac8fda

Browse files
committed
Ruff rules PL for pylint
1 parent 03d56ce commit dac8fda

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

cpplint.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,8 +1620,7 @@ def Check(self, error, filename, linenum):
16201620
if self.lines_in_function > trigger:
16211621
error_level = int(math.log2(self.lines_in_function / base_trigger))
16221622
# 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
1623-
if error_level > 5:
1624-
error_level = 5
1623+
error_level = min(error_level, 5)
16251624
error(filename, linenum, 'readability/fn_size', error_level,
16261625
'Small and focused functions are preferred:'
16271626
f' {self.current_function} has {self.lines_in_function} non-comment lines'
@@ -1759,8 +1758,8 @@ def _ShouldPrintError(category, confidence, filename, linenum):
17591758
for one_filter in _Filters():
17601759
filter_cat, filter_file, filter_line = _ParseFilterSelector(one_filter[1:])
17611760
category_match = category.startswith(filter_cat)
1762-
file_match = filter_file == "" or filter_file == filename
1763-
line_match = filter_line == linenum or filter_line == -1
1761+
file_match = filter_file in ("", filename)
1762+
line_match = filter_line in (linenum, -1)
17641763

17651764
if one_filter.startswith('-'):
17661765
if category_match and file_match and line_match:
@@ -3344,7 +3343,7 @@ def Update(self, filename, clean_lines, linenum, error):
33443343
if _MATCH_ASM.match(line):
33453344
self.stack[-1].inline_asm = _BLOCK_ASM
33463345

3347-
elif token == ';' or token == ')':
3346+
elif token in {';', ')'}:
33483347
# If we haven't seen an opening brace yet, but we already saw
33493348
# a semicolon, this is probably a forward declaration. Pop
33503349
# the stack for these.
@@ -3674,8 +3673,7 @@ def CheckForFunctionLengths(filename, clean_lines, linenum,
36743673
# If the name is all caps and underscores, figure it's a macro and
36753674
# ignore it, unless it's TEST or TEST_F.
36763675
function_name = match_result.group(1).split()[-1]
3677-
if function_name == 'TEST' or function_name == 'TEST_F' or (
3678-
not re.match(r'[A-Z_]+$', function_name)):
3676+
if function_name in {'TEST', 'TEST_F'} or not re.match(r'[A-Z_]+$', function_name):
36793677
starting_func = True
36803678

36813679
if starting_func:
@@ -3753,7 +3751,7 @@ def CheckComment(line, filename, linenum, next_line_start, error):
37533751
middle_whitespace = match.group(3)
37543752
# Comparisons made explicit for correctness
37553753
# -- pylint: disable=g-explicit-bool-comparison
3756-
if middle_whitespace != ' ' and middle_whitespace != '':
3754+
if middle_whitespace not in {' ', ''}:
37573755
error(filename, linenum, 'whitespace/todo', 2,
37583756
'TODO(my_username) should be followed by a space')
37593757

@@ -4973,7 +4971,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
49734971
# (of lines ending in double quotes, commas, equals, or angle brackets)
49744972
# because the rules for how to indent those are non-trivial.
49754973
if (not re.search(r'[",=><] *$', prev) and
4976-
(initial_spaces == 1 or initial_spaces == 3) and
4974+
(initial_spaces in {1, 3}) and
49774975
not re.match(scope_or_label_pattern, cleansed_line) and
49784976
not (clean_lines.raw_lines[linenum] != line and
49794977
re.match(r'^\s*""', line))):
@@ -5138,8 +5136,7 @@ def _ClassifyInclude(fileinfo, include, used_angle_brackets, include_order="defa
51385136
target_dir_pub = os.path.normpath(target_dir + '/../public')
51395137
target_dir_pub = target_dir_pub.replace('\\', '/')
51405138
if target_base == include_base and (
5141-
include_dir == target_dir or
5142-
include_dir == target_dir_pub):
5139+
include_dir in (target_dir, target_dir_pub)):
51435140
return _LIKELY_MY_HEADER
51445141

51455142
# If the target and include share some initial basename
@@ -6824,7 +6821,7 @@ def ParseArguments(args):
68246821
output_format = val
68256822
elif opt == '--quiet':
68266823
quiet = True
6827-
elif opt == '--verbose' or opt == '--v':
6824+
elif opt in {'--verbose', '--v'}:
68286825
verbosity = int(val)
68296826
elif opt == '--filter':
68306827
filters = val

pyproject.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,17 @@ lint.ignore = [
139139
"ISC003", # flake8-implicit-str-concat
140140
"PIE790", # Unnecessary `pass` statement
141141
]
142-
lint.per-file-ignores."cpplint.py" = [ "ICN001", "PERF401" ]
143-
lint.per-file-ignores."cpplint_unittest.py" = [ "FLY002" ]
142+
lint.per-file-ignores."cpplint.py" = [ "ICN001", "PERF401", "PLR5501", "PLW0603", "PLW2901" ]
143+
lint.per-file-ignores."cpplint_unittest.py" = [ "FLY002", "PLW0604" ]
144144
lint.mccabe.max-complexity = 29
145+
lint.pylint.allow-magic-value-types = [ "int", "str" ]
146+
lint.pylint.max-args = 10 # Default is 5
147+
lint.pylint.max-bool-expr = 8 # Default is 5
148+
lint.pylint.max-branches = 30 # Default is 12
149+
lint.pylint.max-locals = 16 # Default is 15
150+
lint.pylint.max-public-methods = 130 # Default is 20
151+
lint.pylint.max-returns = 9 # Default is 9
152+
lint.pylint.max-statements = 74 # Default is 50
145153

146154
[tool.pytest.ini_options]
147155
python_files = [ "*test.py" ]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy