Skip to content

Commit 26899b9

Browse files
authored
Make linter setting configurable (#16)
1 parent 8db9106 commit 26899b9

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

homework_checker/core/schema_manager.py

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def __init__(self: SchemaManager, file_name: Path):
4242
Optional(Tags.TIMEOUT_TAG, default=60): float,
4343
}
4444

45+
style_check_schema = {
46+
Tags.NAME_TAG: str,
47+
}
48+
4549
task_schema = {
4650
Tags.NAME_TAG: str,
4751
Tags.LANGUAGE_TAG: Or(LangTags.CPP, LangTags.BASH),
@@ -57,6 +61,7 @@ def __init__(self: SchemaManager, file_name: Path):
5761
BuildTags.CMAKE, BuildTags.SIMPLE
5862
),
5963
Optional(Tags.BUILD_TIMEOUT_TAG, default=60): float,
64+
Optional(Tags.STYLE_CHECKERS_TAG): [style_check_schema],
6065
Optional(Tags.TESTS_TAG): [test_schema],
6166
}
6267

homework_checker/core/schema_tags.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class Tags:
2323
OUTPUT_PIPE_TAG = "output_pipe_args"
2424
OUTPUT_TYPE_TAG = "output_type"
2525
RUN_GTESTS_TAG = "run_google_tests"
26+
STYLE_CHECKERS_TAG = "style_checkers"
2627
TASKS_TAG = "tasks"
2728
TESTS_TAG = "tests"
2829
TIMEOUT_TAG = "timeout"

homework_checker/core/tasks.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ def __init__(
7676
self._binary_name = task_node[Tags.BINARY_NAME_TAG]
7777
self._build_timeout = task_node[Tags.BUILD_TIMEOUT_TAG]
7878

79+
self._style_checkers = []
80+
if Tags.STYLE_CHECKERS_TAG in task_node:
81+
self._style_checkers = task_node[Tags.STYLE_CHECKERS_TAG]
82+
7983
self._test_nodes = []
8084
if Tags.TESTS_TAG in task_node:
8185
self._test_nodes = task_node[Tags.TESTS_TAG]
@@ -137,9 +141,16 @@ def run_all_tests(
137141
run_all_tests(test_node=test_node, executable_folder=build_folder)
138142
)
139143

140-
style_errors = self._code_style_errors()
141-
if style_errors:
142-
results[STYLE_ERROR_TAG] = style_errors
144+
if self._style_checkers:
145+
for checker in self._style_checkers:
146+
checker_name = checker[Tags.NAME_TAG]
147+
style_errors = self._code_style_errors(checker_name)
148+
if style_errors:
149+
results[
150+
"{tag} {checker}".format(
151+
tag=STYLE_ERROR_TAG, checker=checker_name
152+
)
153+
] = style_errors
143154
return results
144155

145156
def __get_folders_to_inject(
@@ -177,7 +188,7 @@ def _build_if_needed(self: Task, code_folder: Path):
177188
return None, code_folder
178189

179190
@abc.abstractmethod
180-
def _code_style_errors(self: Task):
191+
def _code_style_errors(self: Task, checker_name: str):
181192
return None
182193

183194

@@ -219,8 +230,12 @@ def _build_if_needed(
219230
code_folder,
220231
)
221232

222-
def _code_style_errors(self: CppTask) -> Optional[tools.CmdResult]:
233+
def _code_style_errors(
234+
self: CppTask, checker_name: str
235+
) -> Optional[tools.CmdResult]:
223236
"""Check if code conforms to Google Style."""
237+
if checker_name != "cpplint":
238+
return None
224239
command = (
225240
"cpplint --counting=detailed "
226241
+ "--filter=-legal,-readability/todo,"
@@ -298,7 +313,7 @@ def __init__(self: BashTask, task_node: dict, root_folder: Path, job_file: Path)
298313
def _build_if_needed(self: BashTask, code_folder: Path):
299314
return None, code_folder # There is nothing to build in Bash.
300315

301-
def _code_style_errors(self: BashTask):
316+
def _code_style_errors(self: BashTask, checker_name: str):
302317
return None
303318

304319
def _run_test(

schema/schema.yml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ homeworks:
1313
~[optional]~ compiler_flags: String value
1414
~[optional]~ build_type: Any of ['cmake', 'simple']
1515
~[optional]~ output_type: Any of ['string', 'number']
16+
~[optional]~ style_checkers:
17+
- name: String value
1618
~[optional]~ tests:
1719
- name: String value
1820
~[optional]~ expected_output: Any of ['String value', 'Float value', 'Int value']

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from setuptools import find_packages
77
from setuptools.command.install import install
88

9-
VERSION_STRING = "1.0.4"
9+
VERSION_STRING = "1.1.0"
1010

1111
PACKAGE_NAME = "homework_checker"
1212

0 commit comments

Comments
 (0)