Skip to content

Commit

Permalink
Add Java IntelliJ Inspector
Browse files Browse the repository at this point in the history
Introduce Java IJ inspector with necessary configurations and update the common reviewer logic to include it. Bump version to 1.6.0 and handle missing connection parameters with an exception instead of a warning.
  • Loading branch information
meanmail committed Sep 23, 2024
1 parent c069feb commit ec023ee
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class InspectorType(Enum):
# Java language
PMD = "PMD"
CHECKSTYLE = "CHECKSTYLE"
IJ_JAVA = "IJ_JAVA"

# Kotlin language
DETEKT = "DETEKT"
Expand Down Expand Up @@ -43,6 +44,7 @@ def available_values(cls) -> list[str]:
# Java language
cls.PMD.value,
cls.CHECKSTYLE.value,
cls.IJ_JAVA.value,
# Kotlin language
cls.DETEKT.value,
cls.IJ_KOTLIN.value,
Expand Down
Empty file.
18 changes: 18 additions & 0 deletions hyperstyle/src/python/review/inspectors/ij_java/ij_python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import annotations

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.ij_java.issue_configs import ISSUE_CONFIGS
from hyperstyle.src.python.review.inspectors.ij_java.issue_types import (
IJ_INSPECTION_TO_ISSUE_TYPE,
IJ_MESSAGE_TO_ISSUE_TYPE,
)


class JavaIJInspector(BaseIJInspector):
inspector_type = InspectorType.IJ_JAVA
language_id = model_pb2.LanguageId.Java
issue_configs = ISSUE_CONFIGS
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 @@
from __future__ import annotations

ISSUE_CONFIGS = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import annotations

IJ_INSPECTION_TO_ISSUE_TYPE = {}

IJ_MESSAGE_TO_ISSUE_TYPE = {}
18 changes: 7 additions & 11 deletions hyperstyle/src/python/review/reviewers/common.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import json
import logging
from collections import defaultdict
from typing import TYPE_CHECKING

Expand All @@ -17,6 +16,7 @@
from hyperstyle.src.python.review.inspectors.eslint.eslint import ESLintInspector
from hyperstyle.src.python.review.inspectors.flake8.flake8 import Flake8Inspector
from hyperstyle.src.python.review.inspectors.golang_lint.golang_lint import GolangLintInspector
from hyperstyle.src.python.review.inspectors.ij_java.ij_python import JavaIJInspector
from hyperstyle.src.python.review.inspectors.ij_kotlin.ij_kotlin import KotlinIJInspector
from hyperstyle.src.python.review.inspectors.ij_python.ij_python import PythonIJInspector
from hyperstyle.src.python.review.inspectors.pmd.pmd import PMDInspector
Expand Down Expand Up @@ -55,6 +55,7 @@
Language.JAVA: [
CheckstyleInspector(),
PMDInspector(),
JavaIJInspector(),
],
Language.KOTLIN: [
DetektInspector(),
Expand Down Expand Up @@ -85,18 +86,13 @@ def _inspect_code(
None if config.ij_config is None else json.loads(config.ij_config).get(language.value.lower())
)
if ij_inspectors and connection_parameters is None:
logging.warning(
f"IJ inspectors for the {language.value} will be disabled "
f"as the IJ config for this language was not specified.",
msg = f"Connection parameters for {language.value} inspectors are not provided"
raise ValueError(msg)
for inspector in ij_inspectors:
inspector.setup_connection_parameters(
connection_parameters["host"], connection_parameters["port"]
)

config.disabled_inspectors.update(inspector.inspector_type for inspector in ij_inspectors)
else:
for inspector in ij_inspectors:
inspector.setup_connection_parameters(
connection_parameters["host"], connection_parameters["port"]
)

if isinstance(metadata, InMemoryMetadata):
return inspect_in_parallel(run_inspector_in_memory, metadata.code, config, inspectors)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hyperstyle"
version = "1.5.0"
version = "1.6.0"
description = "A tool for running a set of pre-configured linters and evaluating code quality."
authors = ["Hyperskill Team"]
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions test/python/functional_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def build(self) -> list[str]:
# TODO: remove after adding a test server
self.disable.append(InspectorType.IJ_PYTHON.value)
self.disable.append(InspectorType.IJ_KOTLIN.value)
self.disable.append(InspectorType.IJ_JAVA.value)

if self.disable:
command.extend([RunToolArgument.DISABLE.value.long_name, ",".join(self.disable)])
Expand Down

0 comments on commit ec023ee

Please sign in to comment.