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
30 changes: 28 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,60 @@ jobs:
container: stepik/hyperstyle-base:py3.8.11-java11.0.11-node14.17.3

steps:
- name: Install git
run: |
apt-get update
apt-get -y install git

- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Install requirements
run: |
pip install --no-cache-dir -r requirements-test.txt -r requirements.txt

- 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 --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
# TODO: remove R504, A003, E800, E402, WPS1, WPS2, WPS3, WPS4, WPS5, WPS6, H601
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: Sort whitelists
run: |
for file in "whitelist.txt" "src/python/review/inspectors/flake8/whitelist.txt"
do
LC_ALL=C sort $file -o $file
done

- name: Commit sorted whitelists
uses: EndBug/add-and-commit@v7.2.1
with:
add: "['whitelist.txt', 'src/python/review/inspectors/flake8/whitelist.txt']"
message: 'Sort whitelists (Github Actions)'

- name: Set up Eslint
run: |
# Consistent with eslint version in Dockerfile
npm install eslint@7.5.0 -g && eslint --init

- 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
review test/resources/inspectors/js/case0_no_issues.js
7 changes: 0 additions & 7 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,3 @@ pytest==6.2.3
pytest-runner==5.2
pytest-subtests==0.4.0
jsonschema==3.2.0
pandas==1.2.3
django==3.2
pylint==2.7.4
requests==2.25.1
setuptools==56.0.0
openpyxl==3.0.7
pandarallel==1.5.2
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ radon==4.5.0
django==3.2
requests==2.25.1
argparse==1.4.0
pyyaml
pyyaml==5.4.1
46 changes: 36 additions & 10 deletions src/python/review/inspectors/checkstyle/files/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
<module name="MissingSwitchDefault"/>
<module name="ModifiedControlVariable"/>
<module name="MultipleStringLiterals">
<!-- Consistent with the AvoidDuplicateLiterals rule from PMD config -->
<!-- Consistent with AvoidDuplicateLiterals from PMD -->
<property name="allowedDuplicates" value="3"/>
<property name="ignoreStringsRegexp" value="^.{1,2}$"/>
<property name="ignoreStringsRegexp" value='^".{0,2}"$'/>
</module>
<module name="MultipleVariableDeclarations"/>
<module name="NoFinalizer"/>
Expand Down Expand Up @@ -81,16 +81,42 @@
<module name="AbbreviationAsWordInName"/>
<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>

<!-- Size Violations -->
<module name="ParameterNumber">
Expand Down
5 changes: 5 additions & 0 deletions src/python/review/inspectors/flake8/.flake8
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ 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.
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.
# WPS: Best practices
WPS404, # Forbid complex defaults. TODO: Collision with "B006"
Expand All @@ -50,6 +54,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"
Expand Down
17 changes: 17 additions & 0 deletions src/python/review/inspectors/flake8/whitelist.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
aggfunc
appendleft
arange
argmax
asctime
astype
barmode
betavariate
bgcolor
birthdate
blackbox
bs4
Expand All @@ -13,6 +16,8 @@ capwords
casefold
caseless
concat
config
configs
consts
coord
copysign
Expand Down Expand Up @@ -40,13 +45,15 @@ expm1
falsy
fillna
floordiv
fromkeys
fromstring
fullmatch
gensim
gmtime
groupby
halfs
hashable
hline
href
hyp
hyperskill
Expand All @@ -72,13 +79,16 @@ lemmatizer
lifes
lim
linalg
linecolor
linewidth
linspace
lowercased
lvl
lxml
matmul
minsize
multiline
nbins
ndarray
ndigits
ndim
Expand All @@ -100,6 +110,7 @@ rindex
rmdir
schur
scipy
showline
sigmoid
sqrt
src
Expand All @@ -117,6 +128,7 @@ tokenize
tokenized
tokenizer
tolist
toplevel
tracklist
truediv
truthy
Expand All @@ -125,6 +137,11 @@ unpickled
upd
util
utils
vline
webpage
whitespaces
writeback
xanchor
xaxes
yanchor
yaxis
21 changes: 14 additions & 7 deletions src/python/review/inspectors/pmd/files/bin/basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,31 @@
<rule ref="category/java/codestyle.xml/AvoidProtectedMethodInFinalClassNotExtending"/>
<rule ref="category/java/codestyle.xml/BooleanGetMethodName"/>
<rule ref="category/java/codestyle.xml/CallSuperInConstructor"/>
<rule ref="category/java/codestyle.xml/ClassNamingConventions">
<rule ref="category/java/codestyle.xml/ClassNamingConventions"
message="Name ''{1}'' must use PascalCase (checked pattern ''{2}'').">
<properties>
<property name="utilityClassPattern" value="[A-Z][a-zA-Z0-9]+(Utils?|Helper|Constants)?"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ControlStatementBraces"/>
<!-- Disabled due to NeedBracesCheck duplication -->
<!-- <rule ref="category/java/codestyle.xml/ControlStatementBraces"/> -->
<rule ref="category/java/codestyle.xml/EmptyMethodInAbstractClassShouldBeAbstract"/>
<rule ref="category/java/codestyle.xml/ExtendsObject"/>
<rule ref="category/java/codestyle.xml/FieldDeclarationsShouldBeAtStartOfClass"/>
<rule ref="category/java/codestyle.xml/FieldNamingConventions">
<rule ref="category/java/codestyle.xml/FieldNamingConventions"
message="Fields must be written using camelCase and constants using UPPER_CASE_SNAKE_CASE. (Incorrect name: ''{1}''. Checked pattern: ''{2}'').">
<properties>
<property name="exclusions" value="serialVersionUID|serialPersistentFields|log|logger"/>
</properties>
</rule>
<rule ref="category/java/codestyle.xml/ForLoopShouldBeWhileLoop"/>
<rule ref="category/java/codestyle.xml/FormalParameterNamingConventions"/>
<rule ref="category/java/codestyle.xml/FormalParameterNamingConventions"
message="Name ''{1}'' must use camelCase (checked pattern ''{2}'')."/>
<rule ref="category/java/codestyle.xml/IdenticalCatchBranches"/>
<rule ref="category/java/codestyle.xml/LocalVariableNamingConventions"/>
<rule ref="category/java/codestyle.xml/MethodNamingConventions"/>
<rule ref="category/java/codestyle.xml/LocalVariableNamingConventions"
message="Name ''{1}'' must use camelCase (checked pattern ''{2}'')."/>
<rule ref="category/java/codestyle.xml/MethodNamingConventions"
message="Name ''{1}'' must use camelCase (checked pattern ''{2}'')."/>
<rule ref="category/java/codestyle.xml/PackageCase"/>
<rule ref="category/java/codestyle.xml/UnnecessaryCast"/>
<rule ref="category/java/codestyle.xml/UnnecessaryConstructor"/>
Expand All @@ -93,7 +99,8 @@
<rule ref="category/java/design.xml/AvoidRethrowingException"/>
<rule ref="category/java/design.xml/AvoidThrowingNewInstanceOfSameException"/>
<rule ref="category/java/design.xml/AvoidUncheckedExceptionsInSignatures"/>
<rule ref="category/java/design.xml/CollapsibleIfStatements"/>
<rule ref="category/java/design.xml/CollapsibleIfStatements"
message="These nested if statements could be combined by &amp;&amp; operator."/>
<rule ref="category/java/design.xml/DoNotExtendJavaLangError"/>
<rule ref="category/java/design.xml/ExcessiveParameterList"/>
<rule ref="category/java/design.xml/ExcessivePublicCount"/>
Expand Down
2 changes: 2 additions & 0 deletions src/python/review/inspectors/pylint/issue_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# E errors, for probable bugs in the code

CODE_TO_ISSUE_TYPE: Dict[str, IssueType] = {
'C0200': IssueType.BEST_PRACTICES, # consider using enumerate
'C0415': IssueType.BEST_PRACTICES, # import-outside-toplevel
'W0101': IssueType.ERROR_PRONE, # unreachable code
'W0102': IssueType.ERROR_PRONE, # dangerous default value
'W0104': IssueType.ERROR_PRONE, # statement doesn't have any effect
Expand Down
2 changes: 2 additions & 0 deletions src/python/review/inspectors/pylint/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ disable=invalid-name,
no-else-raise,
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
Expand Down
20 changes: 0 additions & 20 deletions test/python/functional_tests/test_difficulty_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,6 @@ def _get_output_json(local_command: LocalCommandBuilder, file_path: str, history
'line_number': 10,
'text': 'continuation line under-indented for hanging indent',
},
{
'category': 'CODE_STYLE',
'code': 'WPS319',
'column_number': 21,
'difficulty': 'EASY',
'influence_on_penalty': {'EASY': 0, 'HARD': 0, 'MEDIUM': 0},
'line': '"Hello, World")',
'line_number': 10,
'text': 'Found bracket in wrong position',
},
],
}

Expand Down Expand Up @@ -394,16 +384,6 @@ def test_difficulty_levels(local_command: LocalCommandBuilder, file: str, expect
'line_number': 10,
'text': 'continuation line under-indented for hanging indent',
},
{
'category': 'CODE_STYLE',
'code': 'WPS319',
'column_number': 21,
'difficulty': 'EASY',
'influence_on_penalty': {'EASY': 0, 'MEDIUM': 0, 'HARD': 0},
'line': '"Hello, World")',
'line_number': 10,
'text': 'Found bracket in wrong position',
},
],
}

Expand Down
1 change: 1 addition & 0 deletions test/python/inspectors/test_checkstyle_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def test_output_parsing(file_name: str, expected_issues: List[CodeIssue]):
('test_indentation_with_spaces.java', 5),
('test_indentation_with_tabs.java', 5),
('test_indentation_google_style.java', 6),
('test_multiple_literals.java', 1),
]


Expand Down
Loading