Skip to content

Ruff rules PL for Pylint #330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1620,8 +1620,7 @@ def Check(self, error, filename, linenum):
if self.lines_in_function > trigger:
error_level = int(math.log2(self.lines_in_function / base_trigger))
# 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
if error_level > 5:
error_level = 5
error_level = min(error_level, 5)
error(filename, linenum, 'readability/fn_size', error_level,
'Small and focused functions are preferred:'
f' {self.current_function} has {self.lines_in_function} non-comment lines'
Expand Down Expand Up @@ -1759,8 +1758,8 @@ def _ShouldPrintError(category, confidence, filename, linenum):
for one_filter in _Filters():
filter_cat, filter_file, filter_line = _ParseFilterSelector(one_filter[1:])
category_match = category.startswith(filter_cat)
file_match = filter_file == "" or filter_file == filename
line_match = filter_line == linenum or filter_line == -1
file_match = filter_file in ("", filename)
line_match = filter_line in (linenum, -1)

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

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

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

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

# If the target and include share some initial basename
Expand Down Expand Up @@ -6824,7 +6821,7 @@ def ParseArguments(args):
output_format = val
elif opt == '--quiet':
quiet = True
elif opt == '--verbose' or opt == '--v':
elif opt in {'--verbose', '--v'}:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the second item be --v or just -v?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we include both?

Or we should check whether --v can be removed, as that is non-standard and hopefully not in use

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer replacing --v, but I have no idea how we'll check if people use --v.

Copy link
Member Author

@cclauss cclauss Mar 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion moved because this would be a breaking change as in that current production usage may break.

verbosity = int(val)
elif opt == '--filter':
filters = val
Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,17 @@ lint.ignore = [
"ISC003", # flake8-implicit-str-concat
"PIE790", # Unnecessary `pass` statement
]
lint.per-file-ignores."cpplint.py" = [ "ICN001", "PERF401" ]
lint.per-file-ignores."cpplint_unittest.py" = [ "FLY002" ]
lint.per-file-ignores."cpplint.py" = [ "ICN001", "PERF401", "PLR5501", "PLW0603", "PLW2901" ]
lint.per-file-ignores."cpplint_unittest.py" = [ "FLY002", "PLW0604" ]
lint.mccabe.max-complexity = 29
lint.pylint.allow-magic-value-types = [ "int", "str" ]
lint.pylint.max-args = 10 # Default is 5
lint.pylint.max-bool-expr = 8 # Default is 5
lint.pylint.max-branches = 30 # Default is 12
lint.pylint.max-locals = 16 # Default is 15
lint.pylint.max-public-methods = 130 # Default is 20
lint.pylint.max-returns = 9 # Default is 9
lint.pylint.max-statements = 74 # Default is 50

[tool.pytest.ini_options]
python_files = [ "*test.py" ]
Expand Down
Loading
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