Skip to content
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
20 changes: 10 additions & 10 deletions cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ def _IsSourceExtension(s):
return s in GetNonHeaderExtensions()


class _IncludeState(object):
class _IncludeState:
"""Tracks line numbers for includes, and the order in which includes appear.

include_list contains list of lists of (header, line number) pairs.
Expand Down Expand Up @@ -1392,7 +1392,7 @@ def CheckNextIncludeOrder(self, header_type):
return ""


class _CppLintState(object):
class _CppLintState:
"""Maintains module-wide state.."""

def __init__(self):
Expand Down Expand Up @@ -1637,7 +1637,7 @@ def _RestoreFilters():
_cpplint_state.RestoreFilters()


class _FunctionState(object):
class _FunctionState:
"""Tracks current function name and the number of lines in its body."""

_NORMAL_TRIGGER = 250 # for --v=0, 500 for --v=1, etc.
Expand Down Expand Up @@ -1705,7 +1705,7 @@ class _IncludeError(Exception):
pass


class FileInfo(object):
class FileInfo:
"""Provides utility functions for filenames.

FileInfo provides easy access to the components of a file's path
Expand Down Expand Up @@ -2104,7 +2104,7 @@ def ReplaceAlternateTokens(line):
return line


class CleansedLines(object):
class CleansedLines:
"""Holds 4 copies of all lines with different preprocessing applied to them.

1) elided member contains lines without strings and comments.
Expand Down Expand Up @@ -2973,7 +2973,7 @@ def IsForwardClassDeclaration(clean_lines, linenum):
return re.match(r"^\s*(\btemplate\b)*.*class\s+\w+;\s*$", clean_lines[linenum])


class _BlockInfo(object):
class _BlockInfo:
"""Stores information about a generic block of code."""

def __init__(self, linenum, seen_open_brace):
Expand Down Expand Up @@ -3188,7 +3188,7 @@ def CheckEnd(self, filename, clean_lines, linenum, error):
)


class _PreprocessorInfo(object):
class _PreprocessorInfo:
"""Stores checkpoints of nesting stacks when #if/#else is seen."""

def __init__(self, stack_before_if):
Expand All @@ -3202,7 +3202,7 @@ def __init__(self, stack_before_if):
self.seen_else = False


class NestingState(object):
class NestingState:
"""Holds states related to parsing braces."""

def __init__(self):
Expand Down Expand Up @@ -7417,7 +7417,7 @@ def ProcessConfigOverrides(filename):
f"Invalid configuration option ({name}) in file {cfg_file}\n"
)

except IOError:
except OSError:
_cpplint_state.PrintError(
f"Skipping config file '{cfg_file}': Can't open for reading\n"
)
Expand Down Expand Up @@ -7478,7 +7478,7 @@ def ProcessFile(filename, vlevel, extra_check_functions=None):
else:
lf_lines.append(linenum + 1)

except IOError:
except OSError:
# TODO: Maybe make this have an exit code of 2 after all is done
_cpplint_state.PrintError(f"Skipping input '{filename}': Can't open for reading\n")
_RestoreFilters()
Expand Down
5 changes: 2 additions & 3 deletions cpplint_clitest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8; -*-
#
# Copyright (c) 2009 Google Inc. All rights reserved.
#
Expand Down Expand Up @@ -162,8 +161,8 @@ def _run_and_compare(self, definition_file, args, expected_status, expected_out,
# command to reproduce, do not forget first two lines have special meaning
print("\ncd " + cwd + " && " + cmd + " " + args + " 2> <filename>")
(status, out, err) = run_shell_command(cmd, args, cwd)
self.assertEqual(expected_status, status, "bad command status %s" % status)
prefix = "Failed check in %s comparing to %s for command: %s" % (cwd, definition_file, cmd)
self.assertEqual(expected_status, status, f"bad command status {status}")
prefix = f"Failed check in {cwd} comparing to {definition_file} for command: {cmd}"
compare("\n".join(expected_err), err.decode("utf8"), prefix=prefix, show_whitespace=True)
compare("\n".join(expected_out), out.decode("utf8"), prefix=prefix, show_whitespace=True)

Expand Down
29 changes: 10 additions & 19 deletions cpplint_unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8; -*-
#
# Copyright (c) 2009 Google Inc. All rights reserved.
#
Expand Down Expand Up @@ -51,15 +50,13 @@


def codecs_latin_encode(x):
if sys.version_info < (3,):
return x
return codecs.latin_1_encode(x)[0]


# This class works as an error collector and replaces cpplint.Error
# function for the unit tests. We also verify each category we see
# is in cpplint._ERROR_CATEGORIES, to help keep that list up to date.
class ErrorCollector(object):
class ErrorCollector:
# These are a global list, covering all categories seen ever.
_ERROR_CATEGORIES = cpplint._ERROR_CATEGORIES
_SEEN_ERROR_CATEGORIES = {}
Expand Down Expand Up @@ -110,7 +107,7 @@ def RemoveIfPresent(self, substr):

# This class is a lame mock of codecs. We do not verify filename, mode, or
# encoding, but for the current use case it is not needed.
class MockIo(object):
class MockIo:
def __init__(self, mock_file):
# wrap list to allow "with open(mock)"
class EnterableList(list):
Expand Down Expand Up @@ -357,7 +354,7 @@ def testNestingInNamespace(self):
# Test get line width.
def testGetLineWidth(self):
self.assertEqual(0, cpplint.GetLineWidth(""))
self.assertEqual(10, cpplint.GetLineWidth(str("x") * 10))
self.assertEqual(10, cpplint.GetLineWidth("x" * 10))
self.assertEqual(16, cpplint.GetLineWidth("\u90fd|\u9053|\u5e9c|\u770c|\u652f\u5e81"))
self.assertEqual(16, cpplint.GetLineWidth("都|道|府|県|支庁"))
self.assertEqual(5 + 13 + 9, cpplint.GetLineWidth("d𝐱/dt" + "f : t ⨯ 𝐱 → ℝ" + "t ⨯ 𝐱 → ℝ"))
Expand Down Expand Up @@ -1056,21 +1053,17 @@ def testMockMethod(self):
self.assertEqual(
0,
error_collector.Results().count(
(
"Using deprecated casting style. "
"Use static_cast<bool>(...) instead "
"[readability/casting] [4]"
)
"Using deprecated casting style. "
"Use static_cast<bool>(...) instead "
"[readability/casting] [4]"
),
)
self.assertEqual(
1,
error_collector.Results().count(
(
"Using deprecated casting style. "
"Use static_cast<int>(...) instead "
"[readability/casting] [4]"
)
"Using deprecated casting style. "
"Use static_cast<int>(...) instead "
"[readability/casting] [4]"
),
)

Expand Down Expand Up @@ -4842,9 +4835,7 @@ def testRecursiveExclude(self):

expected = [os.path.join("src", "one.cc")]
cpplint._excludes = None
actual = cpplint.ParseArguments(
["--recursive", "--exclude=src{0}t*".format(os.sep), "src"]
)
actual = cpplint.ParseArguments(["--recursive", f"--exclude=src{os.sep}t*", "src"])
self.assertEqual(set(expected), set(actual))

expected = [os.path.join("src", "one.cc")]
Expand Down
30 changes: 15 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ lint.select = [
"TC", # flake8-type-checking
"TID", # flake8-tidy-imports
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle
"YTT", # flake8-2020
# "ANN", # flake8-annotations
Expand All @@ -124,7 +125,6 @@ lint.select = [
# "SLF", # flake8-self
# "T20", # flake8-print
# "TD", # flake8-todos
# "UP", # pyupgrade
]
lint.ignore = [
"FBT003", # flake8-boolean-trap
Expand All @@ -133,7 +133,7 @@ lint.ignore = [
"PIE790", # Unnecessary `pass` statement
]
lint.per-file-ignores."cpplint.py" = [ "ICN001", "PERF401", "PLR5501", "PLW0603", "PLW2901" ]
lint.per-file-ignores."cpplint_unittest.py" = [ "FLY002", "PLW0604" ]
lint.per-file-ignores."cpplint_unittest.py" = [ "FLY002", "PLW0604", "UP031" ]
lint.mccabe.max-complexity = 29
lint.pylint.allow-magic-value-types = [ "int", "str" ]
lint.pylint.max-args = 10 # Default is 5
Expand All @@ -145,13 +145,13 @@ lint.pylint.max-returns = 9 # Default is 9
lint.pylint.max-statements = 74 # Default is 50

[tool.pylint.basic]
argument-rgx = "[a-z_][a-z0-9_]{0,49}$"
class-rgx = "[A-Z_][a-zA-Z0-9]+$"
const-rgx = "[a-zA-Z_][A-Za-z0-9_]{2,49}$"
function-rgx = "[A-Z_][A-Za-z0-9]{2,49}$|main"
include-naming-hint = true
method-rgx = "[A-Z_][A-Za-z0-9]{2,49}$|__init__|__str__|__contains__"
function-rgx = "[A-Z_][A-Za-z0-9]{2,49}$|main"
const-rgx = "[a-zA-Z_][A-Za-z0-9_]{2,49}$"
variable-rgx = "[a-z_][a-z0-9_]{0,49}$"
argument-rgx = "[a-z_][a-z0-9_]{0,49}$"
class-rgx = "[A-Z_][a-zA-Z0-9]+$"

[tool.pylint.messages-control]
disable = [
Expand Down Expand Up @@ -180,25 +180,25 @@ reports = false
score = false

[tool.pylint.format]
indent-string = ' '
indent-after-paren = 4
indent-string = ' '
Comment on lines -183 to +184
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why this wasn't caught before...

Choose a reason for hiding this comment

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

What exactly? This is the same as it was on line 183, but the order was moved in toml.

Copy link
Member

@aaronliu0130 aaronliu0130 Mar 12, 2025

Choose a reason for hiding this comment

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

Hi Melroy! Yeah, I wonder why pyproject-fmt didn't catch any of this before.

max-module-lines = 10000

[tool.pylint.design]
max-locals = 25
max-line-length = 100
max-args = 20
max-attributes = 10
max-bool-expr = 10
max-branches = 30
max-args = 20
max-statements = 75
max-line-length = 100
max-locals = 25
max-returns = 10
max-statements = 75
min-public-methods = 0
max-bool-expr = 10

[tool.pytest.ini_options]
# fail if coverage is under 90%
addopts = "--color=yes --cov-fail-under=90 --cov=cpplint"
python_files = [ "*test.py" ]
testpaths = [ "." ]
required_plugins = [ "pytest-cov", "pytest-timeout" ]
testpaths = [ "." ]
timeout = 60
# fail if coverage is under 90%
addopts = "--color=yes --cov-fail-under=90 --cov=cpplint"
Loading