Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DartLintBear: check settings validity #950

Merged
merged 1 commit into from
Oct 30, 2016
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
13 changes: 12 additions & 1 deletion bears/dart/DartLintBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@ class DartLintBear:
CAN_DETECT = {'Syntax', 'Formatting'}

@staticmethod
def create_arguments(filename, file, config_file):
def create_arguments(
filename, file, config_file,
use_spaces: bool=True, indent_size: int=2):

# use_spaces must be True and indent_size must be 2 because
# dartanalyzer only supports these settings
# see https://github.com/dart-lang/dart_style/issues/261
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for putting the link here ! Really appreciated :)

if (indent_size != 2 or not use_spaces):
raise ValueError(
"DartLintBear only supports `use_spaces=True` "
"and `indent_size=2`"
)
return filename,
27 changes: 26 additions & 1 deletion tests/dart/DartLintBearTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from queue import Queue

from bears.dart.DartLintBear import DartLintBear
from tests.LocalBearTestHelper import verify_local_bear
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting
from tests.LocalBearTestHelper import verify_local_bear, LocalBearTestHelper
from tests.BearTestHelper import generate_skip_decorator


good_file = """
Expand Down Expand Up @@ -30,3 +35,23 @@
valid_files=(good_file,),
invalid_files=(bad_file,),
tempfile_kwargs={"suffix": ".dart"})


@generate_skip_decorator(DartLintBear)
class DartLintBearConfigTest(LocalBearTestHelper):

def test_config_failure_use_spaces(self):
section = Section("name")
section.append(Setting('use_spaces', False))
bear = DartLintBear(section, Queue())

with self.assertRaises(AssertionError):
self.check_validity(bear, [], good_file)

def test_config_failure_wrong_indent_size(self):
section = Section("name")
section.append(Setting('indent_size', 3))
bear = DartLintBear(section, Queue())

with self.assertRaises(AssertionError):
self.check_validity(bear, [], good_file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this tests are actually nice work :)