Skip to content

Commit

Permalink
Develop (#191)
Browse files Browse the repository at this point in the history
* PMD update (#161)

* Add LanguageVersion.JAVA_17

* Add B007's custom tip

* Add W1404 and R1721' custom tips

* Add new words

* Add some inspections in ignore

* Sort whitelists (Github Actions)

* Add WPS442

* Remove W0621

* Add java17

* Update PMD to 6.47.0

* Add java17

* Update PMD to 6.47.0

* Update PMD to 6.47.0

* Remove unnecessary whitespaces

* Add test for Java 17

* Bump version 1.2.7 -> 1.2.8

* Add trailing new line

* Try to update docker image

* Bump version 1.2.8 -> 1.3.0

Co-authored-by: GirZ0n <GirZ0n@users.noreply.github.com>
Co-authored-by: Anastasiia.Birillo <nbirillo@mail.ru>

* Inspectors architecture refactoring (#162)

* Add LanguageVersion.JAVA_17

* Add B007's custom tip

* Add W1404 and R1721' custom tips

* Add new words

* Add some inspections in ignore

* Sort whitelists (Github Actions)

* Add WPS442

* Remove W0621

* Add flake8 data folder

* Add is_fstring function

* Add `get_measure_name_by_measurable_issue_type` function

* Add metric codes

* Refactor some strings into format strings

* Add new words

* Fix flake8 issues

* Add IssueConfig, IssueDescriptionParser and IssueConfigsHandler

* Refactor flake8 using new IssueConfigsHandler class

* Add issue configs tests

* Sort whitelists (Github Actions)

* Typo fix

* Typo fix

* Typo fix

* Remove unnecessary tests and add some more ones

* Add one more test

* Rename test data

* Remove unnecessary tests and add some more

* Move augmented assign pattern tip to `tips.py`

* Remove unnecessary dicts

* Require the `new_description` field

* Fix tests

* Accept only a dictionary in IssueDescriptionParser

* Fix tests

* Add new tests

* Add new tests

* Fix problems with escaped characters

* Move some common files into common folder

* Add new pylint's tests

* Refactor pylint

* Fix imports

* Fix imports

* Move common code into a new function

* Refactor pmd

* Refactor checkstyle and add new tests

* Update tips

* Refactor xml parser

* Fix tests

* Fix description

* Remove unused impoty

* Change default argument for get_magic_number_tip

* Refactor detekt

* Fix import style

* Add new tests for pylint

* Refactor eslint

* Add new tests for eslint

* Bump version 1.3.0 -> 1.3.1

* Update todo

* Fix comment

* Fix import

* Change the order of checks in __post_init__ and fix typos

* Add new tests

* Remove unnecessary typing

* Fix import style

* Try to update docker image

Co-authored-by: GirZ0n <GirZ0n@users.noreply.github.com>
Co-authored-by: Anastasiia.Birillo <nbirillo@mail.ru>

* Golang support (#154)

* Add Golang config

* Add Go language

* Add new words

* Add Go language

* Add golangci-lint inspector

* Add golang and golangci-lint

* Sort whitelists (Github Actions)

* Add new words

* Add metric linter names

* Sort whitelists (Github Actions)

* Add lightbulb

* Sort whitelists (Github Actions)

* Sort whitelists (Github Actions)

* Fix #151: disable AbstractClassWithoutAbstractMethod.

* Undo 6c8d506

* Add get_extension_from_file

* Fix the bug that caused the tool to fail

* Add test

* Fix code style

* Script for setting up the environment (#155)

* Add a script for setting up the environment

* Fix typo

* Update README

* Update README

* Fix PR issues

* Fix extensions

* Update VERSION.md

* Add WIP config

* Fix golangci-lint's download command

* Add golangci-lint download

* Add working directory argument

* Add ability to analyze folders

* Fix extension

* Fix typo

* Fix extension

* Update golangci-lint to 1.47.1

* Fix generics

* Fix incorrect opening of Go projects without go.mod files

* Add concurrency flag

* Add issue types

* Fix typo

* Add noqa flag

* Fix #156 (#157)

* Add get_extension_from_file

* Fix the bug that caused the tool to fail

* Add test

* Fix code style

* Fix extensions

* Update VERSION.md

* Add logging

* Move go installation into Dockerfile.base

* Add --allow-parallel-runners flag

* Fix curl flags

* Fix typo

* Fix configs

* Move is_result_file_correct to common utils

* Rename GolangLint -> GolangLintInspector

* Small fixes:
1. Rename GolangLint -> GolangLintInspector;
2. Add a check for an invalid output file
3. Fix description regexp
4. Fix description style
5. Fix comment

* Add some golang tests

* Add a trailing new line

* Fix typo

* Remove gocognit

* Add go data folder

* Add tests

* Fix typo

* Add `n_line_len` and `n_info`

* Add some more tests

* Rename a variable

* Fix flake8 issue

* Add some more tests

* Bump version to 1.4.0

* Added a new test case

* Remove an unnecessary field

* Remove an unnecessary field and replace `deadcode` with `unused`

* Bump `golangci-lint` version: 1.47.1 -> 1.49.0

* Remove deprecated linters

* Fix tests

* Add new linter

* Fix config

* Fix import and measure's descriptions

* Fix import

* Move `is_result_file_correct` function to `utils.py`

* Move inspector to a new architecture

* Add new tests

* Add issue configs

* Fix config

* Fix config

* Fix typo

* Add installation of third party golang libraries

* Add _is_metalinter_issue

* Remove blank line

* Try to update docker image

* Change container

Co-authored-by: GirZ0n <GirZ0n@users.noreply.github.com>
Co-authored-by: Anastasiia.Birillo <nbirillo@mail.ru>

* Contribution guideline (#166)

* Create CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Update CONTRIBUTING.md

* Fix link

* Update CONTRIBUTING.md

* Update go config

* Run inspectors on code without files (#169)

* Try to add in memory api

* Fix requirements conflicts

* Fix flake8

* Add inspect_in_memory fo inspectors

* Try to support in memory inspectors

* Fix styles

* Fix styles and add more helpers

* Try to adapt flake8 and run_in_subprocess function

* Try to fix teamcity tests

* Fix flake

* Try to fix teamcity

* Try to fix teamcity

* Fix tests

* added inspect_in_memory for pyling inspector (#168)

* added inspect_in_memory for pyling inspector

* fix formatting

* Fix tests

Co-authored-by: Anastasiia.Birillo <nbirillo@mail.ru>

* Update version

Co-authored-by: Sergey Titov <72385325+TitovSergey@users.noreply.github.com>

* ML-149: IJ inspector based on code server (#171)

* Add simple ij inspector

* Move code server params to env variables and update Dockerfile

* Fix flake8

* Fix flake8

* Fix flake8

* Fix flake8

* Sort whitelists (Github Actions)

* Try to fix tests

* Fix code style

* Wrap server connection with try/catch

* Remove test main

* Fix tests

* Edit README.md

* Fix review comments

Co-authored-by: tiginamaria <tiginamaria@users.noreply.github.com>
Co-authored-by: Anastasiia.Birillo <nbirillo@mail.ru>

* Add timeout to request (#172)

* Fix go linter and fix an error in README (#174)

* Disable whitespace inspection for Go and fix a small error in README

* Fix tests

* Update version

* Add issues types for ij python inspections

* Fix flake8

* IJ-Hyperstyle Adaptation (#180)

* Fix ij-inspector (#182)

* Fix ij-inspector

* Fix issues

* Fix styles

* fix: remove an unnecessary quote

* Links fix (#183)

* fix: fix WPS link

* fix: fix golangci-lint link

* fix: fix golangci-lint link

* fix: fix PMD link

* fix: fix Detekt link

* fix: fix checkstyle link

* Kotlin IJ Inspector (#186)

* fix: update .gitignore to exclude unnecessary files

* feat: add IJ Kotlin inspector
feat: add the `ij-config` argument
feat: add BaseIJInspector
refactor: move several inspector-related files to the common folder

* fix: update flake8 run command

* docs: refined the `--ij-config` argument description

* fix: update test configuration to disable IJ_PYTHON and IJ_KOTLIN

* fix: add the `ij_config` argument to test command builder

* fix: fix tests

* fix: add IJ_KOTLIN to an inspector types list

* style: fix flake8's issues

* refactor: rename variable for clarity in common.py

* style: fix flake8's issue

* docs: rearrange wording for consistent format in README

* fix: fix PR issues

* style: fix flake8's issues

* fix: bump the version number

* Refactor build system (#187)

* fix: update .gitignore to exclude unnecessary files

* feat: add IJ Kotlin inspector
feat: add the `ij-config` argument
feat: add BaseIJInspector
refactor: move several inspector-related files to the common folder

* fix: update flake8 run command

* docs: refined the `--ij-config` argument description

* fix: update test configuration to disable IJ_PYTHON and IJ_KOTLIN

* fix: add the `ij_config` argument to test command builder

* fix: fix tests

* fix: add IJ_KOTLIN to an inspector types list

* style: fix flake8's issues

* refactor: rename variable for clarity in common.py

* style: fix flake8's issue

* docs: rearrange wording for consistent format in README

* refactor: refactor build system

* fix: try to fix workflows

* fix: try to fix workflows

* style: fix flake8's issue

* fix: remove MANIFEST.in

* fix: update project license type and remove unneeded sections

* feat: update setup.py for generating proto files

* fix: add protobuf compilation step to build workflow

* bump: bump the tool version

* fix: update a proto path in build workflow

* fix: add proto generation to Dockerfile

* fix: fix incorrect ENV syntax in Dockerfile

* fix: update PROTO_PATH in Dockerfile

* refactor: refactor dependencies structure

* fixL fix a comment

* refactor: refactor Dockerfile, optimizing sequence of commands

* feat: add new directories to .dockerignore

* fix: return dependencies installation

* fix: specify versions for setuptools and setuptools-scm

* style: remove unnecessary cd

* fix: remove redundant dependencies

* fix: removed unnecessary step

* fix: fix the GitHub workflow

* fix: update project author in pyproject.toml

* docs: update README.md installation instructions

* fix: update the build system requires and exclude unnecessary files

* fix: fix a small bug where the inspector type for `BaseIJInspector` was always `IJ_PYTHON` (#188)

* Refactoring (#190)

* Switch to Poetry for dependency management

Replaced `requirements` files and `setup.py` with `pyproject.toml` for Poetry. Updated Dockerfile to use Poetry for project build and dependency installation, and added a new GitHub Actions workflow for sorting whitelists.

* Switch workflows to self-hosted runners

Updated the `.github/workflows/sort_whitespaces.yml`, `.github/workflows/publish.yml`, and `.github/workflows/build.yml` files to use self-hosted runners with a small configuration. This change aims to leverage available self-hosted resources for running GitHub Actions.

* Upgrade grpcio-tools and protobuf versions

Upgraded grpcio-tools from 1.51.1 to 1.66.1 and protobuf from 4.25.4 to 5.28.1 in pyproject.toml and poetry.lock to the latest versions. Updated Dockerfile to adjust paths and improve build context. These changes improve compatibility and maintain security standards.

* Update Python version to 3.10.14

Switching from Python 3.8.11 to 3.10.14 for improved features and performance enhancements. Ensure compatibility with the newer version in your development environment.

* Update wps-light to version 0.15.3

This commit upgrades the wps-light dependency from version 0.15.2 to 0.15.3 in the pyproject.toml file. This ensures the project benefits from the latest fixes and improvements provided in the newer version.

* Use sys.executable and refactor Dockerfile for venv

Switched to using sys.executable in multiple files for better flexibility with the Python interpreter. Updated the Dockerfile to create and use a virtual environment, and adjusted related workflow scripts to use the virtual environment's executables. Added a new GitHub Actions workflow for building the Docker image after a release.

---------

Co-authored-by: meanmail <meanmail@meanmail.dev>

* Remove VERSION.md file

The VERSION.md file has been deleted to streamline project maintenance. Version tracking will now rely on internal systems rather than a separate file.

* Update string prefix removal method

Replaced the custom `remove_prefix` function with Python's built-in `removeprefix` method for better readability and efficiency. This change modernizes the code and leverages Python's built-in capabilities.

* Remove default disabled inspectors

Removed the default 'ij_python' inspector from the disabled set in the `run_tool.py` file. This change prepares the code for production by ensuring no inspectors are disabled by default.

* Revert version to 1.5.0 in pyproject.toml

Reverting the version number from 1.5.1 back to 1.5.0. This change rectifies an unintended version increment in the previous update.

* Remove unused import in pmd.py

Remove the `remove_prefix` import from `pmd.py` which is not being used in the code. This helps to clean up the code and avoid unnecessary imports.

---------

Co-authored-by: Ilya Vlasov <55441714+GirZ0n@users.noreply.github.com>
Co-authored-by: GirZ0n <GirZ0n@users.noreply.github.com>
Co-authored-by: Anastasiia.Birillo <nbirillo@mail.ru>
Co-authored-by: GirZ0n <ilyavlasov2011@gmail.com>
Co-authored-by: Sergey Titov <72385325+TitovSergey@users.noreply.github.com>
Co-authored-by: Maria Tigina <31625351+tiginamaria@users.noreply.github.com>
Co-authored-by: tiginamaria <tiginamaria@users.noreply.github.com>
Co-authored-by: anastasia.birillo <anastasia.i.birillo@gmail.com>
Co-authored-by: Ilya Vlasov <ilya.vlasov@jetbrains.com>
Co-authored-by: meanmail <meanmail@meanmail.dev>
  • Loading branch information
11 people authored Sep 19, 2024
1 parent 7c9fbc1 commit 4ef6aef
Show file tree
Hide file tree
Showing 115 changed files with 2,413 additions and 501 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
.github
.idea
node_modules
venv
.venv
build
**/*.egg-info
**/model_pb2*
linters
124 changes: 71 additions & 53 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,97 @@
name: Python build

on: [ push, pull_request ]
on:
push:
branches:
- main
- develop
pull_request:

jobs:

build:
runs-on: ubuntu-latest
# Consistent with base image in Dockerfile
# container: stepik/hyperstyle-base:py3.8.11-java11.0.11-node14.17.3-go1.18.5
container: nastyabirillo/hyperstyle:1.4.4
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_image:
name: Build Image
runs-on: [ self-hosted, small ]
steps:
- name: Install git
run: |
apt-get update
apt-get -y install git
- uses: actions/checkout@v4

- name: Check env variables
run: |
echo $DETEKT_DIRECTORY && echo $DETEKT_VERSION
echo $CHECKSTYLE_DIRECTORY && echo CHECKSTYLE_VERSION
echo $PMD_DIRECTORY && echo PMD_VERSION
- uses: docker/login-action@v3
with:
registry: hyperskill.azurecr.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- name: Checkout
uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v3

- name: Install requirements
- name: Build and push server image
uses: docker/build-push-action@v6
with:
context: .
pull: true
push: true
tags: hyperskill.azurecr.io/hyperstyle:${{ github.sha }}
cache-from: |
type=gha
type=gha,scope=main
cache-to: type=gha,mode=max

tests:
name: Tests
needs:
- build_image
runs-on: [ self-hosted, small ]
container:
image: hyperskill.azurecr.io/hyperstyle:${{ github.sha }}
credentials:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
steps:
- name: Run tests
run: |
pip install --no-cache-dir -r requirements-test.txt -r requirements.txt
cd /review
/hyperstyle/bin/pytest
- name: Set up git rights
build:
runs-on: [ self-hosted, small ]
needs:
- build_image
container:
image: hyperskill.azurecr.io/hyperstyle:${{ github.sha }}
credentials:
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
steps:
- name: Check env variables
run: |
git config --global --add safe.directory '*'
echo $DETEKT_DIRECTORY && echo $DETEKT_VERSION
echo $CHECKSTYLE_DIRECTORY && echo $CHECKSTYLE_VERSION
echo $PMD_DIRECTORY && echo $PMD_VERSION
echo $GOLANG_LINT_DIRECTORY && echo $GOLANG_LINT_VERSION
- name: Lint with flake8
run: |
cd /review
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules
/hyperstyle/bin/flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules,hyperstyle/src/python/review/inspectors/common/inspector/proto
# TODO: change max-complexity into 10 after refactoring
# TODO: remove R504, A003, E800, E402, WPS1, WPS2, WPS3, WPS4, WPS5, WPS6, H601
flake8 . --count --max-complexity=11 --max-line-length=120 --max-doc-length=120 --ignore=R504,A003,E800,E402,W503,WPS,H601,N400 --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules
- name: Sort whitelists
run: |
for file in "whitelist.txt" "hyperstyle/src/python/review/inspectors/flake8/whitelist.txt"
do
LC_ALL=C sort $file -o $file
done
- name: Commit sorted whitelists
uses: EndBug/add-and-commit@v7.2.1
with:
add: "['whitelist.txt', 'hyperstyle/src/python/review/inspectors/flake8/whitelist.txt']"
message: 'Sort whitelists (Github Actions)'

- name: Set up Eslint
run: |
# Consistent with eslint version in Dockerfile
npm install eslint@7.5.0 -g && eslint --init
- name: Test with pytest
run: |
pytest -vv
- name: Install review module
run: |
pip install .
/hyperstyle/bin/flake8 . --count --max-complexity=11 --max-line-length=120 --max-doc-length=120 --ignore=R504,A003,E800,E402,W503,WPS,H601,N400,I100,I201,I202, --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules,hyperstyle/src/python/review/inspectors/common/inspector/proto
- name: Check installed module can run python linters
run: |
review setup.py
cd /review
/hyperstyle/bin/python -m hyperstyle.src.python.review.run_tool test/resources/inspectors/python/case39_no_issues.py
- name: Check installed module can run java linters
run: |
review test/resources/inspectors/java/test_algorithm_with_scanner.java
cd /review
/hyperstyle/bin/python -m hyperstyle.src.python.review.run_tool test/resources/inspectors/java/test_algorithm_with_scanner.java
- name: Check installed module can run js linters
run: |
review test/resources/inspectors/js/case0_no_issues.js
cd /review
/hyperstyle/bin/python -m hyperstyle.src.python.review.run_tool test/resources/inspectors/js/case0_no_issues.js
2 changes: 1 addition & 1 deletion .github/workflows/build_base_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
type: string
description: 'Image tag'
required: true
default: 'py3.12.5-java11.0.11-node14.17.3-go1.18.5'
default: 'py3.10.14-java11.0.11-node14.17.3-go1.18.5'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build Image after Release

on:
workflow_dispatch:
inputs:
image_tag:
description: 'Image tag'
required: true
default: 'latest'
release:
types:
- released

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
build_image:
name: Build Image
runs-on: [ self-hosted, small ]
steps:
- uses: actions/checkout@v4

- uses: docker/login-action@v3
with:
registry: hyperskill.azurecr.io
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}

- uses: docker/setup-buildx-action@v3

- name: Build and push server image
uses: docker/build-push-action@v6
with:
context: .
pull: true
push: true
tags: hyperskill.azurecr.io/hyperstyle:${{ inputs.image_tag || github.event.release.tag_name }}
cache-from: |
type=gha
type=gha,scope=main
cache-to: type=gha,mode=max
16 changes: 10 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# Publish to PyPI in case of releasing
name: Publish to PyPI in case of releasing

on:
push:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
runs-on: [ self-hosted, small ]

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version-file: .python-version
- name: Install pypa/build
run: |
python -m pip install build --user
Expand All @@ -24,4 +28,4 @@ jobs:
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.SECRETS_TEST_PYPI_API_TOKEN }}
password: ${{ secrets.SECRETS_TEST_PYPI_API_TOKEN }}
39 changes: 39 additions & 0 deletions .github/workflows/sort_whitespaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Sort whitespaces

on:
push:
branches:
- main
- develop
paths:
- 'whitelist.txt'
- 'hyperstyle/src/python/review/inspectors/flake8/whitelist.txt'
pull_request:
paths:
- 'whitelist.txt'
- 'hyperstyle/src/python/review/inspectors/flake8/whitelist.txt'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
sort_whitespaces:
name: Sort whitespaces
runs-on: [ self-hosted, small ]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Sort whitelists
run: |
for file in "whitelist.txt" "hyperstyle/src/python/review/inspectors/flake8/whitelist.txt"
do
LC_ALL=C sort $file -o $file
done
- name: Commit sorted whitelists
uses: EndBug/add-and-commit@v7.2.1
with:
add: "['whitelist.txt', 'hyperstyle/src/python/review/inspectors/flake8/whitelist.txt']"
message: 'Sort whitelists (Github Actions)'
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,11 @@ __pycache__/
/.intellij_inspector/out/

lightweight.Dockerfile
linters

node_modules
.eslintrc.js
package-lock.json

hyperstyle/src/python/review/inspectors/common/inspector/proto/model_pb2*
.env
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.14
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ In this document you will find a detailed description of how to add new function
## Adding a new inspector for an existing language

If you want to add a new inspector for an existing language, you need to:
1. Inherit from the [`BaseInspector`](hyperstyle/src/python/review/inspectors/base_inspector.py#L9) class.
2. Define the [`inspector_type`](hyperstyle/src/python/review/inspectors/base_inspector.py#L29) property. To do this, you need to update the [`InspectorType`](hyperstyle/src/python/review/inspectors/inspector_type.py#L6) class by adding there a name of the inspector.
3. Implement the [`inspect`](hyperstyle/src/python/review/inspectors/base_inspector.py#L33) function, which should run an analysis of the language and return a list of found issues;
1. Inherit from the [`BaseInspector`](hyperstyle/src/python/review/inspectors/common/inspector/base_inspector.py#L9) class.
2. Define the [`inspector_type`](hyperstyle/src/python/review/inspectors/common/inspector/base_inspector.py#L29) property. To do this, you need to update the [`InspectorType`](hyperstyle/src/python/review/inspectors/common/inspector/inspector_type.py#L6) class by adding there a name of the inspector.
3. Implement the [`inspect`](hyperstyle/src/python/review/inspectors/common/inspector/base_inspector.py#L33) function, which should run an analysis of the language and return a list of found issues;

Usually the inspector runs a third-party linter through a command line and parses its result. In this case it will be useful to implement several auxiliary functions:
1. `create_command` – creates a command to run the linter via subprocess.
Expand All @@ -31,9 +31,9 @@ If you are implementing the inspector that uses the third-party linter, you must

### Implementation of the `parse` function

Usually, the `parse` function parses the result of the third-party linter line-by-line, then creates a base issue using the [`BaseIssue`](hyperstyle/src/python/review/inspectors/issue.py#L199) dataclass, which is later converted to either [`CodeIssue`](hyperstyle/src/python/review/inspectors/issue.py#L217) or one of the measurable issues using the [`convert_base_issue`](hyperstyle/src/python/review/inspectors/common/base_issue_converter.py#L17) function and an instance of the [`IssueConigsHandler`](hyperstyle/src/python/review/inspectors/issue_configs.py#L117) class. The resulting issue is added to the general list of found issues and this list is returned from the function after the parsing is finished.
Usually, the `parse` function parses the result of the third-party linter line-by-line, then creates a base issue using the [`BaseIssue`](hyperstyle/src/python/review/inspectors/common/issue/issue.py#L199) dataclass, which is later converted to either [`CodeIssue`](hyperstyle/src/python/review/inspectors/common/issue/issue.py#L217) or one of the measurable issues using the [`convert_base_issue`](hyperstyle/src/python/review/inspectors/common/issue/base_issue_converter.py#L17) function and an instance of the [`IssueConigsHandler`](hyperstyle/src/python/review/inspectors/common/issue/issue_configs.py#L117) class. The resulting issue is added to the general list of found issues and this list is returned from the function after the parsing is finished.

The `IssueConfigHandler` class handles custom issue descriptions and also parses metrics from their descriptions (examples of metrics are: line or function length, cyclomatic complexity, maintainability index). It receives instances of [`IssueConfig`](hyperstyle/src/python/review/inspectors/issue_configs.py#L46) or [`MeasurableIssueConfig`](hyperstyle/src/python/review/inspectors/issue_configs.py#L85) classes as input, which should be stored in the `ISSUE_CONFIGS` list next to the inspector.
The `IssueConfigHandler` class handles custom issue descriptions and also parses metrics from their descriptions (examples of metrics are: line or function length, cyclomatic complexity, maintainability index). It receives instances of [`IssueConfig`](hyperstyle/src/python/review/inspectors/common/issue/issue_configs.py#L46) or [`MeasurableIssueConfig`](hyperstyle/src/python/review/inspectors/common/issue/issue_configs.py#L85) classes as input, which should be stored in the `ISSUE_CONFIGS` list next to the inspector.

Also, if the third-party linter supports output in "Checkstyle" format, you can use the [`parse_xml_file_result`](hyperstyle/src/python/review/inspectors/common/xml_parser.py#L47) function to parse the output file.

Expand All @@ -42,7 +42,7 @@ Also, if the third-party linter supports output in "Checkstyle" format, you can
A sample checklist for adding a new inspector looks like this:
- [ ] I've inherited from the `BaseInspector` class.
- [ ] I've implemented the `inspect` function and _if needed_ I've added a check for the existence of third-party linter environment variables using the [`check_set_up_env_variable`](hyperstyle/src/python/review/common/file_system.py#L124) function.
- [ ] I've added a new inspector type to the `InspectorType` class, updated the [`available_values`](hyperstyle/src/python/review/inspectors/inspector_type.py#L27) function and defined the inspector type.
- [ ] I've added a new inspector type to the `InspectorType` class, updated the [`available_values`](hyperstyle/src/python/review/inspectors/common/inspector/inspector_type.py#L27) function and defined the inspector type.
- [ ] _If needed_. I've added a config to run the third-party linter.
- [ ] _If needed_. I've implemented the `create_command` function.
- [ ] _if needed_. I've implemented the `parse` function and defined the `ISSUES_CONFIGS` list in a separate file.
Expand Down
Loading

0 comments on commit 4ef6aef

Please sign in to comment.