From d44e801e8d95c68ce4dcc575cd650820e4d052fd Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Thu, 18 Feb 2021 07:01:21 -0600 Subject: [PATCH] Updates for issue #450: Changing ignore and ignore_positional options to lowercase. 1) Updated documentation 2) Updated tests 3) Updated code --- .../configuring_multiline_structure_rules.rst | 34 ++- vsg/rules/constant/rule_016.py | 18 +- vsg/tests/constant/test_rule_016.py | 222 +++++++++--------- 3 files changed, 144 insertions(+), 130 deletions(-) diff --git a/docs/configuring_multiline_structure_rules.rst b/docs/configuring_multiline_structure_rules.rst index d4a6c5c3..bcf83b3e 100644 --- a/docs/configuring_multiline_structure_rules.rst +++ b/docs/configuring_multiline_structure_rules.rst @@ -12,34 +12,48 @@ There are several options to these rules: +----------------------+---------+---------+---------------------------------------------------------+ | Method | Type | Default | Description | +======================+=========+=========+=========================================================+ -| first_paren_new_line | boolean | False | First opening parenthesis on it's own line. | +| first_paren_new_line | boolean | false | First opening parenthesis on it's own line. | +----------------------+---------+---------+---------------------------------------------------------+ -| last_paren_new_line | boolean | False | Last closing parenthesis on it's own line. | +| last_paren_new_line | boolean | false | Last closing parenthesis on it's own line. | +----------------------+---------+---------+---------------------------------------------------------+ -| open_paren_new_line | boolean | False | Insert new line after open parenthesis. | +| open_paren_new_line | boolean | false | Insert new line after open parenthesis. | +----------------------+---------+---------+---------------------------------------------------------+ -| close_paren_new_line | boolean | False | Insert new line before close parenthesis. | +| close_paren_new_line | boolean | false | Insert new line before close parenthesis. | +----------------------+---------+---------+---------------------------------------------------------+ -| new_line_after_comma | boolean | False | Insert new line after the commas. | +| new_line_after_comma | boolean | false | Insert new line after the commas. | +----------------------+---------+---------+---------------------------------------------------------+ -| ignore_single_line | boolean | True | Do not apply rules if expression/condition is contained | +| ignore_single_line | boolean | true | Do not apply rules if expression/condition is contained | | | | | on a single line. | +----------------------+-----------------------------------------------------------------------------+ The options can be combined to format the output. -Each option allows one of three values: True, False and Ignore. +Each option except :code:`new_line_after_comma` allows one of three values: true, false and ignore. +----------------------+---------------------------------------------------------+ | Option Value | Action | +======================+=========================================================+ -| True | Option will be enforced. | +| true | Option will be enforced. | +----------------------+---------------------------------------------------------+ -| False | The inverse of the Option will be enforced. | +| false | The inverse of the Option will be enforced. | +----------------------+---------------------------------------------------------+ -| Ignore | The option will be ignored. | +| ignore | The option will be ignored. | +----------------------+---------------------------------------------------------+ +The :code:`new_line_after_comma` option allows one of four values: true, false, ignore and ignore_positional. + ++----------------------+--------------------------------------------------------------+ +| Option Value | Action | ++======================+==============================================================+ +| true | Insert new line after commas. | ++----------------------+--------------------------------------------------------------+ +| false | Remove new line after commas. | ++----------------------+--------------------------------------------------------------+ +| ignore | Ignore commas. | ++----------------------+--------------------------------------------------------------+ +| ignore_positional | Insert new line after commas unless elements are positional. | ++----------------------+--------------------------------------------------------------+ + This is an example of how to configure these options. .. code-block:: yaml diff --git a/vsg/rules/constant/rule_016.py b/vsg/rules/constant/rule_016.py index 52cae9eb..9bc308f4 100644 --- a/vsg/rules/constant/rule_016.py +++ b/vsg/rules/constant/rule_016.py @@ -43,7 +43,7 @@ class rule_016(rule.Rule): self.configuration.append('open_paren_new_line') self.close_paren_new_line = False self.configuration.append('close_paren_new_line') - self.new_line_after_comma = 'Remove' + self.new_line_after_comma = False self.configuration.append('new_line_after_comma') self.ignore_single_line = True self.configuration.append('ignore_single_line') @@ -87,7 +87,7 @@ class rule_016(rule.Rule): def _check_first_paren_new_line(self, oToi): - if self.first_paren_new_line == 'Ignore': + if self.first_paren_new_line == 'ignore': return iLine, lTokens = utils.get_toi_parameters(oToi) @@ -113,7 +113,7 @@ def _check_first_paren_new_line(self, oToi): def _check_last_paren_new_line(self, oToi): # print('-->_check_last_paren_new_line') - if self.last_paren_new_line == 'Ignore': + if self.last_paren_new_line == 'ignore': return iLine, lTokens = utils.get_toi_parameters(oToi) bSearch = False @@ -147,7 +147,7 @@ def _check_last_paren_new_line(self, oToi): def _check_open_paren_new_line(self, oToi): # print('-->_check_open_paren_new_line') - if self.open_paren_new_line == 'Ignore': + if self.open_paren_new_line == 'ignore': return iLine, lTokens = utils.get_toi_parameters(oToi) @@ -216,7 +216,7 @@ def _check_open_paren_new_line(self, oToi): def _check_close_paren_new_line(self, oToi): # print('-->_check_close_paren_new_line') - if self.close_paren_new_line == 'Ignore': + if self.close_paren_new_line == 'ignore': return iLine, lTokens = utils.get_toi_parameters(oToi) @@ -307,7 +307,7 @@ def _check_close_paren_new_line(self, oToi): def _check_new_line_after_comma(self, oToi): # print('-->_check_new_line_after_comma') - if self.new_line_after_comma == 'Ignore_all': + if self.new_line_after_comma == 'ignore_all': return iLine, lTokens = utils.get_toi_parameters(oToi) @@ -375,18 +375,18 @@ def _check_new_line_after_comma(self, oToi): continue if isinstance(oToken, parser.comma): - if bPositionalFound and self.new_line_after_comma == 'Ignore_positional': + if bPositionalFound and self.new_line_after_comma == 'ignore_positional': continue bPositionalFound = True if utils.is_token_at_end_of_line(iToken, lTokens): - if self.new_line_after_comma == 'Remove': + if not self.new_line_after_comma: iEnd = utils.find_next_non_whitespace_token(iToken + 1, lTokens) sSolution = 'Remove carriage return after comma.' oViolation = _create_violation(oToi, iLine, iToken, iEnd, 'new_line_after_comma', 'remove', sSolution) self.add_violation(oViolation) else: - if self.new_line_after_comma == 'Add' or self.new_line_after_comma == 'Ignore_positional': + if self.new_line_after_comma or self.new_line_after_comma == 'ignore_positional': sSolution = 'Add carriage return after comma.' oViolation = _create_violation(oToi, iLine, iToken, iToken + 1, 'new_line_after_comma', 'insert', sSolution) self.add_violation(oViolation) diff --git a/vsg/tests/constant/test_rule_016.py b/vsg/tests/constant/test_rule_016.py index 40069b7e..d4543796 100644 --- a/vsg/tests/constant/test_rule_016.py +++ b/vsg/tests/constant/test_rule_016.py @@ -83,11 +83,11 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_first_paren_new_line_true(self): oRule = constant.rule_016() oRule.first_paren_new_line = True - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' self.assertTrue(oRule) self.assertEqual(oRule.name, 'constant') @@ -101,11 +101,11 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_first_paren_new_line_false(self): oRule = constant.rule_016() oRule.first_paren_new_line = False - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' lExpected = [14, 17, 21, 27, 41, 57] @@ -114,12 +114,12 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_last_paren_new_line_true(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' oRule.last_paren_new_line = True - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' lExpected = [11, 14] @@ -128,12 +128,12 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_last_paren_new_line_false(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' oRule.last_paren_new_line = False - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' lExpected = [18, 24, 38, 54, 72] @@ -142,12 +142,12 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_open_paren_new_line_true(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' oRule.open_paren_new_line = True - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' lExpected = [11, 11, 14, 14, 14, 17, 17, 17, 22, 23, 28, 33] @@ -156,12 +156,12 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_open_paren_new_line_false(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' oRule.open_paren_new_line = False - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' lExpected = [10, 21, 27, 41, 42, 48, 57, 58, 65] @@ -170,12 +170,12 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_close_paren_new_line_true(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' oRule.close_paren_new_line = True - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' lExpected = [11, 11, 14, 14, 17, 17, 22, 23, 32, 37, 47, 53] @@ -184,12 +184,12 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_close_paren_new_line_false(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' oRule.close_paren_new_line = False - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' lExpected = [64, 71] @@ -198,12 +198,12 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_new_line_after_comma_true(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Add' - oRule.align_left = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = True + oRule.align_left = 'ignore' lExpected = [] lExpected.extend([11, 11, 11, 11, 11, 11, 11, 11, 11]) @@ -217,12 +217,12 @@ class test_constant_rule(unittest.TestCase): def test_rule_016_new_line_after_comma_false(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Remove' - oRule.align_left = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = False + oRule.align_left = 'ignore' lExpected = [22] lExpected.extend(range(28, 37)) @@ -238,11 +238,11 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_first_paren_new_line_true(self): oRule = constant.rule_016() oRule.first_paren_new_line = True - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -256,11 +256,11 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_first_paren_new_line_false(self): oRule = constant.rule_016() oRule.first_paren_new_line = False - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -273,12 +273,12 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_last_paren_new_line_true(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' oRule.last_paren_new_line = True - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -291,12 +291,12 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_last_paren_new_line_false(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' oRule.last_paren_new_line = False - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -309,12 +309,12 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_open_paren_new_line_true(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' oRule.open_paren_new_line = True - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -327,12 +327,12 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_open_paren_new_line_false(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' oRule.open_paren_new_line = False - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -345,12 +345,12 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_close_paren_new_line_true(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' oRule.close_paren_new_line = True - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -363,12 +363,12 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_close_paren_new_line_false(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' oRule.close_paren_new_line = False - oRule.new_line_after_comma = 'Ignore_all' - oRule.align_left = 'Ignore' + oRule.new_line_after_comma = 'ignore_all' + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -381,12 +381,12 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_new_line_after_comma_true(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma ='Add' - oRule.align_left = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma =True + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -399,12 +399,12 @@ class test_constant_rule(unittest.TestCase): def test_fix_rule_016_new_line_after_comma_false(self): oRule = constant.rule_016() - oRule.first_paren_new_line = 'Ignore' - oRule.last_paren_new_line = 'Ignore' - oRule.open_paren_new_line = 'Ignore' - oRule.close_paren_new_line = 'Ignore' - oRule.new_line_after_comma = 'Remove' - oRule.align_left = 'Ignore' + oRule.first_paren_new_line = 'ignore' + oRule.last_paren_new_line = 'ignore' + oRule.open_paren_new_line = 'ignore' + oRule.close_paren_new_line = 'ignore' + oRule.new_line_after_comma = False + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -422,8 +422,8 @@ class test_constant_rule(unittest.TestCase): oRule.last_paren_new_line = True oRule.open_paren_new_line = True oRule.close_paren_new_line = True - oRule.new_line_after_comma = 'Add' - oRule.align_left = 'Ignore' + oRule.new_line_after_comma = True + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -441,8 +441,8 @@ class test_constant_rule(unittest.TestCase): oRule.last_paren_new_line = False oRule.open_paren_new_line = False oRule.close_paren_new_line = False - oRule.new_line_after_comma = 'Remove' - oRule.align_left = 'Ignore' + oRule.new_line_after_comma = False + oRule.align_left = 'ignore' oRule.fix(self.oFile) @@ -460,7 +460,7 @@ class test_constant_rule(unittest.TestCase): oRule.last_paren_new_line = True oRule.open_paren_new_line = True oRule.close_paren_new_line = True - oRule.new_line_after_comma = 'Add' + oRule.new_line_after_comma = True oFileOthers = vhdlFile.vhdlFile(lFileOthers) oRule.fix(oFileOthers) @@ -479,7 +479,7 @@ class test_constant_rule(unittest.TestCase): oRule.last_paren_new_line = True oRule.open_paren_new_line = True oRule.close_paren_new_line = True - oRule.new_line_after_comma = 'Add' + oRule.new_line_after_comma = True oFileAssignment = vhdlFile.vhdlFile(lFileAssignment) oRule.fix(oFileAssignment) @@ -498,7 +498,7 @@ class test_constant_rule(unittest.TestCase): oRule.last_paren_new_line = True oRule.open_paren_new_line = True oRule.close_paren_new_line = True - oRule.new_line_after_comma = 'Ignore_positional' + oRule.new_line_after_comma = 'ignore_positional' oFilePositional = vhdlFile.vhdlFile(lFilePositional) oRule.fix(oFilePositional)