From eb31465fb50a670d443d528f6cb34d7a4802fcbd Mon Sep 17 00:00:00 2001 From: Jeremiah Leary Date: Thu, 17 Dec 2020 11:51:16 -0600 Subject: [PATCH] Updates for issue #491: Adding allow_library_clause option to rule library_003 to allow consecutive library clauses. 1) Added tests 2) Added option allow_library_clause to rule library_003 3) Updated documentation --- docs/library_rules.rst | 12 ++++++ ...ank_line_above_line_starting_with_token.py | 4 ++ vsg/rules/library/rule_003.py | 7 ++++ ..._test_input.fixed_allow_library_clause.vhd | 9 +++++ ... => rule_003_test_input.fixed_default.vhd} | 0 vsg/tests/library/test_rule_003.py | 38 +++++++++++++++++-- 6 files changed, 66 insertions(+), 4 deletions(-) create mode 100644 vsg/tests/library/rule_003_test_input.fixed_allow_library_clause.vhd rename vsg/tests/library/{rule_003_test_input.fixed.vhd => rule_003_test_input.fixed_default.vhd} (100%) diff --git a/docs/library_rules.rst b/docs/library_rules.rst index bb404637..d4564c1d 100644 --- a/docs/library_rules.rst +++ b/docs/library_rules.rst @@ -46,11 +46,21 @@ This rule checks for a blank line above the **library** keyword. Refer to the section `Configuring Blank Lines `_ for options regarding comments. +There is an additional **allow_library_clause** option which can be set. +Refer to section `Reporting Single Rule Configuration `_ for details on finding configuration options for individual rules. + +allow_library_clause +^^^^^^^^^^^^^^^^^^^^ + +When set to **True**, it allows consecutive library clauses. + **Violation** .. code-block:: vhdl library ieee; + use ieee.std_logic_1164.all; + library top_dsn; library fifo_dsn; **Fix** @@ -58,7 +68,9 @@ Refer to the section `Configuring Blank Lines `_ f .. code-block:: vhdl library ieee; + use ieee.std_logic_1164.all; + library top_dsn; library fifo_dsn; library_004 diff --git a/vsg/rules/blank_line_above_line_starting_with_token.py b/vsg/rules/blank_line_above_line_starting_with_token.py index c29e14e2..eb98aaf6 100644 --- a/vsg/rules/blank_line_above_line_starting_with_token.py +++ b/vsg/rules/blank_line_above_line_starting_with_token.py @@ -37,7 +37,11 @@ class blank_line_above_line_starting_with_token(rule.Rule): else: return oFile.get_line_above_line_starting_with_token_with_hierarchy(self.lTokens, self.lHierarchyLimits) + def _set_allow_tokens(self): + return + def _analyze(self, lToi): + self._set_allow_tokens() for oToi in lToi: lTokens = oToi.get_tokens() bSkip = False diff --git a/vsg/rules/library/rule_003.py b/vsg/rules/library/rule_003.py index 41ce87ca..b0e39fea 100644 --- a/vsg/rules/library/rule_003.py +++ b/vsg/rules/library/rule_003.py @@ -14,3 +14,10 @@ class rule_003(blank_line_above_line_starting_with_token): def __init__(self): blank_line_above_line_starting_with_token.__init__(self, 'library', '003', lTokens) + self.allow_library_clause = False + self.configuration.append('allow_library_clause') + + def _set_allow_tokens(self): + if self.allow_library_clause: + self.lAllowTokens = [] + self.lAllowTokens.append(token.library_clause.keyword) diff --git a/vsg/tests/library/rule_003_test_input.fixed_allow_library_clause.vhd b/vsg/tests/library/rule_003_test_input.fixed_allow_library_clause.vhd new file mode 100644 index 00000000..c0165e80 --- /dev/null +++ b/vsg/tests/library/rule_003_test_input.fixed_allow_library_clause.vhd @@ -0,0 +1,9 @@ + +library ieee; +library ieee; +-- Some comment + +library ieee; +library ieee; +library ieee; + diff --git a/vsg/tests/library/rule_003_test_input.fixed.vhd b/vsg/tests/library/rule_003_test_input.fixed_default.vhd similarity index 100% rename from vsg/tests/library/rule_003_test_input.fixed.vhd rename to vsg/tests/library/rule_003_test_input.fixed_default.vhd diff --git a/vsg/tests/library/test_rule_003.py b/vsg/tests/library/test_rule_003.py index d22ad666..3d2c0bd8 100644 --- a/vsg/tests/library/test_rule_003.py +++ b/vsg/tests/library/test_rule_003.py @@ -10,9 +10,13 @@ sTestDir = os.path.dirname(__file__) lFile = utils.read_vhdlfile(os.path.join(sTestDir,'rule_003_test_input.vhd')) -lExpected = [] -lExpected.append('') -utils.read_file(os.path.join(sTestDir, 'rule_003_test_input.fixed.vhd'), lExpected) +lExpected_default = [] +lExpected_default.append('') +utils.read_file(os.path.join(sTestDir, 'rule_003_test_input.fixed_default.vhd'), lExpected_default) + +lExpected_allow_library_clause = [] +lExpected_allow_library_clause.append('') +utils.read_file(os.path.join(sTestDir, 'rule_003_test_input.fixed_allow_library_clause.vhd'), lExpected_allow_library_clause) class test_library_rule(unittest.TestCase): @@ -23,6 +27,7 @@ class test_library_rule(unittest.TestCase): def test_rule_003(self): oRule = library.rule_003() oRule.allow_comments = True + oRule.allow_library_clause = False self.assertTrue(oRule) self.assertEqual(oRule.name, 'library') self.assertEqual(oRule.identifier, '003') @@ -35,12 +40,37 @@ class test_library_rule(unittest.TestCase): def test_fix_rule_003(self): oRule = library.rule_003() oRule.allow_comments = True + oRule.allow_library_clause = False oRule.fix(self.oFile) lActual = self.oFile.get_lines() - self.assertEqual(lExpected, lActual) + self.assertEqual(lExpected_default, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_rule_003_w_allow_library_clause(self): + oRule = library.rule_003() + oRule.allow_comments = False + oRule.allow_library_clause = True + + lExpected = [5] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_003_w_allow_library_clause(self): + oRule = library.rule_003() + oRule.allow_comments = False + oRule.allow_library_clause = True + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_allow_library_clause, lActual) oRule.analyze(self.oFile) self.assertEqual(oRule.violations, [])