Skip to content

Commit be4f343

Browse files
committed
CheckstyleBear.py: Add configuration check
Add invalid_config function to CheckstyleBear.py Add tests to invalid configurations Closes coala#898
1 parent 4df9c20 commit be4f343

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

TestFile.py

Whitespace-only changes.

bears/java/CheckstyleBear.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"geosoft": "http://geosoft.no/development/geosoft_checks.xml"}
1111

1212

13+
def invalid_configuration(checkstyle_configs, use_spaces, indent_size):
14+
return (checkstyle_configs == 'google' and
15+
(not use_spaces or indent_size != 2))
16+
17+
1318
def known_checkstyle_or_path(setting):
1419
if str(setting) in known_checkstyles.keys():
1520
return str(setting)
@@ -44,7 +49,8 @@ def setup_dependencies(self):
4449

4550
def create_arguments(
4651
self, filename, file, config_file,
47-
checkstyle_configs: known_checkstyle_or_path="google"):
52+
checkstyle_configs: known_checkstyle_or_path="google",
53+
use_spaces: bool=True, indent_size: int = 2):
4854
"""
4955
:param checkstyle_configs:
5056
A file containing configs to use in ``checkstyle``. It can also
@@ -64,6 +70,9 @@ def create_arguments(
6470
- geosoft - The Java style followed by GeoSoft. More info at
6571
<http://geosoft.no/development/javastyle.html>
6672
"""
73+
if invalid_configuration(checkstyle_configs, use_spaces, indent_size):
74+
raise ValueError('Invalid configuration! Cannot proceed.')
75+
6776
if checkstyle_configs in known_checkstyles:
6877
checkstyle_configs = self.download_cached_file(
6978
known_checkstyles[checkstyle_configs],

tests/java/CheckstyleBearTest.py

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ def test_known_configs(self):
3030
self.section["checkstyle_configs"] = "google"
3131
self.check_validity(self.uut, [], self.good_file)
3232

33+
def test_config_failure_use_spaces(self):
34+
self.section["checkstyle_configs"] = "google"
35+
self.section.append(Setting('use_spaces', False))
36+
with self.assertRaises(AssertionError):
37+
self.check_validity(self.uut, [], self.good_file)
38+
39+
def test_config_failure_indent_size(self):
40+
self.section["checkstyle_configs"] = "google"
41+
self.section.append(Setting('indent_size', 3))
42+
with self.assertRaises(AssertionError):
43+
self.check_validity(self.uut, [], self.good_file)
44+
3345
def test_with_custom_configfile(self):
3446
self.section["checkstyle_configs"] = self.empty_config
3547
self.check_validity(self.uut, [], self.good_file)

0 commit comments

Comments
 (0)