diff --git a/src/python/review/inspectors/flake8/flake8.py b/src/python/review/inspectors/flake8/flake8.py index 8fe5a567..74104af6 100644 --- a/src/python/review/inspectors/flake8/flake8.py +++ b/src/python/review/inspectors/flake8/flake8.py @@ -34,7 +34,7 @@ def inspect(cls, path: Path, config: dict) -> List[BaseIssue]: @classmethod def parse(cls, output: str) -> List[BaseIssue]: - row_re = re.compile(r'^(.*):(\d+):(\d+):([A-Z]\d{3}):(.*)$', re.M) + row_re = re.compile(r'^(.*):(\d+):(\d+):([A-Z]+\d{3}):(.*)$', re.M) cc_description_re = re.compile(r"'(.+)' is too complex \((\d+)\)") issues: List[BaseIssue] = [] diff --git a/test/python/inspectors/test_flake8_inspector.py b/test/python/inspectors/test_flake8_inspector.py index c723a2db..7de27bc3 100644 --- a/test/python/inspectors/test_flake8_inspector.py +++ b/test/python/inspectors/test_flake8_inspector.py @@ -12,7 +12,7 @@ ('case1_simple_valid_program.py', 0), ('case2_boolean_expressions.py', 1), ('case3_redefining_builtin.py', 1), - ('case4_naming.py', 7), + ('case4_naming.py', 10), ('case5_returns.py', 1), ('case6_unused_variables.py', 3), ('case8_good_class.py', 0), @@ -49,7 +49,7 @@ def test_file_with_issues(file_name: str, n_issues: int): ('case2_boolean_expressions.py', IssuesTestInfo(n_code_style=1, n_cc=8)), ('case3_redefining_builtin.py', IssuesTestInfo(n_error_prone=1)), - ('case4_naming.py', IssuesTestInfo(n_code_style=7, n_cc=5)), + ('case4_naming.py', IssuesTestInfo(n_code_style=7, n_best_practices=3, n_cc=5)), ('case6_unused_variables.py', IssuesTestInfo(n_best_practices=3, n_cc=1)), ('case8_good_class.py', IssuesTestInfo(n_cc=1)), @@ -79,16 +79,18 @@ def test_file_with_issues_info(file_name: str, expected_issues_info: IssuesTestI def test_parse(): file_name = 'test.py' output = ('test.py:1:11:W602:test 1\n' - 'test.py:2:12:E703:test 2') + 'test.py:2:12:E703:test 2\n' + 'test.py:3:13:SC200:test 3') issues = Flake8Inspector.parse(output) assert all(str(issue.file_path) == file_name for issue in issues) - assert [issue.line_no for issue in issues] == [1, 2] - assert [issue.column_no for issue in issues] == [11, 12] - assert [issue.description for issue in issues] == ['test 1', 'test 2'] + assert [issue.line_no for issue in issues] == [1, 2, 3] + assert [issue.column_no for issue in issues] == [11, 12, 13] + assert [issue.description for issue in issues] == ['test 1', 'test 2', 'test 3'] assert [issue.type for issue in issues] == [IssueType.CODE_STYLE, - IssueType.CODE_STYLE] + IssueType.CODE_STYLE, + IssueType.BEST_PRACTICES] def test_choose_issue_type(): diff --git a/test/resources/functional_tests/file_or_project/project/one.py b/test/resources/functional_tests/file_or_project/project/one.py index 965b9075..1ed52ea9 100644 --- a/test/resources/functional_tests/file_or_project/project/one.py +++ b/test/resources/functional_tests/file_or_project/project/one.py @@ -1,4 +1,4 @@ -from other import do_smth_useless +from other import do_something_useless if __name__ == '__main__': - do_smth_useless() \ No newline at end of file + do_something_useless() \ No newline at end of file diff --git a/test/resources/functional_tests/file_or_project/project/other.py b/test/resources/functional_tests/file_or_project/project/other.py index 5ef7e762..8553df01 100644 --- a/test/resources/functional_tests/file_or_project/project/other.py +++ b/test/resources/functional_tests/file_or_project/project/other.py @@ -1,4 +1,4 @@ -def do_smth_useless(): +def do_something_useless(): a = 1 b = 2 c = 3 \ No newline at end of file diff --git a/test/resources/inspectors/python/case13_complex_logic_2.py b/test/resources/inspectors/python/case13_complex_logic_2.py index 23e0ee63..1eaf13dc 100644 --- a/test/resources/inspectors/python/case13_complex_logic_2.py +++ b/test/resources/inspectors/python/case13_complex_logic_2.py @@ -17,10 +17,10 @@ mid_col = [elements[1], elements[4], elements[7]] down_col = [elements[2], elements[5], elements[8]] -diagonal1 = [elements[0], elements[4], elements[8]] -diagonal2 = [elements[2], elements[4], elements[6]] +diagonal_1 = [elements[0], elements[4], elements[8]] +diagonal_2 = [elements[2], elements[4], elements[6]] -full_field = [up_row, up_col, mid_row, mid_col, down_row, down_col, diagonal1, diagonal2] +full_field = [up_row, up_col, mid_row, mid_col, down_row, down_col, diagonal_1, diagonal_2] x_win = ['X', 'X', 'X'] o_win = ['O', 'O', 'O'] diff --git a/test/resources/inspectors/python/case14_returns_errors.py b/test/resources/inspectors/python/case14_returns_errors.py index 5b91e4d1..ff66f62b 100644 --- a/test/resources/inspectors/python/case14_returns_errors.py +++ b/test/resources/inspectors/python/case14_returns_errors.py @@ -1,22 +1,22 @@ -def f1(y): +def f_1(y): if not y: return return None # error! -def f2(y): +def f_2(y): if not y: return # error! return 1 -def f3(y): +def f_3(y): if not y: return # error! return 1 -def f4(): +def f_4(): a = 1 # some code that not using `a` print('test') diff --git a/test/resources/inspectors/python/case18_comprehensions.py b/test/resources/inspectors/python/case18_comprehensions.py index 0c01854a..3ed9be6f 100644 --- a/test/resources/inspectors/python/case18_comprehensions.py +++ b/test/resources/inspectors/python/case18_comprehensions.py @@ -13,9 +13,9 @@ sum([x ** 2 for x in range(10)]) # sum(x ** 2 for x in range(10)) -dct = dict() # we allow this -lst = list() # we allow this -tpl = tuple() # we allow this +test_dict = dict() # we allow this +test_list = list() # we allow this +test_tuple = tuple() # we allow this list([0 for _ in range(10)]) diff --git a/test/resources/inspectors/python/case21_imports.py b/test/resources/inspectors/python/case21_imports.py index 3c1ed10e..bdac468b 100644 --- a/test/resources/inspectors/python/case21_imports.py +++ b/test/resources/inspectors/python/case21_imports.py @@ -1,5 +1,5 @@ import itertools import functools -from functools import partialmethod +from math import ceil -print(partialmethod) \ No newline at end of file +print(ceil(0.1)) \ No newline at end of file diff --git a/whitelist.txt b/whitelist.txt index b80187db..8f29cf65 100644 --- a/whitelist.txt +++ b/whitelist.txt @@ -52,6 +52,8 @@ subdirs sym unlink utils +param +params # Springlint issues cbo dit