diff --git a/vsg/rules/entity.py b/vsg/rules/entity.py index 88e42aa8..4b2d0884 100644 --- a/vsg/rules/entity.py +++ b/vsg/rules/entity.py @@ -426,3 +426,37 @@ class rule_017(entity_rule): def _fix_violations(self, oFile): self._fix_keyword_alignment(oFile) + +class rule_018(entity_rule): + ''' + Entity rule 018 ensures the alignment of comments in the entity. + ''' + + def __init__(self): + entity_rule.__init__(self) + self.identifier = '018' + self.solution = 'Inconsistent alignment of comments in entity.' + self.phase = 5 + + def analyze(self, oFile): + lGroup = [] + fGroupFound = False + iStartGroupIndex = None + for iLineNumber, oLine in enumerate(oFile.lines): + if not fGroupFound and oLine.insideEntity: + fGroupFound = True + iStartGroupIndex = iLineNumber + if oLine.isEndEntityDeclaration: + lGroup.append(oLine) + fGroupFound = False + self._check_keyword_alignment(iStartGroupIndex, '--', lGroup) + lGroup = [] + iStartGroupIndex = None + if fGroupFound: + if oLine.isPortDeclaration: + lGroup.append(oLine) + else: + lGroup.append(line.line('Removed line')) + + def _fix_violations(self, oFile): + self._fix_keyword_alignment(oFile) diff --git a/vsg/tests/entity/entity_test_input.vhd b/vsg/tests/entity/entity_test_input.vhd index cfe7b6d0..c762d079 100644 --- a/vsg/tests/entity/entity_test_input.vhd +++ b/vsg/tests/entity/entity_test_input.vhd @@ -18,17 +18,17 @@ end entity ENTITY1 entITy entiTY2 IS generic ( - G_GENERIC1 : std_logic :='0'; - G_generic2 : std_logic := '1' + G_GENERIC1 : std_logic :='0';-- Comment + G_generic2 : std_logic := '1' -- Comment ); PORt ( - i_port1 : in std_logic; - o_port2 : out std_logic; - io_port3 : inout std_logic; - PORT4 :in std_logic; - PORT5 : out std_logic; - PORT6 : inout std_logic ); + i_port1 : in std_logic; -- Comment + o_port2 : out std_logic; -- Comment + io_port3 : inout std_logic; -- Comment + PORT4 :in std_logic; -- Comment + PORT5 : out std_logic;--Comment + PORT6 : inout std_logic );--Comment end entity entiTY2 eNTITY entiTY3 is diff --git a/vsg/tests/entity/test_fix_rule_entity.py b/vsg/tests/entity/test_fix_rule_entity.py index b85b99c7..ca11bb55 100644 --- a/vsg/tests/entity/test_fix_rule_entity.py +++ b/vsg/tests/entity/test_fix_rule_entity.py @@ -115,3 +115,9 @@ class testFixRuleEntityMethods(unittest.TestCase): oRule.fix(oFile) oRule.analyze(oFile) self.assertEqual(oRule.violations, []) + + def test_fix_rule_018(self): + oRule = entity.rule_018() + oRule.fix(oFile) + oRule.analyze(oFile) + self.assertEqual(oRule.violations, []) diff --git a/vsg/tests/entity/test_rule_entity.py b/vsg/tests/entity/test_rule_entity.py index 164aa30b..cc6624e5 100644 --- a/vsg/tests/entity/test_rule_entity.py +++ b/vsg/tests/entity/test_rule_entity.py @@ -181,3 +181,13 @@ class testRuleEntityMethods(unittest.TestCase): dExpected = ['8-15','25-31','39-46','56-62','70-77','86-90','98-102','118-122','128-132'] oRule.analyze(oFile) self.assertEqual(oRule.violations, dExpected) + + def test_rule_018(self): + oRule = entity.rule_018() + self.assertTrue(oRule) + self.assertEqual(oRule.name, 'entity') + self.assertEqual(oRule.identifier, '018') + + dExpected = ['19-33'] + oRule.analyze(oFile) + self.assertEqual(oRule.violations, dExpected)