Skip to content

Conversation

@zachflanders-frb
Copy link
Contributor

@zachflanders-frb zachflanders-frb commented Oct 24, 2025

Description:

This is a proof of concept for adding code quality checks back into our CI/CD pipeline. We previously used CodeClimate, but that product has been discontinued. The pylint library very established library that has checks that match all of the checks that we previously used with CodeClimate and could be a good replacement for our code quality checks.

This PR is a good opportunity to discuss which checks we want to have going forward. The pylint user guide includes a complete list of checks.

CodeClimate check name description Pylint check name Pylint description
argument count methods or functions defined with a high number of arguments too-many-arguments Used when a function or method takes too many arguments.
complex logic Boolean logic that may be hard to understand too-many-branches, too-many-boolean-expressions Used when a function or method has too many branches, making it hard to follow., Used when an if statement contains too many boolean expressions.
file lines Excessive lines of code within a single file too-many-lines Used when a module has too many lines, reducing its readability.
method complexity Functions or methods that may be hard to understand (cognitive complexity) too-complex Used when a method or function is too complex based on McCabe Complexity Cyclomatic
method count Classes defined with a high number of functions or methods too-many-instance-attributes, too-many-public-methods Used when class has too many instance attributes, try to reduce this to get a simpler (and so easier to use) class., Used when class has too many public methods, try to reduce this to get a simpler (and so easier to use) class.
method lines excessive lines of code within a single function or method too-many-statements Used when a function or method has too many statements. You should then split it in smaller functions / methods.
nested control flow deeply nested control structures like if or case too-many-nested-blocks Used when a function or a method has too many nested blocks. This makes the code less understandable and maintainable.
return statements functions of methods with a high number of return statements too-many-return-statements Used when a function or method has too many return statement, making it hard to follow.
similar code duplicate code which is not identical but shares the same structure duplicate-code Indicates that a set of similar lines has been detected among multiple file. This usually means that the code should be refactored to avoid this duplication.

I included a test file to trigger a code climate check failure. You can see the failure message here.

************* Module usaspending-api.usaspending_api.code_quality_poc.pylint-test
usaspending_api/code_quality_poc/pylint-test.py:4:0: R0913: Too many arguments (10/6) (too-many-arguments)
usaspending_api/code_quality_poc/pylint-test.py:7:0: R0902: Too many instance attributes (21/10) (too-many-instance-attributes)
usaspending_api/code_quality_poc/pylint-test.py:84:4: R0911: Too many return statements (5/3) (too-many-return-statements)
usaspending_api/code_quality_poc/pylint-test.py:7:0: R0904: Too many public methods (23/20) (too-many-public-methods)

@zachflanders-frb zachflanders-frb added the do not merge [PR] shouldn't be merged label Oct 24, 2025
- name: install pylint
run: pip install pylint==4.0.2
- name: pylint
run: pylint ${{ steps.changed-files.outputs.all_changed_files }}
Copy link
Contributor Author

@zachflanders-frb zachflanders-frb Oct 24, 2025

Choose a reason for hiding this comment

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

Checks can be run on just the files changed in the PR.

Comment on lines +43 to +54
enable = [
"too-many-instance-attributes",
"too-many-public-methods",
"too-many-return-statements",
"too-many-branches",
"too-many-arguments",
"too-many-statements",
"too-many-boolean-expressions",
"too-complex",
"too-many-lines",
"too-many-nested-blocks"
]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checks can be enabled in the pyproject.toml

Comment on lines +56 to +71
[tool.pylint.design]
max-args = 6
max-public-methods = 20
max-attributes = 10
max-bool-expr = 8
max-branches = 10
max-returns = 3
max-statements = 45
max-complexity=10


[tool.pylint.format]
max-module-lines = 250

[tool.pylint.refactoring]
max-nested-blocks = 5
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checks can be configured in the pyproject.toml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not merge [PR] shouldn't be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants