Skip to content

Commit 8d6a03d

Browse files
authored
Replace pylint with ruff (pixee#277)
* fix code to comply with ruff * replace pylint with ruff in pre-commit * remove pylint disable from codemodder code * update contributing.md * add ruff to makefile
1 parent 9b5d38b commit 8d6a03d

35 files changed

Lines changed: 48 additions & 121 deletions

‎.github/workflows/lint.yml‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,6 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
jobs:
19-
linting:
20-
name: Pylint Checks
21-
runs-on: ubuntu-20.04
22-
timeout-minutes: 5
23-
steps:
24-
- name: Set Up Python
25-
uses: actions/setup-python@v5
26-
with:
27-
python-version: '3.11'
28-
- name: Check out code
29-
uses: actions/checkout@v4
30-
- name: Install Codemodder Package
31-
run: pip install .
32-
- name: Install Dependencies
33-
run: pip install ".[test]"
34-
- name: Run pylint
35-
run: make lint
36-
3719
complexity:
3820
name: Code Complexity
3921
runs-on: ubuntu-20.04

‎.pre-commit-config.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ repos:
3838
"types-PyYAML==6.0",
3939
"types-toml~=0.10",
4040
]
41+
- repo: https://github.com/astral-sh/ruff-pre-commit
42+
rev: v0.2.2
43+
hooks:
44+
- id: ruff
45+
exclude: tests/samples/
46+
# todo: replace black with this?
47+
# Run the formatter.
48+
# - id: ruff-format

‎CONTRIBUTING.md‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
## Pre-commit install
44

5-
We use [pre-commit](https://pre-commit.com/) to run some quick linting such as `black`.
6-
While pre-commit isn't configured in CI, `black` is. `pylint` and running tests are not configured
7-
for pre-commit so commiting is fast.
5+
We use [pre-commit](https://pre-commit.com/) to run some quick linting such as `black` and `ruff`.
6+
This also runs in CI.
87

98

109
## Local Development
@@ -15,11 +14,11 @@ but for local development here is a good workflow.
1514
1. To use virtualenv, create an environment with `virtualenv pixeeenv` or `/usr/bin/env python3 -m venv pixeeenv`
1615
to specify a specific Python version. If using `bash` or any compatible shell, activate with `source pixeeenv/bin/activate`. Otherwise, look at [`venv`'s documentation](https://docs.python.org/3/library/venv.html) for instructions.
1716

18-
1. `cd codemodder-python` and `pip install -e .` to install the package in development mode
17+
2. `cd codemodder-python` and `pip install -e .` to install the package in development mode
1918

20-
1. Run `pip install ".[all]"` to install packages used for development and testing
19+
3. Run `pip install ".[all]"` to install packages used for development and testing
2120

22-
1. You should now be able to run `pylint`, `pytest`, etc.
21+
4. You should now be able to run `ruff`, `pytest`, etc.
2322

2423

2524
## Docker

‎Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pygoat-test:
1212
${PYTEST} -v ci_tests/test_pygoat_findings.py
1313

1414
lint:
15-
pylint -v codemodder core_codemods tests integration_tests
15+
ruff check src tests integration_tests --exclude tests/samples/
1616

1717
radon:
1818
radon cc codemodder --min A --total-average

‎integration_tests/base_test.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# pylint: disable=no-member, protected-access, attribute-defined-outside-init
21
import git
32
import json
43
import os

‎pylintrc‎

Lines changed: 0 additions & 41 deletions
This file was deleted.

‎src/codemodder/codemods/api.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import libcst as cst
55

6-
from codemodder.codemods.base_codemod import ( # pylint: disable=unused-import
6+
from codemodder.codemods.base_codemod import ( # noqa: F401
77
BaseCodemod,
88
Metadata,
99
Reference,
@@ -13,7 +13,7 @@
1313
LibcstResultTransformer,
1414
LibcstTransformerPipeline,
1515
)
16-
from codemodder.file_context import FileContext # pylint: disable=unused-import
16+
from codemodder.file_context import FileContext # noqa: F401
1717
from codemodder.codemods.semgrep import SemgrepRuleDetector
1818

1919

‎src/codemodder/codemods/base_visitor.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(
1515
results: list[Result] | None,
1616
line_exclude: list[int],
1717
line_include: list[int],
18-
): # pylint: disable=super-init-not-called
18+
):
1919
self.results = results
2020
self.line_exclude = line_exclude
2121
self.line_include = line_include

‎src/codemodder/codemods/libcst_transformer.py‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def update_code(file_path, new_code):
2929
f.write(new_code)
3030

3131

32-
class LibcstResultTransformer(
33-
BaseTransformer
34-
): # pylint: disable=too-many-public-methods
32+
class LibcstResultTransformer(BaseTransformer):
3533
"""
3634
Transformer class that performs libcst-based transformations on a given file
3735
@@ -76,7 +74,6 @@ def transform(
7674
def _new_or_updated_node(self, original_node, updated_node):
7775
if self.node_is_selected(original_node):
7876
if (attr := getattr(self, "on_result_found", None)) is not None:
79-
# pylint: disable=not-callable
8077
new_node = attr(original_node, updated_node)
8178
self.report_change(original_node)
8279
return new_node
@@ -102,7 +99,6 @@ def leave_ClassDef(
10299
return self._new_or_updated_node(original_node, updated_node)
103100

104101
def node_position(self, node):
105-
# pylint: disable=no-member
106102
# See https://github.com/Instagram/LibCST/blob/main/libcst/_metadata_dependent.py#L112
107103
return self.get_metadata(self.METADATA_DEPENDENCIES[0], node)
108104

@@ -134,14 +130,11 @@ def report_change(self, original_node):
134130
)
135131

136132
def remove_unused_import(self, original_node):
137-
# pylint: disable=no-member
138133
RemoveImportsVisitor.remove_unused_import_by_node(self.context, original_node)
139134

140135
def add_needed_import(self, module, obj=None):
141136
# TODO: do we need to check if this import already exists?
142-
AddImportsVisitor.add_needed_import(
143-
self.context, module, obj # pylint: disable=no-member
144-
)
137+
AddImportsVisitor.add_needed_import(self.context, module, obj)
145138

146139
def update_call_target(
147140
self,

‎src/codemodder/codemods/sonar.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ def from_core_codemod(
2121
rules: list[str],
2222
transformer: BaseTransformerPipeline | None = None,
2323
new_references: list[Reference] | None = None,
24-
): # pylint: disable=too-many-arguments
24+
):
2525
return SonarCodemod(
2626
metadata=Metadata(
2727
name=name,
2828
summary="Sonar: " + other.summary,
29-
review_guidance=other._metadata.review_guidance, # pylint: disable=protected-access
29+
review_guidance=other._metadata.review_guidance,
3030
references=(
3131
other.references
3232
if not new_references

0 commit comments

Comments
 (0)