Skip to content

Commit 66c4c80

Browse files
authored
Ruff rules PL for Pylint (#330)
Add ruff rules PL for Pylint: https://docs.astral.sh/ruff/rules/#pylint-pl % `ruff check --select=PL` % `ruff check --select=PLR0 --preview`
1 parent 776a72b commit 66c4c80

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
@@ -1619,8 +1619,7 @@ def Check(self, error, filename, linenum):
16191619
if self.lines_in_function > trigger:
16201620
error_level = int(math.log2(self.lines_in_function / base_trigger))
16211621
# 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
1622-
if error_level > 5:
1623-
error_level = 5
1622+
error_level = min(error_level, 5)
16241623
error(filename, linenum, 'readability/fn_size', error_level,
16251624
'Small and focused functions are preferred:'
16261625
f' {self.current_function} has {self.lines_in_function} non-comment lines'
@@ -1758,8 +1757,8 @@ def _ShouldPrintError(category, confidence, filename, linenum):
17581757
for one_filter in _Filters():
17591758
filter_cat, filter_file, filter_line = _ParseFilterSelector(one_filter[1:])
17601759
category_match = category.startswith(filter_cat)
1761-
file_match = filter_file == "" or filter_file == filename
1762-
line_match = filter_line == linenum or filter_line == -1
1760+
file_match = filter_file in ("", filename)
1761+
line_match = filter_line in (linenum, -1)
17631762

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

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

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

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

51445141
# If the target and include share some initial basename
@@ -6819,7 +6816,7 @@ def ParseArguments(args):
68196816
output_format = val
68206817
elif opt == '--quiet':
68216818
quiet = True
6822-
elif opt == '--verbose' or opt == '--v':
6819+
elif opt in {'--verbose', '--v'}:
68236820
verbosity = int(val)
68246821
elif opt == '--filter':
68256822
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