Skip to content

Commit

Permalink
fix: fix PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GirZ0n committed Sep 19, 2023
1 parent ae2c803 commit b7f24a0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Python language (all versions can be found in the [requirements.txt](requirement
* [Site and docs](https://radon.readthedocs.io/en/latest/)
* [Repository](https://github.com/rubik/radon)

- [x] Python IJ Inspections
- [x] Python IJ Inspections [MIT]
* [Site and docs](https://www.jetbrains.com/help/pycharm/disabling-and-enabling-inspections.html)
* [Repository](https://github.com/JetBrains-Research/code-quality-ij-server/tree/master)

Expand All @@ -63,7 +63,7 @@ Kotlin language:
* [Site and docs](https://detekt.github.io/detekt/)
* [Repository](https://github.com/detekt/detekt)

- [x] Kotlin IJ inspections
- [x] Kotlin IJ inspections [MIT]
* [Site and docs](https://www.jetbrains.com/help/idea/code-inspection.html)
* [Repository](https://github.com/JetBrains-Research/code-quality-ij-server/tree/master)

Expand Down Expand Up @@ -141,7 +141,7 @@ curl -sSLO https://github.com/pmd/pmd/releases/download/pmd_releases/${PMD_VERSI
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GOLANG_LINT_DIRECTORY} v${GOLANG_LINT_VERSION}
```

Also, you should generate model files for IntelliJ-based inspectors:
Also, you must generate model files for IntelliJ-based inspectors:
```bash
python3 -m grpc_tools.protoc --proto_path=. --python_out=. --pyi_out=. --grpc_python_out=. hyperstyle/src/python/review/inspectors/common/inspector/proto/model.proto
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,15 @@ def language_id(self) -> model_pb2.LanguageId:
def issue_configs(self) -> List[IssueConfig]:
raise NotImplementedError('issue_configs property is not implemented yet')

@staticmethod
@property
@abstractmethod
def ij_inspection_to_issue_type(self) -> Dict[str, IssueType]:
raise NotImplementedError('ij_inspection_to_issue_type property is not implemented yet')

@property
@abstractmethod
def choose_issue_type(issue: model_pb2.Problem) -> IssueType:
raise NotImplementedError('choose_issue_type method is not implemented yet')
def ij_message_to_issue_type(self) -> Dict[str, Dict[str, IssueType]]:
raise NotImplementedError('ij_message_to_issue_type property is not implemented yet')

def setup_connection_parameters(self, host: str, port: int):
self.host = host
Expand Down Expand Up @@ -135,3 +140,15 @@ def _get_inspection_result(self, code_text: str, file_path: Path) -> List[BaseIs
# TODO: replace with error when add mock server into tests
logger.info('Inspector failed to connect to code server.', e)
return []

def choose_issue_type(self, problem: model_pb2.Problem) -> IssueType:
if problem.inspector in self.ij_message_to_issue_type:
for key, value in self.ij_message_to_issue_type[problem.inspector].items():
if problem.name in key:
return value

if problem.inspector in self.ij_inspection_to_issue_type:
return self.ij_inspection_to_issue_type[problem.inspector]

# PEP-8 inspection
return IssueType.CODE_STYLE
12 changes: 6 additions & 6 deletions hyperstyle/src/python/review/inspectors/ij_kotlin/ij_kotlin.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from hyperstyle.src.python.review.inspectors.common.inspector.base_inspector import BaseIJInspector
from hyperstyle.src.python.review.inspectors.common.inspector.inspector_type import InspectorType
from hyperstyle.src.python.review.inspectors.common.inspector.proto import model_pb2
from hyperstyle.src.python.review.inspectors.common.issue.issue import IssueType
from hyperstyle.src.python.review.inspectors.ij_kotlin.issue_configs import ISSUE_CONFIGS
from hyperstyle.src.python.review.inspectors.ij_kotlin.issue_types import (
IJ_MESSAGE_TO_ISSUE_TYPE,
IJ_INSPECTION_TO_ISSUE_TYPE,
)


class KotlinIJInspector(BaseIJInspector):
inspector_type = InspectorType.IJ_KOTLIN
language_id = model_pb2.LanguageId.kotlin
issue_configs = ISSUE_CONFIGS

@staticmethod
def choose_issue_type(problem: model_pb2.Problem) -> IssueType:
# TODO: add categorization
return IssueType.BEST_PRACTICES
ij_inspection_to_issue_type = IJ_INSPECTION_TO_ISSUE_TYPE
ij_message_to_issue_type = IJ_MESSAGE_TO_ISSUE_TYPE
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IJ_INSPECTION_TO_ISSUE_TYPE = {}

IJ_MESSAGE_TO_ISSUE_TYPE = {}
20 changes: 4 additions & 16 deletions hyperstyle/src/python/review/inspectors/ij_python/ij_python.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
from hyperstyle.src.python.review.inspectors.common.inspector.base_inspector import BaseIJInspector
from hyperstyle.src.python.review.inspectors.common.inspector.inspector_type import InspectorType
from hyperstyle.src.python.review.inspectors.common.inspector.proto import model_pb2
from hyperstyle.src.python.review.inspectors.common.issue.issue import IssueType
from hyperstyle.src.python.review.inspectors.ij_python.issue_configs import ISSUE_CONFIGS
from hyperstyle.src.python.review.inspectors.ij_python.issue_types import (
IJ_PYTHON_CODE_TO_ISSUE_TYPE,
ISSUE_TYPE_EXCEPTIONS,
IJ_MESSAGE_TO_ISSUE_TYPE,
IJ_INSPECTION_TO_ISSUE_TYPE,
)


class PythonIJInspector(BaseIJInspector):
inspector_type = InspectorType.IJ_PYTHON
language_id = model_pb2.LanguageId.Python
issue_configs = ISSUE_CONFIGS

@staticmethod
def choose_issue_type(problem: model_pb2.Problem) -> IssueType:
if problem.inspector in ISSUE_TYPE_EXCEPTIONS:
for key, value in ISSUE_TYPE_EXCEPTIONS[problem.inspector].items():
if problem.name in key:
return value

if problem.inspector in IJ_PYTHON_CODE_TO_ISSUE_TYPE:
return IJ_PYTHON_CODE_TO_ISSUE_TYPE[problem.inspector]

# PEP-8 inspection
return IssueType.CODE_STYLE
ij_inspection_to_issue_type = IJ_INSPECTION_TO_ISSUE_TYPE
ij_message_to_issue_type = IJ_MESSAGE_TO_ISSUE_TYPE
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from hyperstyle.src.python.review.inspectors.common.issue.issue import IssueType

# Synchronized with https://github.com/JetBrains-Research/code-quality-ij-server/tree/master/docs/inspections/python
IJ_PYTHON_CODE_TO_ISSUE_TYPE: Dict[str, IssueType] = {
IJ_INSPECTION_TO_ISSUE_TYPE = {
# BEST_PRACTICES
'PyUnusedLocalInspection': IssueType.BEST_PRACTICES,
'PySimplifyBooleanCheckInspection': IssueType.BEST_PRACTICES,
Expand Down Expand Up @@ -65,7 +65,7 @@
'PyUnresolvedReferencesInspection': IssueType.ERROR_PRONE,
}

ISSUE_TYPE_EXCEPTIONS = {
IJ_MESSAGE_TO_ISSUE_TYPE = {
'PyDataclassInspection': {
'is useless until ''__post_init__'' is declared': IssueType.BEST_PRACTICES,
'should take all init-only variables (incl. inherited) in the same order as they are defined':
Expand Down

0 comments on commit b7f24a0

Please sign in to comment.