Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requirements upgrade #21

Merged
merged 59 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
41eddcd
Added param and params to whitelist
GirZ0n Mar 14, 2021
d176f77
Fixed flake8-spellcheck issue
GirZ0n Mar 14, 2021
1f77c30
Added new test
GirZ0n Mar 16, 2021
79f229b
Added wps-light support
GirZ0n Mar 21, 2021
3e00358
Fixed tests
GirZ0n Mar 21, 2021
fc32b5f
Merge branch 'develop' into wps-light-support
GirZ0n Mar 21, 2021
c295334
Update build.yml
GirZ0n Mar 21, 2021
5c9c329
Small test fix
GirZ0n Mar 21, 2021
542068e
Small code refactoring:
GirZ0n Mar 22, 2021
aa3a6e7
Added support for flake8-broken-line
GirZ0n Mar 23, 2021
f8c2a87
Code refactoring
GirZ0n Mar 23, 2021
48ef2af
Added support for flake8-string-format
GirZ0n Mar 26, 2021
d142938
Added tests for flake8-string-format
GirZ0n Mar 26, 2021
cff0776
Added support for flake8-commas
GirZ0n Mar 27, 2021
a5a6c82
Added tests for flake8-commas
GirZ0n Mar 27, 2021
0c88f53
Added multiline
GirZ0n Mar 27, 2021
323f748
Added C812 to ignore
GirZ0n Mar 27, 2021
4287cf0
Added support for cohesion
GirZ0n Mar 29, 2021
afaf0dd
Fixed tests
GirZ0n Mar 29, 2021
4b2930c
Merge remote-tracking branch 'origin/new-flake8-plugins' into new-fla…
GirZ0n Mar 29, 2021
7b79c6b
Added H601 (cohesion) to ignore
GirZ0n Mar 29, 2021
0d2a9cb
Added test for cohesion
GirZ0n Mar 30, 2021
923c18a
Added sqrt
GirZ0n Mar 30, 2021
43d5193
Added Radon inspector and maintainability index metric
GirZ0n Apr 3, 2021
47cb02e
Added tests for Radon inspector and maintainability metric
GirZ0n Apr 3, 2021
a034652
Fix trailing commas
GirZ0n Apr 4, 2021
f2d3377
Remove Halstead complexity placeholders
GirZ0n Apr 6, 2021
5a7378f
Add comments
GirZ0n Apr 6, 2021
72075ce
Merge branch 'develop' into radon-support
GirZ0n Apr 6, 2021
ffd212e
Fixed F401
GirZ0n Apr 6, 2021
528599a
Small import refactoring
GirZ0n Apr 6, 2021
9556546
Fixed W293
GirZ0n Apr 6, 2021
ef6fdb9
Added W503
GirZ0n Apr 6, 2021
e7f282b
Merge branch 'radon-support' into trailing-commas-fix
GirZ0n Apr 6, 2021
54c22f2
Remove C812
GirZ0n Apr 6, 2021
ffbcf4c
Trailing commas fix (#20)
GirZ0n Apr 8, 2021
33bb0c1
Fixed test due to flake8-comprehensions update
GirZ0n Apr 10, 2021
d0856dd
Fixed test due to flake8-comprehensions update
GirZ0n Apr 10, 2021
f5db776
Added changelog
GirZ0n Apr 10, 2021
51bd0a7
Fixed test due to pylint update
GirZ0n Apr 10, 2021
dc73b38
Fixed the test since pylint no longer checks for spaces
GirZ0n Apr 10, 2021
81356dc
Added convert_percentage_of_value_to_lack_of_value
GirZ0n Apr 10, 2021
06553f3
Replaced __get_cohesion_lack with convert_percentage_of_value_to_lack…
GirZ0n Apr 10, 2021
ac4349b
typo fix
GirZ0n Apr 10, 2021
a442f84
Small code refactoring:
GirZ0n Apr 10, 2021
6367493
Removed unused import
GirZ0n Apr 10, 2021
805a492
Small code refactoring:
GirZ0n Apr 10, 2021
ad6df78
Updated versions of dependencies
GirZ0n Apr 10, 2021
62600e3
Added maintainability index tip
GirZ0n Apr 10, 2021
bacb25f
Fixed test
GirZ0n Apr 10, 2021
5fe2640
Added django dictionary support
GirZ0n Apr 10, 2021
302dd8c
Merge branch 'radon-support' into requirements_upgrade
GirZ0n Apr 10, 2021
847c98e
Fixed C408
GirZ0n Apr 10, 2021
59bde6f
Merge remote-tracking branch 'origin/requirements_upgrade' into requi…
GirZ0n Apr 10, 2021
03ffc91
flake8-import-order issues fix (#22)
GirZ0n Apr 12, 2021
1ce5f22
Merge branch 'develop' into requirements_upgrade
GirZ0n Apr 13, 2021
342e46a
Remove extra import
GirZ0n Apr 13, 2021
737dfe2
Remove extra import
GirZ0n Apr 13, 2021
fdf859c
flake8-spellcheck issues fix (#23)
GirZ0n Apr 14, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
# 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
# TODO: change max-complexity into 10 after refactoring
flake8 . --count --max-complexity=11 --max-line-length=120 --max-doc-length=120 --ignore=I201,I202,I101,I100,R504,A003,E800,SC200,SC100,E402,W503,WPS,C812,H601 --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules
flake8 . --count --max-complexity=11 --max-line-length=120 --max-doc-length=120 --ignore=R504,A003,E800,SC200,SC100,E402,W503,WPS,H601 --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules
- name: Set up Eslint
run: |
npm install eslint --save-dev
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ Python language:
- [x] Pylint [GNU LGPL v2]
* [Site and docs](https://www.pylint.org/)
* [Repository](https://github.com/PyCQA/pylint)


- [x] Radon [MIT]
* [Site and docs](https://radon.readthedocs.io/en/latest/)
* [Repository](https://github.com/rubik/radon)

Java language:

Expand Down Expand Up @@ -92,7 +95,7 @@ Argument | Description
--- | ---
**‑h**, **‑‑help** | show the help message and exit.
**‑v**, **‑‑verbosity** | choose logging level according [this](https://docs.python.org/3/library/logging.html#levels) list: `1` - **ERROR**; `2` - **INFO**; `3` - **DEBUG**; `0` - disable logging (**CRITICAL** value); default value is `0` (**CRITICAL**).
**‑d**, **‑‑disable** | disable inspectors. Available values: for **Python** language: `pylint` for [Pylint](https://github.com/PyCQA/pylint), `flake8` for [flake8](https://flake8.pycqa.org/en/latest/), `python_ast` to check different measures providing by AST; for **Java** language: `checkstyle` for the [Checkstyle](https://checkstyle.sourceforge.io/), `pmd` for [PMD](https://pmd.github.io/); for `Kotlin` language: detekt for [Detekt](https://detekt.github.io/detekt/); for **JavaScript** language: `eslint` for [ESlint](https://eslint.org/). Example: `-d pylint,flake8`.
**‑d**, **‑‑disable** | disable inspectors. Available values: for **Python** language: `pylint` for [Pylint](https://github.com/PyCQA/pylint), `flake8` for [flake8](https://flake8.pycqa.org/en/latest/), `radon` for [Radon](https://radon.readthedocs.io/en/latest/), `python_ast` to check different measures providing by AST; for **Java** language: `checkstyle` for the [Checkstyle](https://checkstyle.sourceforge.io/), `pmd` for [PMD](https://pmd.github.io/); for `Kotlin` language: detekt for [Detekt](https://detekt.github.io/detekt/); for **JavaScript** language: `eslint` for [ESlint](https://eslint.org/). Example: `-d pylint,flake8`.
**‑‑allow-duplicates** | allow duplicate issues found by different linters. By default, duplicates are skipped.
**‑‑language-version**, **‑‑language_version** | specify the language version for JAVA inspectors. Available values: `java7`, `java8`, `java9`, `java11`. **Note**: **‑‑language_version** is deprecated. Will be deleted in the future.
**‑‑n-cpu**, **‑‑n_cpu** | specify number of _cpu_ that can be used to run inspectors. **Note**: **‑‑n_cpu** is deprecated. Will be deleted in the future.
Expand Down
10 changes: 5 additions & 5 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pytest~=5.4.3
pytest~=6.2.3
pytest-runner
pytest-subtests
jsonschema==3.2.0
Django~=3.0.8
pylint~=2.5.3
requests~=2.24.0
setuptools~=47.3.1
Django~=3.2
pylint~=2.7.4
requests~=2.25.1
setuptools~=56.0.0
25 changes: 13 additions & 12 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
setuptools==47.3.1
setuptools==56.0.0

# python code analysis tools
pylint==2.5.3
pylint-django==2.0.15
flake8==3.8.3
pylint==2.7.4
pylint-django==2.3.0
flake8==3.9.0

# flake8 plugins
flake8-bugbear==20.1.4
flake8-bugbear==21.4.3
flake8-builtins==1.5.3
flake8-comprehensions==3.2.3
flake8-eradicate==0.4.0
flake8-comprehensions==3.4.0
flake8-eradicate==1.0.0
flake8-import-order==0.18.1
flake8-plugin-utils==1.3.0
flake8-plugin-utils==1.3.1
flake8-polyfill==1.0.2
flake8-return==1.1.1
flake8-spellcheck==0.14.0
flake8-return==1.1.2
flake8-spellcheck==0.24.0
mccabe==0.6.1
pep8-naming==0.11.1
wps-light==0.15.2
flake8-broken-line==0.3.0
flake8-string-format==0.3.0
flake8-commas==2.0.0
cohesion==1.0.0
radon==4.5.0

# extra libraries and frameworks
django==3.0.8
requests==2.24.0
django==3.2
requests==2.25.1
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ def get_inspectors_additional_files() -> List[str]:
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Operating System :: OS Independent'
'Operating System :: OS Independent',
],
keywords='code review',
python_requires='>=3.8, <4',
install_requires=['upsourceapi'],
packages=find_packages(exclude=[
'*.unit_tests', '*.unit_tests.*', 'unit_tests.*', 'unit_tests',
'*.functional_tests', '*.functional_tests.*', 'functional_tests.*', 'functional_tests'
'*.functional_tests', '*.functional_tests.*', 'functional_tests.*', 'functional_tests',
]),
zip_safe=False,
package_data={
'': get_inspectors_additional_files()
'': get_inspectors_additional_files(),
},
entry_points={
'console_scripts': [
'review=review.run_tool:main'
]
}
'review=review.run_tool:main',
],
},
)
2 changes: 1 addition & 1 deletion src/python/review/application_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass
from enum import Enum, unique
from typing import Optional, Set, List
from typing import List, Optional, Set

from src.python.review.inspectors.inspector_type import InspectorType

Expand Down
4 changes: 2 additions & 2 deletions src/python/review/common/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from contextlib import contextmanager
from enum import Enum, unique
from pathlib import Path
from typing import List, Union, Callable
from typing import Callable, List, Union


@unique
Expand Down Expand Up @@ -77,7 +77,7 @@ def create_directory(directory: str) -> None:
def get_file_line(path: Path, line_number: int):
return linecache.getline(
str(path),
line_number
line_number,
).strip()


Expand Down
2 changes: 1 addition & 1 deletion src/python/review/common/java_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def javac(javac_args: Union[str, Path]) -> bool:
output_bytes: bytes = subprocess.check_output(
f'javac {javac_args}',
shell=True,
stderr=subprocess.STDOUT
stderr=subprocess.STDOUT,
)
output_str = str(output_bytes, Encoding.UTF_ENCODING.value)

Expand Down
2 changes: 1 addition & 1 deletion src/python/review/common/parallel_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def inspect_in_parallel(path: Path,
with multiprocessing.Pool(config.n_cpu) as pool:
issues = pool.map(
functools.partial(run_inspector, path, config),
inspectors
inspectors,
)

return list(itertools.chain(*issues))
2 changes: 1 addition & 1 deletion src/python/review/common/subprocess_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def run_in_subprocess(command: List[str]) -> str:
process = subprocess.run(
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
stderr=subprocess.PIPE,
)

stdout = process.stdout.decode()
Expand Down
4 changes: 2 additions & 2 deletions src/python/review/inspectors/checkstyle/checkstyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ class CheckstyleInspector(BaseInspector):
r'Boolean expression complexity is (\d+)',

'LineLengthCheck':
r'Line is longer than \d+ characters \(found (\d+)\)'
r'Line is longer than \d+ characters \(found (\d+)\)',
}

@classmethod
def _create_command(cls, path: Path, output_path: Path) -> List[str]:
return [
'java', '-jar', PATH_TOOLS_CHECKSTYLE_JAR,
'-c', PATH_TOOLS_CHECKSTYLE_CONFIG,
'-f', 'xml', '-o', output_path, str(path)
'-f', 'xml', '-o', output_path, str(path),
]

def inspect(self, path: Path, config: dict) -> List[BaseIssue]:
Expand Down
12 changes: 12 additions & 0 deletions src/python/review/inspectors/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from math import floor


def convert_percentage_of_value_to_lack_of_value(percentage_of_value: float) -> int:
"""
Converts percentage of value to lack of value.
Calculated by the formula: floor(100 - percentage_of_value).

:param percentage_of_value: value in the range from 0 to 100.
:return: lack of value.
"""
return floor(100 - percentage_of_value)
4 changes: 2 additions & 2 deletions src/python/review/inspectors/detekt/detekt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DetektInspector(BaseInspector):
'ComplexCondition':
r'This condition is too complex \((\d+)\)',
'ComplexMethod':
r'The function .* appears to be too complex \((\d+)\)'
r'The function .* appears to be too complex \((\d+)\)',
}

@classmethod
Expand All @@ -38,7 +38,7 @@ def _create_command(cls, path: Path, output_path: Path):
'--config', PATH_DETEKT_CONFIG,
'--plugins', PATH_DETEKT_PLUGIN,
'--report', f'xml:{output_path}',
'--input', str(path)
'--input', str(path),
]

def inspect(self, path: Path, config) -> List[BaseIssue]:
Expand Down
2 changes: 1 addition & 1 deletion src/python/review/inspectors/eslint/eslint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ESLintInspector(BaseInspector):

origin_class_to_pattern = {
'complexity':
r'complexity of (\d+)'
r'complexity of (\d+)',
}

@classmethod
Expand Down
6 changes: 4 additions & 2 deletions src/python/review/inspectors/flake8/.flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[flake8]
disable_noqa=True

dictionaries=en_US,python,technical,django

ignore=W291, # trailing whitespaces
W292, # no newline at end of file
W293, # blank line contains whitespaces
Expand Down Expand Up @@ -50,5 +53,4 @@ ignore=W291, # trailing whitespaces
F524, # missing argument. TODO: Collision with "P201" and "P202"
F525, # mixing automatic and manual numbering. TODO: Collision with "P205"
# flake8-commas
C814, # missing trailing comma in Python

C814, # missing trailing comma in Python 2
21 changes: 6 additions & 15 deletions src/python/review/inspectors/flake8/flake8.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import logging
import math
import re
from pathlib import Path
from typing import List

from src.python.review.common.subprocess_runner import run_in_subprocess
from src.python.review.inspectors.base_inspector import BaseInspector
from src.python.review.inspectors.common import convert_percentage_of_value_to_lack_of_value
from src.python.review.inspectors.flake8.issue_types import CODE_PREFIX_TO_ISSUE_TYPE, CODE_TO_ISSUE_TYPE
from src.python.review.inspectors.inspector_type import InspectorType
from src.python.review.inspectors.issue import (
BaseIssue,
CodeIssue,
CohesionIssue,
CyclomaticComplexityIssue,
IssueType,
IssueData,
CohesionIssue,
IssueType,
)
from src.python.review.inspectors.tips import get_cyclomatic_complexity_tip

Expand Down Expand Up @@ -69,7 +69,9 @@ def parse(cls, output: str) -> List[BaseIssue]:
issues.append(CyclomaticComplexityIssue(**issue_data))
elif cohesion_match is not None: # flake8-cohesion
issue_data[IssueData.DESCRIPTION.value] = description # TODO: Add tip
issue_data[IssueData.COHESION_LACK.value] = cls.__get_cohesion_lack(float(cohesion_match.group(1)))
issue_data[IssueData.COHESION_LACK.value] = convert_percentage_of_value_to_lack_of_value(
float(cohesion_match.group(1)),
)
issue_data[IssueData.ISSUE_TYPE.value] = IssueType.COHESION
issues.append(CohesionIssue(**issue_data))
else:
Expand Down Expand Up @@ -98,14 +100,3 @@ def choose_issue_type(code: str) -> IssueType:
return IssueType.BEST_PRACTICES

return issue_type

@staticmethod
def __get_cohesion_lack(cohesion_percentage: float) -> int:
"""
Converts cohesion percentage to lack of cohesion.
Calculated by the formula: floor(100 - cohesion_percentage).

:param cohesion_percentage: cohesion set as a percentage.
:return: lack of cohesion
"""
return math.floor(100 - cohesion_percentage)
2 changes: 2 additions & 0 deletions src/python/review/inspectors/inspector_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class InspectorType(Enum):
PYLINT = 'PYLINT'
PYTHON_AST = 'PYTHON_AST'
FLAKE8 = 'FLAKE8'
RADON = 'RADON'

# Java language
PMD = 'PMD'
Expand All @@ -29,6 +30,7 @@ def available_values(cls) -> List[str]:
cls.PYLINT.value,
cls.FLAKE8.value,
cls.PYTHON_AST.value,
cls.RADON.value,

# Java language
cls.PMD.value,
Expand Down
8 changes: 4 additions & 4 deletions src/python/review/inspectors/intellij/intellij.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self):
def create_command(output_dir_path) -> List[Union[str, Path]]:
return [
INTELLIJ_INSPECTOR_EXECUTABLE, INTELLIJ_INSPECTOR_PROJECT,
INTELLIJ_INSPECTOR_SETTINGS, output_dir_path, '-v2'
INTELLIJ_INSPECTOR_SETTINGS, output_dir_path, '-v2',
]

def inspect(self, path: Path, config: dict) -> List[BaseIssue]:
Expand Down Expand Up @@ -134,8 +134,8 @@ def parse(cls, out_dir_path: Path,
file_path = Path(
text.replace(
'file://$PROJECT_DIR$',
str(INTELLIJ_INSPECTOR_PROJECT)
)
str(INTELLIJ_INSPECTOR_PROJECT),
),
)
elif tag == 'line':
line_no = int(text)
Expand All @@ -160,7 +160,7 @@ def parse(cls, out_dir_path: Path,
description=description,
origin_class=issue_class,
inspector_type=cls.inspector_type,
type=issue_type
type=issue_type,
))

return issues
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
from typing import Dict

from src.python.review.inspectors.issue import IssueType

from src.python.review.inspectors.intellij.issue_types.java import (
ISSUE_CLASS_TO_ISSUE_TYPE as JAVA_ISSUE_CLASS_TO_ISSUE_TYPE,
)

from src.python.review.inspectors.intellij.issue_types.kotlin import (
ISSUE_CLASS_TO_ISSUE_TYPE as KOTLIN_ISSUE_CLASS_TO_ISSUE_TYPE,
)

from src.python.review.inspectors.intellij.issue_types.python import (
ISSUE_CLASS_TO_ISSUE_TYPE as PYTHON_ISSUE_CLASS_TO_ISSUE_TYPE,
)
from src.python.review.inspectors.issue import IssueType

ISSUE_CLASS_TO_ISSUE_TYPE: Dict[str, IssueType] = {
**JAVA_ISSUE_CLASS_TO_ISSUE_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,5 @@
'\'when\' that can be simplified by introducing an argument':
IssueType.CODE_STYLE,

'Annotator': IssueType.ERROR_PRONE
'Annotator': IssueType.ERROR_PRONE,
}
Loading