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
7 changes: 3 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ jobs:
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide.
# TODO: Delete W503 from ignore after refactoring and change max-complexity into 10
flake8 . --count --exit-zero --max-complexity=15 --max-line-length=127 --ignore=I201,I101,I100,R504,A003,I202,SC200,E800,W505,SC100,E402,R504,W503 --statistics --exclude=.git,__pycache__,docs/source/conf.py,old,build,dist,venv,test/resources,.eggs,review.egg-info,.pytest_cache,node_modules
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
- name: Set up Eslint
run: |
npm install eslint --save-dev
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ 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`.
**‑‑allow_duplicates** | allow duplicate issues found by different linters. By default, duplicates are skipped.
**‑‑language_version** | specify the language version for JAVA inspectors. Available values: `java7`, `java8`, `java9`, `java11`.
**‑‑n_cpu** | specify number of _cpu_ that can be used to run inspectors
**‑‑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.
**‑f**, **‑‑format** | the output format. Available values: `json`, `text`. Default value is `json`.
**‑s**, **‑‑start_line**| the first line to be analyzed. By default it starts from `1`.
**‑e**, **‑‑end_line** | the end line to be analyzed. The default value is `None`, which meant to handle file by the end.
**‑‑new_format** | the argument determines whether the tool should use the _new format_. _New format_ means separating the result by the files to allow getting quality and observed issues for each file separately. The default value is `False`.
**‑s**, **‑‑start-line**| the first line to be analyzed. By default it starts from `1`.
**‑e**, **‑‑end-line** | the end line to be analyzed. The default value is `None`, which meant to handle file by the end.
**‑‑new-format** | the argument determines whether the tool should use the _new format_. _New format_ means separating the result by the files to allow getting quality and observed issues for each file separately. The default value is `False`.

The output examples:

Expand Down
3 changes: 2 additions & 1 deletion src/python/review/common/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def get_file_line(path: Path, line_number: int):
).strip()


def get_content_from_file(file_path: Path, encoding: str = Encoding.ISO_ENCODING.value, to_strip_nl: bool = True) -> str:
def get_content_from_file(file_path: Path, encoding: str = Encoding.ISO_ENCODING.value,
to_strip_nl: bool = True) -> str:
with open(file_path, 'r', encoding=encoding) as f:
content = f.read()
return content if not to_strip_nl else content.rstrip('\n')
Expand Down
4 changes: 2 additions & 2 deletions src/python/review/inspectors/base_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class BaseInspector(abc.ABC):
@property
@abc.abstractmethod
def inspector_type(self) -> InspectorType:
raise NotImplementedError(f'inspector_type property not implemented yet')
raise NotImplementedError('inspector_type property not implemented yet')

@abc.abstractmethod
def inspect(self, path: Path, config: dict) -> List[BaseIssue]:
raise NotImplementedError(f'inspect method not implemented yet')
raise NotImplementedError('inspect method not implemented yet')
5 changes: 2 additions & 3 deletions src/python/review/quality/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import List

from src.python.review.inspectors.issue import IssueType
from src.python.review.reviewers.utils.code_statistics import CodeStatistics


@total_ordering
Expand Down Expand Up @@ -44,11 +43,11 @@ def __init__(self, rules: List[Rule]):

@property
def quality_type(self) -> QualityType:
return min([rule.quality_type for rule in self.rules], default=QualityType.EXCELLENT)
return min(map(lambda rule: rule.quality_type, self.rules), default=QualityType.EXCELLENT)

@property
def next_quality_type(self) -> QualityType:
return min([rule.next_level_type for rule in self.rules], default=QualityType.EXCELLENT)
return min(map(lambda rule: rule.next_level_type, self.rules), default=QualityType.EXCELLENT)

# TODO@nbirillo: why rule.quality_type == quality_type for next level????
@property
Expand Down
2 changes: 1 addition & 1 deletion src/python/review/reviewers/utils/code_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_code_style_lines(issues: List[BaseIssue]) -> int:

def __get_max_measure_by_issue_type(issue_type: IssueType, issues: List[BaseIssue]) -> int:
return max(map(
lambda issue: issue.measure,
lambda issue: issue.measure(),
filter(lambda issue: issue.type == issue_type, issues)
), default=0)

Expand Down
19 changes: 10 additions & 9 deletions src/python/review/run_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,19 @@ def configure_arguments(parser: argparse.ArgumentParser) -> None:
type=parse_disabled_inspectors,
default=set())

parser.add_argument('--allow_duplicates', action='store_true',
parser.add_argument('--allow-duplicates', action='store_true',
help='Allow duplicate issues found by different linters. '
'By default, duplicates are skipped.')

parser.add_argument('--language_version',
# TODO: deprecated argument: language_version. Delete after several realises.
parser.add_argument('--language_version', '--language-version',
help='Specify the language version for JAVA inspectors.',
default=None,
choices=LanguageVersion.values(),
type=str)

parser.add_argument('--n_cpu',
# TODO: deprecated argument: --n_cpu. Delete after several realises.
parser.add_argument('--n_cpu', '--n-cpu',
help='Specify number of cpu that can be used to run inspectors',
default=1,
type=positive_int)
Expand All @@ -94,22 +96,22 @@ def configure_arguments(parser: argparse.ArgumentParser) -> None:
help='Path to file or directory to inspect.')

parser.add_argument('-f', '--format',
default=OutputFormat.JSON,
default=OutputFormat.JSON.value,
choices=OutputFormat.values(),
type=str,
help='The output format. Default is JSON.')

parser.add_argument('-s', '--start_line',
parser.add_argument('-s', '--start-line',
default=1,
type=positive_int,
help='The first line to be analyzed. It starts from 1.')

parser.add_argument('-e', '--end_line',
parser.add_argument('-e', '--end-line',
default=None,
type=positive_int,
help='The end line to be analyzed or None.')

parser.add_argument('--new_format',
parser.add_argument('--new-format',
action='store_true',
help='The argument determines whether the tool '
'should use the new format')
Expand Down Expand Up @@ -140,8 +142,7 @@ def main() -> int:
max_n_cpu = os.cpu_count()
if n_cpu > max_n_cpu:
n_cpu = max_n_cpu
logger.warning(f'Number of available cpu is {max_n_cpu}, '
f'but {n_cpu} was passed')
logger.warning('Number of available cpu is %s, but %s was passed', max_n_cpu, n_cpu)

start_line = args.start_line
if start_line < 1:
Expand Down
6 changes: 3 additions & 3 deletions test/python/functional_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def build(self) -> List[str]:
command.extend(['-d', ','.join(self.disable)])

if self.allow_duplicates:
command.append('--allow_duplicates')
command.append('--allow-duplicates')

if self.language_version is not None:
command.extend(['--language_version', self.language_version])
command.extend(['--language-version', self.language_version])

if self.new_format:
command.append('--new_format')
command.append('--new-format')

command.extend([
'--n_cpu', str(self.n_cpu),
Expand Down