From c17b5362c2efd3cf983c74ca305459e4ed38b089 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Tue, 27 Jul 2021 15:38:41 +0300 Subject: [PATCH 01/13] Fixed issue #70 --- src/python/review/inspectors/pylint/issue_types.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/review/inspectors/pylint/issue_types.py b/src/python/review/inspectors/pylint/issue_types.py index edfe8818..374b67a3 100644 --- a/src/python/review/inspectors/pylint/issue_types.py +++ b/src/python/review/inspectors/pylint/issue_types.py @@ -8,6 +8,7 @@ # E errors, for probable bugs in the code CODE_TO_ISSUE_TYPE: Dict[str, IssueType] = { + 'C0200': IssueType.BEST_PRACTICES, # consider using enumerate 'W0101': IssueType.ERROR_PRONE, # unreachable code 'W0102': IssueType.ERROR_PRONE, # dangerous default value 'W0104': IssueType.ERROR_PRONE, # statement doesn't have any effect From 9b020474e91385fa7e96db3d03c223c86cd8be81 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Tue, 27 Jul 2021 15:51:11 +0300 Subject: [PATCH 02/13] Fixed issue #72: now only spellcheck checks brackets --- src/python/review/inspectors/pmd/files/bin/basic.xml | 3 ++- test/python/inspectors/test_pmd_inspector.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/python/review/inspectors/pmd/files/bin/basic.xml b/src/python/review/inspectors/pmd/files/bin/basic.xml index 6cacd764..3048aa9e 100644 --- a/src/python/review/inspectors/pmd/files/bin/basic.xml +++ b/src/python/review/inspectors/pmd/files/bin/basic.xml @@ -52,7 +52,8 @@ - + + diff --git a/test/python/inspectors/test_pmd_inspector.py b/test/python/inspectors/test_pmd_inspector.py index 393a2d46..15b8006e 100644 --- a/test/python/inspectors/test_pmd_inspector.py +++ b/test/python/inspectors/test_pmd_inspector.py @@ -15,7 +15,7 @@ ('test_comparing_strings.java', 3), ('test_constants.java', 4), ('test_covariant_equals.java', 1), - ('test_curly_braces.java', 2), + ('test_curly_braces.java', 0), ('test_double_checked_locking.java', 2), ('test_for_loop.java', 2), ('test_implementation_types.java', 0), From e3ceef36deeff6af9da3cf57c1df81dff2538cc3 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Tue, 27 Jul 2021 16:17:11 +0300 Subject: [PATCH 03/13] Fixed issue #73 --- .../inspectors/checkstyle/files/config.xml | 42 +++++++++++++++---- .../review/inspectors/pmd/files/bin/basic.xml | 15 ++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/python/review/inspectors/checkstyle/files/config.xml b/src/python/review/inspectors/checkstyle/files/config.xml index 00222e43..92fa6f07 100644 --- a/src/python/review/inspectors/checkstyle/files/config.xml +++ b/src/python/review/inspectors/checkstyle/files/config.xml @@ -87,16 +87,42 @@ + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + diff --git a/src/python/review/inspectors/pmd/files/bin/basic.xml b/src/python/review/inspectors/pmd/files/bin/basic.xml index 3048aa9e..6ff44ab3 100644 --- a/src/python/review/inspectors/pmd/files/bin/basic.xml +++ b/src/python/review/inspectors/pmd/files/bin/basic.xml @@ -46,7 +46,8 @@ - + @@ -59,17 +60,21 @@ - + - + - - + + From a2cc1351539069912cd5835d10cc91609db2851b Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Tue, 27 Jul 2021 16:27:03 +0300 Subject: [PATCH 04/13] Fixed issue #77 --- src/python/review/inspectors/flake8/.flake8 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/review/inspectors/flake8/.flake8 b/src/python/review/inspectors/flake8/.flake8 index 19edebba..223ef2e0 100644 --- a/src/python/review/inspectors/flake8/.flake8 +++ b/src/python/review/inspectors/flake8/.flake8 @@ -27,6 +27,7 @@ ignore=W291, # trailing whitespaces WPS305, # Forbid f strings. WPS306, # Forbid writing classes without base classes. WPS318, # Forbid extra indentation. TODO: Collision with standard flake8 indentation check + WPS319, # Forbid brackets in the wrong position. (Because of the unnecessary strictness) WPS323, # Forbid % formatting on strings. WPS324, # Enforce consistent return statements. TODO: Collision with flake8-return WPS335, # Forbid wrong for loop iter targets. From 0fb08385651044d5fbbc173803c44bd5f3f9dd43 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Tue, 27 Jul 2021 16:33:31 +0300 Subject: [PATCH 05/13] Fixed issue #78 --- src/python/review/inspectors/pylint/pylintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/review/inspectors/pylint/pylintrc b/src/python/review/inspectors/pylint/pylintrc index c435b63b..dbb1cb77 100644 --- a/src/python/review/inspectors/pylint/pylintrc +++ b/src/python/review/inspectors/pylint/pylintrc @@ -164,6 +164,7 @@ disable=invalid-name, no-else-raise, no-else-break, no-else-continue, + W0614, # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From e631a46c34959019b54a31b6ca32555f3328c07d Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Tue, 27 Jul 2021 17:02:14 +0300 Subject: [PATCH 06/13] Fixed issue #71 --- src/python/review/inspectors/flake8/.flake8 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/review/inspectors/flake8/.flake8 b/src/python/review/inspectors/flake8/.flake8 index 223ef2e0..f72d3e19 100644 --- a/src/python/review/inspectors/flake8/.flake8 +++ b/src/python/review/inspectors/flake8/.flake8 @@ -26,6 +26,7 @@ ignore=W291, # trailing whitespaces WPS303, # Forbid underscores in numbers. WPS305, # Forbid f strings. WPS306, # Forbid writing classes without base classes. + WPS317, # Forbid incorrect indentation for parameters. (Because of the unnecessary strictness) WPS318, # Forbid extra indentation. TODO: Collision with standard flake8 indentation check WPS319, # Forbid brackets in the wrong position. (Because of the unnecessary strictness) WPS323, # Forbid % formatting on strings. From d518906ba73ee895fc6d06fa7c5996b6940d8df5 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Tue, 27 Jul 2021 17:42:02 +0300 Subject: [PATCH 07/13] Fixed issue #79 --- src/python/review/inspectors/flake8/.flake8 | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/review/inspectors/flake8/.flake8 b/src/python/review/inspectors/flake8/.flake8 index f72d3e19..33d1ac8f 100644 --- a/src/python/review/inspectors/flake8/.flake8 +++ b/src/python/review/inspectors/flake8/.flake8 @@ -33,6 +33,7 @@ ignore=W291, # trailing whitespaces WPS324, # Enforce consistent return statements. TODO: Collision with flake8-return WPS335, # Forbid wrong for loop iter targets. WPS358, # Forbid using float zeros: 0.0. + WPS359, # Forbids to unpack iterable objects to lists. (Because of its similarity to "WPS414") WPS362, # Forbid assignment to a subscript slice. # WPS: Best practices WPS404, # Forbid complex defaults. TODO: Collision with "B006" From 03f3ef07618374fffc5201ff53f7d0d9847e6be9 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Wed, 28 Jul 2021 09:30:05 +0300 Subject: [PATCH 08/13] Fixed issue #81 --- src/python/review/inspectors/pmd/files/bin/basic.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python/review/inspectors/pmd/files/bin/basic.xml b/src/python/review/inspectors/pmd/files/bin/basic.xml index 6ff44ab3..612bbf0e 100644 --- a/src/python/review/inspectors/pmd/files/bin/basic.xml +++ b/src/python/review/inspectors/pmd/files/bin/basic.xml @@ -96,7 +96,8 @@ - + From 9c75e6f3020b38d1209cbb01463e7c31c906aedd Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Wed, 28 Jul 2021 10:28:38 +0300 Subject: [PATCH 09/13] Added case 36: unpacking --- test/python/inspectors/test_flake8_inspector.py | 2 ++ test/resources/inspectors/python/case36_unpacking.py | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/resources/inspectors/python/case36_unpacking.py diff --git a/test/python/inspectors/test_flake8_inspector.py b/test/python/inspectors/test_flake8_inspector.py index f1ed0958..7dc7354c 100644 --- a/test/python/inspectors/test_flake8_inspector.py +++ b/test/python/inspectors/test_flake8_inspector.py @@ -34,6 +34,7 @@ ('case33_commas.py', 14), ('case34_cohesion.py', 1), ('case35_line_break.py', 11), + ('case36_unpacking.py', 3), ] @@ -76,6 +77,7 @@ def test_file_with_issues(file_name: str, n_issues: int): ('case32_string_format.py', IssuesTestInfo(n_error_prone=28, n_other_complexity=6)), ('case33_commas.py', IssuesTestInfo(n_code_style=14, n_cc=4)), ('case34_cohesion.py', IssuesTestInfo(n_cc=6, n_cohesion=2)), + ('case36_unpacking.py', IssuesTestInfo(n_error_prone=2, n_cc=1, n_other_complexity=1)), ] diff --git a/test/resources/inspectors/python/case36_unpacking.py b/test/resources/inspectors/python/case36_unpacking.py new file mode 100644 index 00000000..74b4ec9c --- /dev/null +++ b/test/resources/inspectors/python/case36_unpacking.py @@ -0,0 +1,10 @@ +[a, b, c], [x, y, z] = (sorted(map(int, input().split())) for _ in 'lm') +if [a, b, c] == [x, y, z]: + a = "Boxes are equal" +elif a <= x and b <= y and c <= z: + a = "The first box is smaller than the second one" +elif a >= x and b >= y and c >= z: + a = "The first box is larger than the second one" +else: + a = "Boxes are incomparable" +print(a) From 0800b2221dec3cada1284c5d74db4fbef72b2651 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Wed, 28 Jul 2021 11:03:12 +0300 Subject: [PATCH 10/13] Added case 37: wildcard import --- .../inspectors/test_flake8_inspector.py | 2 ++ .../python/case37_wildcard_import.py | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/resources/inspectors/python/case37_wildcard_import.py diff --git a/test/python/inspectors/test_flake8_inspector.py b/test/python/inspectors/test_flake8_inspector.py index 7dc7354c..2a2ebf26 100644 --- a/test/python/inspectors/test_flake8_inspector.py +++ b/test/python/inspectors/test_flake8_inspector.py @@ -35,6 +35,7 @@ ('case34_cohesion.py', 1), ('case35_line_break.py', 11), ('case36_unpacking.py', 3), + ('case37_wildcard_import.py', 7), ] @@ -78,6 +79,7 @@ def test_file_with_issues(file_name: str, n_issues: int): ('case33_commas.py', IssuesTestInfo(n_code_style=14, n_cc=4)), ('case34_cohesion.py', IssuesTestInfo(n_cc=6, n_cohesion=2)), ('case36_unpacking.py', IssuesTestInfo(n_error_prone=2, n_cc=1, n_other_complexity=1)), + ('case37_wildcard_import.py', IssuesTestInfo(n_best_practices=1, n_error_prone=3, n_cc=2, n_other_complexity=2)), ] diff --git a/test/resources/inspectors/python/case37_wildcard_import.py b/test/resources/inspectors/python/case37_wildcard_import.py new file mode 100644 index 00000000..ed12a4b1 --- /dev/null +++ b/test/resources/inspectors/python/case37_wildcard_import.py @@ -0,0 +1,33 @@ +from numpy import * + +n, m = [int(_) for _ in input().split()] +mat = zeros((n, m)) +s = 1 +for j in range(n): + for i in range(j, m - j): + if s > n * m: + break + mat[j][i] = s + s += 1 + + for i in range(j - n + 1, -j): + if s > n * m: + break + mat[i][-j - 1] = s + s += 1 + for i in range(-j - 2, -m + j - 1, -1): + if s > n * m: + break + mat[-j - 1][i] = s + s += 1 + + for i in range(-2 - j, -n + j, -1): + if s > n * m: + break + mat[i][j] = s + s += 1 + +for r in range(n): + for c in range(m): + print(str(int(mat[r][c])).ljust(2), end=' ') + print() From 3990f8151d7798bfcfcd72ae52244f7c1ee70ee9 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Wed, 28 Jul 2021 11:03:51 +0300 Subject: [PATCH 11/13] Ignoring WPS347 and F405 --- src/python/review/inspectors/flake8/.flake8 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/python/review/inspectors/flake8/.flake8 b/src/python/review/inspectors/flake8/.flake8 index 33d1ac8f..f0452e5a 100644 --- a/src/python/review/inspectors/flake8/.flake8 +++ b/src/python/review/inspectors/flake8/.flake8 @@ -32,6 +32,7 @@ ignore=W291, # trailing whitespaces WPS323, # Forbid % formatting on strings. WPS324, # Enforce consistent return statements. TODO: Collision with flake8-return WPS335, # Forbid wrong for loop iter targets. + WPS347, # Forbid imports that may cause confusion outside of the module. (controversial) WPS358, # Forbid using float zeros: 0.0. WPS359, # Forbids to unpack iterable objects to lists. (Because of its similarity to "WPS414") WPS362, # Forbid assignment to a subscript slice. @@ -52,6 +53,7 @@ ignore=W291, # trailing whitespaces P101, # format string does contain unindexed parameters P102, # docstring does contain unindexed parameters P103, # other string does contain unindexed parameters + F405, # Name may be undefined, or defined from star imports (Collision with the stricter "F403") F522, # unused named arguments. TODO: Collision with "P302" F523, # unused positional arguments. TODO: Collision with "P301" F524, # missing argument. TODO: Collision with "P201" and "P202" From bacf42fbd2ed632dea4af60d853fa747a7ef4a57 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Wed, 28 Jul 2021 11:35:34 +0300 Subject: [PATCH 12/13] Added cases 36 (unpacking) and 37 (wildcard_import). Also removed W0622 (redefining_builtin) --- test/python/inspectors/test_pylint_inspector.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/python/inspectors/test_pylint_inspector.py b/test/python/inspectors/test_pylint_inspector.py index ba4be12f..fc381234 100644 --- a/test/python/inspectors/test_pylint_inspector.py +++ b/test/python/inspectors/test_pylint_inspector.py @@ -11,7 +11,7 @@ ('case0_spaces.py', 0), ('case1_simple_valid_program.py', 0), ('case2_boolean_expressions.py', 3), - ('case3_redefining_builtin.py', 2), + ('case3_redefining_builtin.py', 0), ('case4_naming.py', 3), ('case5_returns.py', 1), ('case6_unused_variables.py', 4), @@ -32,6 +32,8 @@ ('case25_django.py', 0), ('case27_using_requests.py', 0), ('case30_allow_else_return.py', 0), + ('case36_unpacking.py', 0), + ('case37_wildcard_import.py', 1), ] From ec8d40c21c181123a593ef605b4bb32baa050830 Mon Sep 17 00:00:00 2001 From: Ilya Vlasov Date: Wed, 28 Jul 2021 11:35:46 +0300 Subject: [PATCH 13/13] Removed W0622 (redefining_builtin) --- src/python/review/inspectors/pylint/pylintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/review/inspectors/pylint/pylintrc b/src/python/review/inspectors/pylint/pylintrc index dbb1cb77..357ba058 100644 --- a/src/python/review/inspectors/pylint/pylintrc +++ b/src/python/review/inspectors/pylint/pylintrc @@ -165,6 +165,7 @@ disable=invalid-name, no-else-break, no-else-continue, W0614, + W0622, # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option