Skip to content

Commit 4983c39

Browse files
committed
DartLintBear: Check settings validity
As pointed out here dart-lang/dart_style#261, dartanalyzer only supports indentation using 2 spaces. This commit changes DartLintBear to check that ``use_spaces`` is True and ``indent_size`` is 2 and raises a ``ValueError`` if not. Fixes coala#897
1 parent a8b530d commit 4983c39

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

bears/dart/DartLintBear.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,16 @@ class DartLintBear:
1919
CAN_DETECT = {'Syntax', 'Formatting'}
2020

2121
@staticmethod
22-
def create_arguments(filename, file, config_file):
22+
def create_arguments(
23+
filename, file, config_file,
24+
use_spaces: bool=True, indent_size: int=2):
25+
26+
# use_spaces must be True and indent_size must be 2 because
27+
# dartanalyzer only supports these settings
28+
# see https://github.com/dart-lang/dart_style/issues/261
29+
if (indent_size != 2 or not use_spaces):
30+
raise ValueError(
31+
"DartLintBear only supports `use_spaces=True` "
32+
"and `indent_size=2`"
33+
)
2334
return filename,

tests/dart/DartLintBearTest.py

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
from queue import Queue
2+
13
from bears.dart.DartLintBear import DartLintBear
2-
from tests.LocalBearTestHelper import verify_local_bear
4+
from coalib.settings.Section import Section
5+
from coalib.settings.Setting import Setting
6+
from tests.LocalBearTestHelper import verify_local_bear, LocalBearTestHelper
7+
from tests.BearTestHelper import generate_skip_decorator
38

49

510
good_file = """
@@ -30,3 +35,23 @@
3035
valid_files=(good_file,),
3136
invalid_files=(bad_file,),
3237
tempfile_kwargs={"suffix": ".dart"})
38+
39+
40+
@generate_skip_decorator(DartLintBear)
41+
class DartLintBearConfigTest(LocalBearTestHelper):
42+
43+
def test_config_failure_use_spaces(self):
44+
section = Section("name")
45+
section.append(Setting('use_spaces', False))
46+
bear = DartLintBear(section, Queue())
47+
48+
with self.assertRaises(AssertionError):
49+
self.check_validity(bear, [], good_file)
50+
51+
def test_config_failure_wrong_indent_size(self):
52+
section = Section("name")
53+
section.append(Setting('indent_size', 3))
54+
bear = DartLintBear(section, Queue())
55+
56+
with self.assertRaises(AssertionError):
57+
self.check_validity(bear, [], good_file)

0 commit comments

Comments
 (0)