Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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=I201,I202,I101,I100,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
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/common/file_system.py
Original file line number Diff line number Diff line change
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
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
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
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,
}
2 changes: 1 addition & 1 deletion src/python/review/inspectors/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def get_base_issue_data_dict(cls,
cls.LINE_NUMBER.value: line_number,
cls.COLUMN_NUMBER.value: column_number,
cls.ORIGIN_ClASS.value: origin_class,
cls.INSPECTOR_TYPE.value: inspector_type
cls.INSPECTOR_TYPE.value: inspector_type,
}


Expand Down
2 changes: 1 addition & 1 deletion src/python/review/inspectors/pmd/pmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _create_command(cls, path: Path,
'-language', 'java',
'-version', java_version.value,
'-f', 'csv', '-r', str(output_path),
'-t', str(n_cpu)
'-t', str(n_cpu),
]

def inspect(self, path: Path, config: dict) -> List[BaseIssue]:
Expand Down
14 changes: 7 additions & 7 deletions src/python/review/inspectors/pyast/python_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def visit(self, node: ast.AST):
origin_class=BOOL_EXPR_LEN_ORIGIN_CLASS,
inspector_type=self._inspector_type,
bool_expr_len=length,
type=IssueType.BOOL_EXPR_LEN
type=IssueType.BOOL_EXPR_LEN,
))


Expand All @@ -58,7 +58,7 @@ def __init__(self, content: str, file_path: Path, inspector_type: InspectorType)
def visit(self, node):
if isinstance(self._previous_node, (ast.FunctionDef, ast.AsyncFunctionDef)):
func_length = self._find_func_len(
self._previous_node.lineno, node.lineno
self._previous_node.lineno, node.lineno,
)

self._function_lens.append(FuncLenIssue(
Expand All @@ -69,7 +69,7 @@ def visit(self, node):
origin_class=FUNC_LEN_ORIGIN_CLASS,
inspector_type=self._inspector_type,
func_len=func_length,
type=IssueType.FUNC_LEN
type=IssueType.FUNC_LEN,
))

self._previous_node = node
Expand All @@ -80,7 +80,7 @@ def visit(self, node):
def function_lens(self) -> List[FuncLenIssue]:
if isinstance(self._previous_node, (ast.FunctionDef, ast.AsyncFunctionDef)):
func_length = self._find_func_len(
self._previous_node.lineno, self._n_lines + 1
self._previous_node.lineno, self._n_lines + 1,
)

self._function_lens.append(FuncLenIssue(
Expand All @@ -91,7 +91,7 @@ def function_lens(self) -> List[FuncLenIssue]:
origin_class=FUNC_LEN_ORIGIN_CLASS,
inspector_type=self._inspector_type,
func_len=func_length,
type=IssueType.FUNC_LEN
type=IssueType.FUNC_LEN,
))

self._previous_node = None
Expand Down Expand Up @@ -125,13 +125,13 @@ def inspect(cls, path: Path, config: dict) -> List[BaseIssue]:
bool_gatherer = BoolExpressionLensGatherer(path_to_file, cls.inspector_type)
bool_gatherer.visit(tree)
metrics.extend(
bool_gatherer.bool_expression_lens
bool_gatherer.bool_expression_lens,
)

func_gatherer = FunctionLensGatherer(file_content, path_to_file, cls.inspector_type)
func_gatherer.visit(tree)
metrics.extend(
func_gatherer.function_lens
func_gatherer.function_lens,
)

return metrics
Expand Down
6 changes: 3 additions & 3 deletions src/python/review/inspectors/pylint/pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PylintInspector(BaseInspector):
supported_issue_types = (
IssueType.CODE_STYLE,
IssueType.BEST_PRACTICES,
IssueType.ERROR_PRONE
IssueType.ERROR_PRONE,
)

@classmethod
Expand All @@ -31,7 +31,7 @@ def inspect(cls, path: Path, config: dict) -> List[CodeIssue]:
'--load-plugins', 'pylint_django',
f'--rcfile={PATH_PYLINT_CONFIG}',
f'--msg-template={MSG_TEMPLATE}',
str(path)
str(path),
]

output = run_in_subprocess(command)
Expand Down Expand Up @@ -70,7 +70,7 @@ def parse(cls, output: str) -> List[CodeIssue]:
origin_class=origin_class,
description=description,
inspector_type=cls.inspector_type,
type=issue_type
type=issue_type,
))

return issues
Expand Down
2 changes: 1 addition & 1 deletion src/python/review/inspectors/radon/radon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def inspect(cls, path: Path, config: dict) -> List[BaseIssue]:
"radon", "mi",
"--max", "F",
"--show",
path
path,
]

mi_output = run_in_subprocess(mi_command)
Expand Down
4 changes: 2 additions & 2 deletions src/python/review/inspectors/spotbugs/spotbugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _create_command(cls, path: Path) -> List[str]:
PATH_SPOTBUGS_EXCLUDE,
'-textui',
'-medium',
str(path)
str(path),
]

def inspect(self, path: Path, config: dict) -> List[BaseIssue]:
Expand Down Expand Up @@ -100,5 +100,5 @@ def _parse_single_line(cls, line: str, file_name_to_path: Dict[str, Path]) -> Ba
type=IssueType.ERROR_PRONE,
origin_class=issue_class,
description=short_desc,
inspector_type=cls.inspector_type
inspector_type=cls.inspector_type,
)
10 changes: 5 additions & 5 deletions src/python/review/inspectors/springlint/springlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SpringlintInspector(BaseInspector):
'cbo': 'class_objects_coupling',
'lcom': 'cohesion_lack',
'rfc': 'class_response',
'nom': 'method_number'
'nom': 'method_number',
}

metric_name_to_description = {
Expand All @@ -61,7 +61,7 @@ class SpringlintInspector(BaseInspector):
'cbo': get_class_coupling_tip(),
'lcom': get_cohesion_tip(),
'rfc': get_class_response_tip(),
'nom': get_method_number_tip()
'nom': get_method_number_tip(),
}

metric_name_to_issue_type = {
Expand All @@ -71,7 +71,7 @@ class SpringlintInspector(BaseInspector):
'cbo': IssueType.COUPLING,
'lcom': IssueType.COHESION,
'rfc': IssueType.CLASS_RESPONSE,
'nom': IssueType.METHOD_NUMBER
'nom': IssueType.METHOD_NUMBER,
}

@classmethod
Expand All @@ -81,7 +81,7 @@ def _create_command(cls, path: Path, output_path: Path) -> List[str]:
PATH_SPRINGLINT_JAR,
'--output', str(output_path),
'-otype', 'html',
'--project', str(path)
'--project', str(path),
]

def inspect(self, path: Path, config: dict) -> List[BaseIssue]:
Expand Down Expand Up @@ -137,7 +137,7 @@ def _parse_smells(cls, file_content: AnyStr, origin_path: str = '') -> List[Base
origin_class=smell['name'],
inspector_type=cls.inspector_type,
type=IssueType.ARCHITECTURE,
description=smell['description']
description=smell['description'],
) for smell in file_smell['smells']])

return issues
Expand Down
12 changes: 6 additions & 6 deletions src/python/review/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
'formatters': {
'common': {
'class': 'logging.Formatter',
'format': '%(asctime)s | %(levelname)s | %(message)s'
}
'format': '%(asctime)s | %(levelname)s | %(message)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'DEBUG',
'formatter': 'common',
'stream': sys.stdout
'stream': sys.stdout,
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'INFO'
}
'level': 'INFO',
},
},
'disable_existing_loggers': False
'disable_existing_loggers': False,
}
13 changes: 6 additions & 7 deletions src/python/review/quality/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __le__(self, other: 'QualityType') -> bool:
QualityType.BAD: 0,
QualityType.MODERATE: 1,
QualityType.GOOD: 2,
QualityType.EXCELLENT: 3
QualityType.EXCELLENT: 3,
}

return order[self] < order[other]
Expand Down Expand Up @@ -81,12 +81,11 @@ def __str__(self):
message_deltas_part = ''

if self.quality_type != QualityType.EXCELLENT:
message_next_level_part = textwrap.dedent(
f"""\
Next level: {self.next_quality_type.value}
Next level requirements:
"""
)
message_next_level_part = f"""\
Next level: {self.next_quality_type.value}
Next level requirements:
"""
message_next_level_part = textwrap.dedent(message_next_level_part)

for rule in self.next_level_requirements:
message_deltas_part += f'{rule.rule_type.value}: {rule.next_level_delta}\n'
Expand Down
Loading