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 7a8bdb2
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 124 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/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from importlib.metadata import version as pkg_version
from logging import Logger

import slither_lsp.app.request_handlers as request_handlers
import slither_lsp.app.types.params as slsp
from slither_lsp.app import request_handlers
from slither_lsp.app.slither_server import SlitherServer


Expand Down
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,11 @@
# pylint: disable=protected-access

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/goto_def_impl_refs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: disable=broad-exception-caught

from typing import TYPE_CHECKING, Callable, List, Optional, Set

import lsprotocol.types as lsp
Expand Down
31 changes: 17 additions & 14 deletions slither_lsp/app/request_handlers/symbols.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: disable=too-many-branches

from typing import TYPE_CHECKING, List, Optional

import lsprotocol.types as lsp
Expand All @@ -21,6 +23,17 @@ def document_symbol(
# Obtain our filename for this file
target_filename_str: str = uri_to_fs_path(params.text_document.uri)
res: List[lsp.DocumentSymbol] = []

def add_child(children, obj, kind):
children.append(
lsp.DocumentSymbol(
name=obj.name,
kind=kind,
range=source_to_range(obj.source_mapping),
selection_range=get_object_name_range(obj, comp),
)
)

for analysis, comp in ls.get_analyses_containing(target_filename_str):
filename = comp.filename_lookup(target_filename_str)

Expand All @@ -36,35 +49,25 @@ def document_symbol(
kind = lsp.SymbolKind.Class
children: List[lsp.DocumentSymbol] = []

def add_child(obj, kind):
children.append(
lsp.DocumentSymbol(
name=obj.name,
kind=kind,
range=source_to_range(obj.source_mapping),
selection_range=get_object_name_range(obj, comp),
)
)

for struct in contract.structures_declared:
if struct.source_mapping is None:
continue
add_child(struct, lsp.SymbolKind.Struct)
add_child(children, struct, lsp.SymbolKind.Struct)

for enum in contract.enums_declared:
if enum.source_mapping is None:
continue
add_child(enum, lsp.SymbolKind.Enum)
add_child(children, enum, lsp.SymbolKind.Enum)

for event in contract.events_declared:
if event.source_mapping is None:
continue
add_child(event, lsp.SymbolKind.Enum)
add_child(children, event, lsp.SymbolKind.Enum)

for func in contract.functions_and_modifiers_declared:
if func.source_mapping is None:
continue
add_child(func, lsp.SymbolKind.Function)
add_child(children, func, lsp.SymbolKind.Function)

res.append(
lsp.DocumentSymbol(
Expand Down
12 changes: 6 additions & 6 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 Expand Up @@ -114,14 +114,14 @@ def on_get_subtypes(
for other_contract, other_contract_comp in contracts:
if contract not in other_contract.immediate_inheritance:
continue
range = get_object_name_range(other_contract, other_contract_comp)
range_ = get_object_name_range(other_contract, other_contract_comp)
if other_contract.is_interface:
kind = lsp.SymbolKind.Interface
else:
kind = lsp.SymbolKind.Class
item = TypeItem(
name=other_contract.name,
range=to_range(range),
range=to_range(range_),
kind=kind,
filename=other_contract.source_mapping.filename.absolute,
offset=get_definition(other_contract, other_contract_comp).start,
Expand Down Expand Up @@ -169,14 +169,14 @@ def on_get_supertypes(
]

for sup, comp in supertypes:
range = get_object_name_range(sup, comp)
range_ = get_object_name_range(sup, comp)
if sup.is_interface:
kind = lsp.SymbolKind.Interface
else:
kind = lsp.SymbolKind.Class
item = TypeItem(
name=sup.name,
range=to_range(range),
range=to_range(range_),
kind=kind,
filename=sup.source_mapping.filename.absolute,
offset=get_definition(sup, comp).start,
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))
8 changes: 5 additions & 3 deletions slither_lsp/app/slither_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# pylint: disable=broad-exception-caught, protected-access

import logging
from collections import defaultdict
from concurrent.futures import ThreadPoolExecutor
Expand Down Expand Up @@ -102,7 +104,7 @@ def on_initialize(ls: SlitherServer, params):
ls._on_initialize(params)

@self.feature(lsp.INITIALIZED)
def on_initialized(ls: SlitherServer, params):
def on_initialized(ls: SlitherServer):
ls.show_message("slither-lsp initialized", lsp.MessageType.Debug)

@self.thread()
Expand Down Expand Up @@ -179,7 +181,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 +234,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
22 changes: 11 additions & 11 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 All @@ -93,15 +93,15 @@ class SlitherDetectorResult:
""" Source mapped elements that are relevant to this detector result. """

@staticmethod
def from_dict(dict):
def from_dict(dict_):
return SlitherDetectorResult(
check=dict["check"],
confidence=dict["confidence"],
impact=dict["impact"],
description=dict["description"],
check=dict_["check"],
confidence=dict_["confidence"],
impact=dict_["impact"],
description=dict_["description"],
elements=[
SlitherDetectorResultElement.from_dict(elem)
for elem in dict["elements"]
for elem in dict_["elements"]
],
)

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 7a8bdb2

Please sign in to comment.