Skip to content

Commit

Permalink
remove pylint disable from codemodder code
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Feb 19, 2024
1 parent 7d3aef9 commit a8c528b
Show file tree
Hide file tree
Showing 20 changed files with 17 additions and 44 deletions.
6 changes: 2 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

## Pre-commit install

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


## Local Development
Expand All @@ -19,7 +17,7 @@ to specify a specific Python version. If using `bash` or any compatible shell, a

1. Run `pip install ".[all]"` to install packages used for development and testing

1. You should now be able to run `pylint`, `pytest`, etc.
1. You should now be able to run `ruff`, `pytest`, etc.


## Docker
Expand Down
1 change: 0 additions & 1 deletion integration_tests/base_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=no-member, protected-access, attribute-defined-outside-init
import git
import json
import os
Expand Down
2 changes: 1 addition & 1 deletion src/codemodder/codemods/base_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(
results: list[Result] | None,
line_exclude: list[int],
line_include: list[int],
): # pylint: disable=super-init-not-called
):
self.results = results
self.line_exclude = line_exclude
self.line_include = line_include
Expand Down
11 changes: 2 additions & 9 deletions src/codemodder/codemods/libcst_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def update_code(file_path, new_code):
f.write(new_code)


class LibcstResultTransformer(
BaseTransformer
): # pylint: disable=too-many-public-methods
class LibcstResultTransformer(BaseTransformer):
"""
Transformer class that performs libcst-based transformations on a given file
Expand Down Expand Up @@ -76,7 +74,6 @@ def transform(
def _new_or_updated_node(self, original_node, updated_node):
if self.node_is_selected(original_node):
if (attr := getattr(self, "on_result_found", None)) is not None:
# pylint: disable=not-callable
new_node = attr(original_node, updated_node)
self.report_change(original_node)
return new_node
Expand All @@ -102,7 +99,6 @@ def leave_ClassDef(
return self._new_or_updated_node(original_node, updated_node)

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

Expand Down Expand Up @@ -134,14 +130,11 @@ def report_change(self, original_node):
)

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

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

def update_call_target(
self,
Expand Down
4 changes: 2 additions & 2 deletions src/codemodder/codemods/sonar.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def from_core_codemod(
rules: list[str],
transformer: BaseTransformerPipeline | None = None,
new_references: list[Reference] | None = None,
): # pylint: disable=too-many-arguments
):
return SonarCodemod(
metadata=Metadata(
name=name,
summary="Sonar: " + other.summary,
review_guidance=other._metadata.review_guidance, # pylint: disable=protected-access
review_guidance=other._metadata.review_guidance,
references=(
other.references
if not new_references
Expand Down
1 change: 0 additions & 1 deletion src/codemodder/codemods/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class BaseType(Enum):
FALSE = 7


# pylint: disable-next=R0911
def infer_expression_type(node: cst.BaseExpression) -> Optional[BaseType]:
"""
Tries to infer if the resulting type of a given expression is one of the base literal types.
Expand Down
3 changes: 1 addition & 2 deletions src/codemodder/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
path_exclude: list[str],
tool_result_files_map: dict[str, list[str]] | None = None,
max_workers: int = 1,
): # pylint: disable=too-many-arguments
):
self.directory = directory
self.dry_run = dry_run
self.verbose = verbose
Expand Down Expand Up @@ -118,7 +118,6 @@ def process_dependencies(
self._dependency_update_by_codemod[codemod_id] = None
return record

# pylint: disable-next=cyclic-import
from codemodder.dependency_management import DependencyManager

for package_store in store_list:
Expand Down
2 changes: 1 addition & 1 deletion src/codemodder/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Result(ABCDataclass):
rule_id: str
locations: list[Location]

def match_location(self, pos, node): # pylint: disable=unused-argument
def match_location(self, pos, node):
for location in self.locations:
start_column = location.start.column
end_column = location.end.column
Expand Down
5 changes: 1 addition & 4 deletions src/core_codemods/file_resource_leak.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ def __init__(
self.leaked_assigned_resources = leaked_assigned_resources
self.changes: list[Change] = []

def _is_fixable(
self, block, index, named_targets, other_targets
) -> bool: # pylint: disable=too-many-arguments
def _is_fixable(self, block, index, named_targets, other_targets) -> bool:
# assigned to something that is not a Name?
if other_targets:
return False
Expand Down Expand Up @@ -363,7 +361,6 @@ def _find_transitive_assignment_targets(
return named_targets, other_targets
return ([], [])

# pylint: disable-next=too-many-arguments
def _wrap_in_with_statement(
self,
stmts: list[SimpleStatementLine],
Expand Down
1 change: 0 additions & 1 deletion src/core_codemods/fix_async_task_instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class FixAsyncTaskInstantiation(SimpleCodemod, NameAndAncestorResolutionMixin):
change_description = "Replace instantiation of `asyncio.Task` with higher-level functions to create tasks."
_module_name = "asyncio"

# pylint: disable=too-many-return-statements
def leave_Call(self, original_node: cst.Call, updated_node: cst.Call) -> cst.Call:
if not self.filter_by_path_includes_or_excludes(
self.node_position(original_node)
Expand Down
2 changes: 1 addition & 1 deletion src/core_codemods/flask_json_response_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class FlaskJsonResponseTypeVisitor(
content_type_key = "Content-Type"
json_content_type = "application/json"

def __init__( # pylint: disable=super-init-not-called
def __init__(
self,
context: CodemodContext,
file_context: FileContext,
Expand Down
1 change: 0 additions & 1 deletion src/core_codemods/sql_parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def _fix_injection(

return (prepend, append)

# pylint: disable-next=too-many-arguments
def _remove_literal_and_gather_extra(
self, original_node, updated_node, prefix, new_raw_value, extra_raw_value
) -> Optional[SimpleString]:
Expand Down
1 change: 0 additions & 1 deletion src/core_codemods/url_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ def _find_assignments(self, node: CSTNode):
Given a MetadataWrapper and a CSTNode representing an access, find all the possible assignments that it refers.
"""
scope = self.get_metadata(ScopeProvider, node)
# pylint: disable=protected-access
return next(iter(scope.accesses[node]))._Access__assignments

def find_single_assignment(self, node: CSTNode) -> Optional[CSTNode]:
Expand Down
11 changes: 4 additions & 7 deletions tests/codemods/base_codemod_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=no-member,not-callable,attribute-defined-outside-init
import os
from pathlib import Path
from textwrap import dedent
Expand All @@ -20,7 +19,7 @@ def setup_method(self):
self.codemod = self.codemod()
self.changeset = []

def run_and_assert( # pylint: disable=too-many-arguments
def run_and_assert(
self,
tmpdir,
input_code,
Expand Down Expand Up @@ -68,9 +67,7 @@ def run_and_assert( # pylint: disable=too-many-arguments
changes[0],
)

def assert_changes( # pylint: disable=too-many-arguments
self, root, file_path, input_code, expected, changes
):
def assert_changes(self, root, file_path, input_code, expected, changes):
expected_diff = create_diff(
dedent(input_code).splitlines(keepends=True),
dedent(expected).splitlines(keepends=True),
Expand All @@ -84,7 +81,7 @@ def assert_changes( # pylint: disable=too-many-arguments

assert output_code == dedent(expected)

def run_and_assert_filepath( # pylint: disable=too-many-arguments
def run_and_assert_filepath(
self,
root: Path,
file_path: Path,
Expand Down Expand Up @@ -133,7 +130,7 @@ def create_dir_structure(self, tmpdir):
class BaseSASTCodemodTest(BaseCodemodTest):
tool: ClassVar = NotImplemented

def run_and_assert( # pylint: disable=too-many-arguments
def run_and_assert(
self,
tmpdir,
input_code,
Expand Down
4 changes: 1 addition & 3 deletions tests/codemods/test_include_exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ class TestMatchCodemods:
@classmethod
def setup_class(cls):
cls.registry = load_registered_codemods()
cls.codemod_map = (
cls.registry._codemods_by_name # pylint: disable=protected-access
)
cls.codemod_map = cls.registry._codemods_by_name
cls.default_ids = [
c().id if isinstance(c, type) else c.id for c in registry.codemods
]
Expand Down
2 changes: 1 addition & 1 deletion tests/dependency_management/test_base_dependency_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class FakeDependencyWriter(DependencyWriter):
def add_to_file( # pylint: disable=useless-return
def add_to_file(
self, dependencies: list[Dependency], dry_run: bool = False
) -> ChangeSet | None:
del dependencies, dry_run
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=redefined-outer-name
import pytest
from codemodder.project_analysis.file_parsers import PyprojectTomlParser

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=redefined-outer-name
import pytest
from codemodder.project_analysis.file_parsers import SetupCfgParser

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=redefined-outer-name
import pytest
from codemodder.project_analysis.file_parsers import SetupPyParser

Expand Down
1 change: 0 additions & 1 deletion tests/test_code_directory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=redefined-outer-name
from pathlib import Path
import pytest

Expand Down

0 comments on commit a8c528b

Please sign in to comment.