Skip to content

Commit cad53d7

Browse files
authored
chore: Use ruff to replace other linters used in pre-commit hook (#1062)
* chore: Use ruff to replace other linters used in pre-commit hook (backport #1058) * Add bandit checks to ruff * Replace flake8 with ruff * Add isort check to ruff * Autofix ruff lint errors * Set line-length to 100 * Replace black with ruff format * Reformat with ruff * Move ruff and codespell config to pyproject.toml * Retain black configuration * Move codespell configuration back to setup.cfg * Format code before linting it in pre-commit * Enable more ruff lint rules * Fix isort problems
1 parent ddf066d commit cad53d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+141
-92
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,6 @@ repos:
1515
- id: mixed-line-ending
1616
- id: trailing-whitespace
1717

18-
- repo: https://github.com/pycqa/isort
19-
rev: 5.13.2
20-
hooks:
21-
- id: isort
22-
23-
- repo: https://github.com/psf/black
24-
rev: 24.8.0
25-
hooks:
26-
- id: black
27-
28-
- repo: https://github.com/PyCQA/flake8
29-
rev: 7.1.1
30-
hooks:
31-
- id: flake8
32-
33-
- repo: https://github.com/PyCQA/bandit
34-
rev: 1.7.10
35-
hooks:
36-
- id: bandit
37-
args: ["--skip", "B101,B110,B311"]
38-
3918
- repo: https://github.com/codespell-project/codespell
4019
rev: v2.3.0
4120
hooks:
@@ -44,4 +23,5 @@ repos:
4423
- repo: https://github.com/astral-sh/ruff-pre-commit
4524
rev: v0.12.7
4625
hooks:
26+
- id: ruff-format
4727
- id: ruff-check

pyproject.toml

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,96 @@
1-
[tool.bandit]
2-
skips = ["B101", "B110", "B311"]
3-
41
[tool.black]
2+
# We use ruff for formatting, but black formatter should be compatible with ruff.
3+
line-length = 100
4+
5+
[tool.ruff]
56
line-length = 100
7+
8+
[tool.ruff.lint]
9+
select = [
10+
# "AIR", # Airflow
11+
# "ERA", # Eradicate
12+
# "FAST", # FastAPI
13+
14+
# flake8 extensions
15+
"YTT", # flake8-2020
16+
# "ANN", # flake8-annotations
17+
"ASYNC", # flake8-async
18+
"S", # flake8-bandit
19+
# "BLE", # flake8-blind-except
20+
# "FBT", # flake8-boolean-trap
21+
# "B", # flake8-bugbear
22+
# "A", # flake8-builtins
23+
# "COM", # flake8-commas
24+
"C4", # flake8-comprehensions
25+
# "CPY", # flake8-copyright
26+
# "DTZ", # flake8-datetimez
27+
"T10", # flake8-debugger
28+
# "DJ", # flake8-django
29+
# "EM", # flake8-errmsg
30+
# "EXE", # flake8-executable
31+
# "FIX", # flake8-fixme
32+
# "FA", # flake8-future-annotations
33+
"INT", # flake8-gettext
34+
# "ISC", # flake8-implicit-str-concat
35+
"ICN", # flake8-import-conventions
36+
# "LOG", # flake8-logging
37+
# "G", # flake8-logging-format
38+
# "INP", # flake8-no-pep420
39+
# "PIE", # flake8-pie
40+
# "T20", # flake8-print
41+
# "PYI", # flake8-pyi
42+
# "PT", # flake8-pytest-style
43+
"Q", # flake8-quotes
44+
# "RSE", # flake8-raise
45+
# "RET", # flake8-return
46+
# "SLF", # flake8-self
47+
# "SIM", # flake8-simplify
48+
"SLOT", # flake8-slots
49+
"TID", # flake8-tidy-imports
50+
# "TD", # flake8-todos
51+
# "TC", # flake8-type-checking
52+
# "ARG", # flake8-unused-arguments
53+
# "PTH", # flake8-use-pathlib
54+
55+
"FLY", # flynt
56+
"I", # isort
57+
"C90", # mccabe
58+
"NPY", # numpy
59+
"PD", # pandas-vet
60+
# "N", # pep8-naming
61+
# "PERF", # Perflint
62+
"E", # pycodestyle errors
63+
"W", # pycodestyle warnings
64+
# "DOC", # pydoclint
65+
"D", # pydocstyle
66+
"F", # pyflakes
67+
"PGH", # pygrep-hooks
68+
# "PL", # pylint
69+
# "UP", # pyupgrade
70+
# "FURB", # refurb
71+
# "RUF", # ruff
72+
# "TRY", # tryceratops
73+
]
74+
ignore = [
75+
# Undocumented code
76+
"D100",
77+
"D101",
78+
"D102",
79+
"D103",
80+
"D104",
81+
"D105",
82+
"D106",
83+
"D107",
84+
85+
# Conflicting pydocstyle rules
86+
"D203", # incorrect-blank-line-before-class
87+
"D212", # multi-line-summary-first-line
88+
89+
"S101", # assert
90+
"S110", # try-except-pass
91+
"S311", # suspicious-non-cryptographic-random-usage
92+
]
93+
94+
mccabe.max-complexity = 36
95+
96+
pycodestyle.max-line-length = 217

rosapi/scripts/rosapi_node

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ from rosapi_msgs.srv import (
7070

7171

7272
class Rosapi(Node):
73-
7473
NAME = "rosapi"
7574

7675
def __init__(self):

rosapi/src/rosapi/params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from rcl_interfaces.srv import ListParameters
4040
from ros2node.api import get_absolute_node_name
4141
from ros2param.api import call_get_parameters, call_set_parameters, get_parameter_value
42+
4243
from rosapi.proxy import get_nodes
4344

4445
""" Methods to interact with the param server. Values have to be passed

rosbridge_library/src/rosbridge_library/capabilities/action_feedback.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737

3838
class ActionFeedback(Capability):
39-
4039
action_feedback_msg_fields = [
4140
(True, "action", str),
4241
(False, "id", str),

rosbridge_library/src/rosbridge_library/capabilities/action_result.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737

3838
class ActionResult(Capability):
39-
4039
action_result_msg_fields = [
4140
(True, "action", str),
4241
(False, "id", str),

rosbridge_library/src/rosbridge_library/capabilities/advertise.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ def is_empty(self):
8080

8181

8282
class Advertise(Capability):
83-
8483
advertise_msg_fields = [(True, "topic", str), (True, "type", str)]
8584
unadvertise_msg_fields = [(True, "topic", str)]
8685

rosbridge_library/src/rosbridge_library/capabilities/advertise_action.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
from rclpy.action import ActionServer
3939
from rclpy.action.server import CancelResponse, ServerGoalHandle
4040
from rclpy.callback_groups import ReentrantCallbackGroup
41+
4142
from rosbridge_library.capability import Capability
4243
from rosbridge_library.internal import message_conversion
4344
from rosbridge_library.internal.ros_loader import get_action_class
4445
from rosbridge_library.protocol import Protocol
4546

4647

4748
class AdvertisedActionHandler:
48-
4949
id_counter = 1
5050

5151
def __init__(

rosbridge_library/src/rosbridge_library/capabilities/advertise_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import rclpy
44
from rclpy.callback_groups import ReentrantCallbackGroup
5+
56
from rosbridge_library.capability import Capability
67
from rosbridge_library.internal import message_conversion
78
from rosbridge_library.internal.ros_loader import get_service_class
89

910

1011
class AdvertisedServiceHandler:
11-
1212
id_counter = 1
1313

1414
def __init__(self, service_name, service_type, protocol):

rosbridge_library/src/rosbridge_library/capabilities/call_service.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939

4040

4141
class CallService(Capability):
42-
4342
call_service_msg_fields = [
4443
(True, "service", str),
4544
(False, "fragment_size", (int, type(None))),

0 commit comments

Comments
 (0)