Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
051260c
wps-light support (#17)
GirZ0n Apr 3, 2021
f3d42f3
New flake8 plugins support (#18)
GirZ0n Apr 5, 2021
4b47996
Radon support (#19)
GirZ0n Apr 12, 2021
388f2fa
Requirements upgrade (#21)
GirZ0n Apr 14, 2021
eef3f41
xlsx-run-tool (#24)
dariadiatlova May 3, 2021
045deff
Update version to 1.2.0
nbirillo May 17, 2021
595f758
Merge branch 'main' into main-upd
vyahhi May 17, 2021
7e765fb
Rename output_format to format
GirZ0n May 30, 2021
afa44ec
Fix double quotes
GirZ0n May 30, 2021
60c93bf
Fix small issues
GirZ0n May 30, 2021
f3c2ff9
Fix small issues
GirZ0n May 30, 2021
5db1ca3
Fix double quotes
GirZ0n May 30, 2021
057031f
Fix double quotes
GirZ0n May 30, 2021
c5ffb19
Inspectors fix (#39)
GirZ0n May 31, 2021
b3d7c70
New category (#38)
GirZ0n May 31, 2021
bf40554
Merge branch 'main' into main-upd
vyahhi Jun 3, 2021
0e82bf7
Fixed trailing commas
GirZ0n Jun 3, 2021
ba15cb3
Delete create_directory function
nbirillo Jun 4, 2021
2ebb2e1
Fix GitHub actions (#44)
nbirillo Jun 16, 2021
baaa082
Fix Dockerfiles
nbirillo Jun 16, 2021
191948d
Install some dependencies for TeamCity
nbirillo Jun 16, 2021
fab7503
Merge branch 'main' into main-upd
nbirillo Jul 19, 2021
f5e3def
Update build
nbirillo Jul 19, 2021
f2e23f8
Add checks from teamcity
nbirillo Jul 19, 2021
011d272
Update build
nbirillo Jul 19, 2021
a48c808
Fix indentation
nbirillo Jul 19, 2021
e42e7a2
Fix PR comments
nbirillo Jul 19, 2021
9049c21
Merge remote-tracking branch 'origin/main-upd' into main-upd
nbirillo Jul 19, 2021
9061551
Delete init files from resources
nbirillo Jul 19, 2021
765dee0
Add init in multi file project
nbirillo Jul 19, 2021
eccbe1a
Fix flake8 tests
nbirillo Jul 20, 2021
5d329e5
Main upd bugs fix (#74)
nbirillo Jul 26, 2021
0065b51
Merge branch 'main' into main-upd
nbirillo Jul 26, 2021
6fc7095
Issues fix (#80)
GirZ0n Jul 28, 2021
dae00c0
Issue #87 fix (#90)
GirZ0n Aug 3, 2021
d155109
Fixed issues #91 and #92 (#97)
GirZ0n Aug 9, 2021
5c57bca
Delete xlsx
nbirillo Aug 10, 2021
5e8fdfc
Remove openpyxl
nbirillo Aug 11, 2021
469e50c
Issues fix (#104)
GirZ0n Aug 12, 2021
5d77b39
Update flake8 whitelist
nbirillo Aug 13, 2021
93da434
Recovered accidentally deleted words
GirZ0n Aug 13, 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
18 changes: 17 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 --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,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: |
Expand All @@ -32,3 +32,19 @@ jobs:
- name: Test with pytest
run: |
pytest

- name: Install review module
run: |
pip install .

- name: Check installed module can run python linters
run: |
review setup.py

- name: Check installed module can run java linters
run: |
review 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
9 changes: 6 additions & 3 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 Expand Up @@ -193,7 +196,7 @@ __Note__: If you have `ModuleNotFoundError` while you try to run tests, please c

__Note__: We use [eslint](https://eslint.org/) and [open-jdk 11](https://openjdk.java.net/projects/jdk/11/)
in the tests. Please, set up the environment before running the tests.
You can see en example of the environment configuration in
You can see en example of the environment configuration in
the [Dockerfile](Dockerfile) file.

Use `pytest` from the root directory to run __ALL__ tests.
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.1
1.2.0
6 changes: 5 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ pytest==6.2.3
pytest-runner==5.2
pytest-subtests==0.4.0
jsonschema==3.2.0
pandas==1.2.3
pandas==1.2.3
django==3.2
pylint==2.7.4
requests==2.25.1
setuptools==56.0.0
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ 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.2
Expand Down
26 changes: 15 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ def get_version() -> str:

def get_inspectors_additional_files() -> List[str]:
inspectors_path = current_dir / 'src' / 'python' / 'review' / 'inspectors'

result = []
for root, _, files in os.walk(inspectors_path):
for file in files:
file_path = Path(root) / file
if not file_path.name.endswith('.py'):
result.append(str(file_path))
if not file.endswith('.py'):
result.append(str(Path(root) / file))

return result

Expand All @@ -45,22 +43,28 @@ 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'
'*.unit_tests',
'*.unit_tests.*',
'unit_tests.*',
'unit_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=src.python.review.run_tool:main'
]
}
'review=src.python.review.run_tool:main',
],
},
)
74 changes: 74 additions & 0 deletions src/python/common/tool_arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
from dataclasses import dataclass
from enum import Enum, unique
from typing import List, Optional

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


@unique
class VerbosityLevel(Enum):
"""
Same meaning as the logging level. Should be used in command-line args.
"""
DEBUG = 3
INFO = 2
ERROR = 1
DISABLE = 0

@classmethod
def values(cls) -> List[int]:
return [member.value for member in VerbosityLevel]


@dataclass(frozen=True)
class ArgumentsInfo:
short_name: Optional[str]
long_name: str
description: str


@unique
class RunToolArgument(Enum):
VERBOSITY = ArgumentsInfo('-v', '--verbosity',
'Choose logging level: '
f'{VerbosityLevel.ERROR.value} - ERROR; '
f'{VerbosityLevel.INFO.value} - INFO; '
f'{VerbosityLevel.DEBUG.value} - DEBUG; '
f'{VerbosityLevel.DISABLE.value} - disable logging; '
'default is 0')

inspectors = [inspector.lower() for inspector in InspectorType.available_values()]
disabled_inspectors_example = f'-d {inspectors[0].lower()},{inspectors[1].lower()}'

DISABLE = ArgumentsInfo('-d', '--disable',
'Disable inspectors. '
f'Available values: {", ".join(inspectors)}. '
f'Example: {disabled_inspectors_example}')

DUPLICATES = ArgumentsInfo(None, '--allow-duplicates',
'Allow duplicate issues found by different linters. '
'By default, duplicates are skipped.')

LANG_VERSION = ArgumentsInfo(None, '--language-version',
'Specify the language version for JAVA inspectors.'
'Available values are: '
f'{LanguageVersion.PYTHON_3.value}, {LanguageVersion.JAVA_8.value}, '
f'{LanguageVersion.JAVA_11.value}, {LanguageVersion.KOTLIN.value}.')

CPU = ArgumentsInfo(None, '--n-cpu',
'Specify number of cpu that can be used to run inspectors')

PATH = ArgumentsInfo(None, 'path', 'Path to file or directory to inspect.')

FORMAT = ArgumentsInfo('-f', '--format',
'The output format. Default is JSON.')

START_LINE = ArgumentsInfo('-s', '--start-line',
'The first line to be analyzed. It starts from 1.')

END_LINE = ArgumentsInfo('-e', '--end-line', 'The end line to be analyzed or None.')

NEW_FORMAT = ArgumentsInfo(None, '--new-format',
'The argument determines whether the tool '
'should use the new format')
26 changes: 25 additions & 1 deletion src/python/review/application_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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.common.file_system import Extension
from src.python.review.inspectors.inspector_type import InspectorType


Expand All @@ -22,7 +23,30 @@ class LanguageVersion(Enum):
JAVA_8 = 'java8'
JAVA_9 = 'java9'
JAVA_11 = 'java11'
PYTHON_3 = 'python3'
KOTLIN = 'kotlin'

@classmethod
def values(cls) -> List[str]:
return [member.value for member in cls.__members__.values()]

@classmethod
def language_to_extension_dict(cls) -> dict:
return {cls.PYTHON_3.value: Extension.PY.value,
cls.JAVA_7.value: Extension.JAVA.value,
cls.JAVA_8.value: Extension.JAVA.value,
cls.JAVA_9.value: Extension.JAVA.value,
cls.JAVA_11.value: Extension.JAVA.value,
cls.KOTLIN.value: Extension.KT.value}

@classmethod
def language_by_extension(cls, lang: str) -> str:
return cls.language_to_extension_dict()[lang]

def is_java(self) -> bool:
return (
self == LanguageVersion.JAVA_7
or self == LanguageVersion.JAVA_8
or self == LanguageVersion.JAVA_9
or self == LanguageVersion.JAVA_11
)
15 changes: 6 additions & 9 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 @@ -65,19 +65,16 @@ def new_temp_dir() -> Path:
def create_file(file_path: Union[str, Path], content: str):
file_path = Path(file_path)

create_directory(os.path.dirname(file_path))
with open(file_path, 'w') as f:
f.write(content)


def create_directory(directory: str) -> None:
os.makedirs(directory, exist_ok=True)
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, 'w+') as f:
f.writelines(content)
yield Path(file_path)


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
47 changes: 37 additions & 10 deletions src/python/review/inspectors/checkstyle/files/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
<module name="MissingSwitchDefault"/>
<module name="ModifiedControlVariable"/>
<module name="MultipleStringLiterals">
<property name="allowedDuplicates" value="2"/>
<property name="ignoreStringsRegexp" value="^.{1,5}$"/>
<!-- Consistent with AvoidDuplicateLiterals from PMD -->
<property name="allowedDuplicates" value="3"/>
<property name="ignoreStringsRegexp" value='^".{0,2}"$'/>
</module>
<module name="MultipleVariableDeclarations"/>
<module name="NoFinalizer"/>
Expand Down Expand Up @@ -87,16 +88,42 @@
</module>
<module name="ConstantName">
<property name="format" value="^log(ger)?$|^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$"/>
<message key="name.invalidPattern"
value="Name ''{0}'' must use UPPER_CASE_SNAKE_CASE (checked pattern ''{1}'')."/>
</module>
<module name="LambdaParameterName">
<message key="name.invalidPattern"
value="Name ''{0}'' must use camelCase (checked pattern ''{1}'')."/>
</module>
<module name="LocalFinalVariableName">
<message key="name.invalidPattern"
value="Name ''{0}'' must use camelCase (checked pattern ''{1}'')."/>
</module>
<module name="LocalVariableName">
<message key="name.invalidPattern"
value="Name ''{0}'' must use camelCase (checked pattern ''{1}'')."/>
</module>
<module name="MemberName">
<message key="name.invalidPattern"
value="Name ''{0}'' must use camelCase (checked pattern ''{1}'')."/>
</module>
<module name="MethodName">
<message key="name.invalidPattern"
value="Name ''{0}'' must use camelCase (checked pattern ''{1}'')."/>
</module>
<module name="LambdaParameterName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>
<module name="ParameterName">
<message key="name.invalidPattern"
value="Name ''{0}'' must use camelCase (checked pattern ''{1}'')."/>
</module>
<module name="StaticVariableName">
<message key="name.invalidPattern"
value="Name ''{0}'' must use camelCase (checked pattern ''{1}'')."/>
</module>
<module name="TypeName">
<message key="name.invalidPattern"
value="Name ''{0}'' must use PascalCase (checked pattern ''{1}'')."/>
</module>

<!-- Checks for Size Violations. -->
<!-- See http://checkstyle.sf.net/config_sizes.html -->
Expand Down
Loading