Skip to content

Commit

Permalink
HappinessLintBear: Throw exception when use_spaces
Browse files Browse the repository at this point in the history
Throw error if use_space is true as tabbed
identation is to be used.

Closes coala#1754
  • Loading branch information
newbazz committed Dec 5, 2017
1 parent 1a7c514 commit bdbc81e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bears/js/HappinessLintBear.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class HappinessLintBear:
ASCIINEMA_URL = 'https://asciinema.org/a/80714'
CAN_DETECT = {'Syntax'}

@staticmethod
def create_arguments(filename, file, config_file):
@classmethod
def create_arguments(cls, filename, file, config_file,
use_spaces: bool=False):
if use_spaces:
raise ValueError(
'"use_spaces=True" is incompatible with {}, '
'set it to false.'.format(cls.name)
)

return filename,
22 changes: 22 additions & 0 deletions tests/js/HappinessLintBearTest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import re
from queue import Queue

from bears.js.HappinessLintBear import HappinessLintBear
from coalib.testing.LocalBearTestHelper import verify_local_bear
from coalib.settings.Section import Section
from coalib.settings.Setting import Setting
from coalib.testing.LocalBearTestHelper import LocalBearTestHelper
from coalib.testing.BearTestHelper import generate_skip_decorator


good_file = """
Expand All @@ -17,3 +24,18 @@
HappinessLintBearTest = verify_local_bear(HappinessLintBear,
valid_files=(good_file,),
invalid_files=(bad_file,))


@generate_skip_decorator(HappinessLintBear)
class HappinessLintBearConfigTest(LocalBearTestHelper):

USE_SPACE_ERR_MSG = re.escape('"use_spaces=True" is incompatible with '
'HappinessLintBear, set it to false.')

def test_validate_use_spaces(self):
section = Section('name')
section.append(Setting('use_spaces', True))
bear = HappinessLintBear(section, Queue())

with self.assertRaisesRegex(ValueError, self.USE_SPACE_ERR_MSG):
bear.run(bad_file, use_spaces=True)

0 comments on commit bdbc81e

Please sign in to comment.