Skip to content

Commit

Permalink
Fix pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
frabert committed Apr 9, 2024
1 parent b972041 commit 5fa26ff
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 98 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
run: |
mkdir -p .github/linters
cp pyproject.toml .github/linters
pip install .
- name: Register pylint problem matcher
run: |
Expand Down
20 changes: 17 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,22 @@ slither-lsp = "slither_lsp.__main__:main"
max-line-length = 120

disable = """
import-outside-toplevel,
missing-module-docstring,
useless-return,
duplicate-code
missing-class-docstring,
missing-function-docstring,
unnecessary-lambda,
cyclic-import,
line-too-long,
invalid-name,
fixme,
too-many-return-statements,
too-many-ancestors,
logging-fstring-interpolation,
logging-not-lazy,
duplicate-code,
import-error,
unsubscriptable-object,
unnecessary-lambda-assignment,
too-few-public-methods,
too-many-instance-attributes
"""
2 changes: 1 addition & 1 deletion slither_lsp/app/feature_analyses/slither_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def clear(self) -> None:
:return: None
"""
# Loop through all diagnostic files, publish new diagnostics for each file with no items.
for file_uri in self.diagnostics.keys():
for file_uri, _ in self.diagnostics:
self._clear_single(file_uri, False)

# Clear the dictionary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from typing import Any

from pygls.server import LanguageServer
from slither.__main__ import get_detectors_and_printers, output_detectors_json


def get_detector_list(ls: LanguageServer, params: Any) -> Any:
def get_detector_list():
"""
Handler which invokes slither to obtain a list of all detectors and some properties that describe them.
"""
Expand Down
5 changes: 1 addition & 4 deletions slither_lsp/app/request_handlers/analysis/get_version.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
from importlib.metadata import version as pkg_version
from typing import Any

from pygls.server import LanguageServer


def get_version(ls: LanguageServer, params: Any) -> Any:
def get_version():
"""
Handler which retrieves versions for slither, crytic-compile, and related applications.
"""
Expand Down
2 changes: 1 addition & 1 deletion slither_lsp/app/request_handlers/call_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def on_prepare_call_hierarchy(
"offset": offset,
},
)
return [elem for elem in res.values()]
return list(res.values())


def register_on_get_incoming_calls(ls: "SlitherServer"):
Expand Down
1 change: 0 additions & 1 deletion slither_lsp/app/request_handlers/compilation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .autogenerate_standard_json import autogenerate_standard_json
from .get_command_line_args import get_command_line_args

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from argparse import ArgumentParser
from typing import Any

from crytic_compile.cryticparser.cryticparser import init as crytic_parser_init
from pygls.server import LanguageServer


def get_command_line_args(ls: LanguageServer, params: Any) -> Any:
def get_command_line_args():
"""
Handler which obtains data regarding all command line arguments available in crytic-compile.
"""
Expand Down
2 changes: 2 additions & 0 deletions slither_lsp/app/request_handlers/symbols.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: enable=too-many-branches

from typing import TYPE_CHECKING, List, Optional

import lsprotocol.types as lsp
Expand Down
4 changes: 2 additions & 2 deletions slither_lsp/app/request_handlers/type_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def on_prepare_type_hierarchy(
if not isinstance(obj, Contract):
continue
offset = get_definition(obj, comp).start
range = get_object_name_range(obj, comp)
range_ = get_object_name_range(obj, comp)
if obj.is_interface:
kind = lsp.SymbolKind.Interface
else:
kind = lsp.SymbolKind.Class
res.add(
TypeItem(
name=obj.name,
range=to_range(range),
range=to_range(range_),
kind=kind,
filename=source.filename.absolute,
offset=offset,
Expand Down
8 changes: 4 additions & 4 deletions slither_lsp/app/request_handlers/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def to_lsp_pos(pos: Pos) -> lsp.Position:
return lsp.Position(line=pos[0], character=pos[1])


def to_lsp_range(range: Range) -> lsp.Range:
return lsp.Range(start=to_lsp_pos(range[0]), end=to_lsp_pos(range[1]))
def to_lsp_range(range_: Range) -> lsp.Range:
return lsp.Range(start=to_lsp_pos(range_[0]), end=to_lsp_pos(range_[1]))


def to_pos(pos: lsp.Position) -> Pos:
return (pos.line, pos.character)


def to_range(range: lsp.Range) -> Range:
return (to_pos(range.start), to_pos(range.end))
def to_range(range_: lsp.Range) -> Range:
return (to_pos(range_.start), to_pos(range_.end))
4 changes: 2 additions & 2 deletions slither_lsp/app/slither_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def queue_compile_workspace(self, uri: str):
path = uri_to_fs_path(uri)
workspace_name = split(path)[1]

def compile():
def do_compile():
detector_classes, _ = get_detectors_and_printers()
with self.workspace_in_progress[uri]:
self.show_message(
Expand Down Expand Up @@ -232,7 +232,7 @@ def compile():
)
self._refresh_detector_output()

self.analysis_pool.submit(compile)
self.analysis_pool.submit(do_compile)

def _on_did_change_workspace_folders(
self, params: lsp.DidChangeWorkspaceFoldersParams
Expand Down
10 changes: 5 additions & 5 deletions slither_lsp/app/types/analysis_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ class SlitherDetectorResultElement:
""" The type of item this represents (contract, function, etc.) """

@staticmethod
def from_dict(dict):
def from_dict(dict_):
return SlitherDetectorResultElement(
name=dict["name"],
name=dict_["name"],
source_mapping=(
SlitherDetectorResultElementSourceMapping(**dict["source_mapping"])
if dict["source_mapping"]
SlitherDetectorResultElementSourceMapping(**dict_["source_mapping"])
if dict_["source_mapping"]
else None
),
type=dict["type"],
type=dict_["type"],
)


Expand Down
2 changes: 1 addition & 1 deletion slither_lsp/app/utils/file_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def is_solidity_file(path: str) -> bool:
filename_base, file_extension = os.path.splitext(path)
_, file_extension = os.path.splitext(path)
return file_extension is not None and file_extension.lower() == ".sol"


Expand Down

0 comments on commit 5fa26ff

Please sign in to comment.