Updates for issue #180

Adding rule component_020:

  1)  Added test for comment alignment in component declarations
  2)  Added rule to detect and fix alignment of comments
  3)  Added documentation
This commit is contained in:
Jeremiah C Leary 2018-11-26 20:36:30 -06:00
parent 1796569713
commit d6470d0911
5 changed files with 91 additions and 0 deletions

View File

@ -381,3 +381,23 @@ Refer to the entity for port types, port directions and purpose.
WR_EN : in std_logic;
RD_EN : out std_logic;
component_020
#############
This rule checks the comments at the end of the port and generic assignments in component declarations are aligned.
This rule is useful if component_019 is disabled.
**Violation**
.. code-block:: vhdl
WR_EN : in std_logic; -- Enables write to RAM
RD_EN : out std_logic; -- Enable reads from RAM
**Fix**
.. code-block:: vhdl
WR_EN : in std_logic; -- Enables write to RAM
RD_EN : out std_logic; -- Enable reads from RAM

View File

@ -18,3 +18,4 @@ from .rule_016 import rule_016
from .rule_017 import rule_017
from .rule_018 import rule_018
from .rule_019 import rule_019
from .rule_020 import rule_020

View File

@ -0,0 +1,49 @@
from vsg import rule
from vsg import check
from vsg import fix
from vsg import line
class rule_020(rule.rule):
'''
Entity rule 020 ensures the alignment of comments in a component declaration.
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'component'
self.identifier = '020'
self.solution = 'Inconsistent alignment of comments in component instantiation.'
self.phase = 6
def analyze(self, oFile):
lGroup = []
fGroupFound = False
iStartGroupIndex = None
for iLineNumber, oLine in enumerate(oFile.lines):
fGroupFound, iStartGroupIndex = search_for_group(fGroupFound, oLine, iStartGroupIndex, iLineNumber)
if oLine.isComponentEnd:
lGroup.append(oLine)
fGroupFound = False
check.keyword_alignment(self, iStartGroupIndex, '--', lGroup)
lGroup = []
iStartGroupIndex = None
store_lines_for_group(fGroupFound, oLine, lGroup)
def _fix_violations(self, oFile):
fix.keyword_alignment(self, oFile)
def search_for_group(fGroupFound, oLine, iStartGroupIndex, iLineNumber):
if not fGroupFound and oLine.insideComponent:
return True, iLineNumber
return fGroupFound, iStartGroupIndex
def store_lines_for_group(fGroupFound, oLine, lGroup):
if fGroupFound:
if oLine.hasComment and not oLine.isComment:
lGroup.append(oLine)
else:
lGroup.append(line.line('Removed line'))

View File

@ -128,3 +128,13 @@ class testFixRuleComponentMethods(unittest.TestCase):
self.assertEqual(oFileComment.lines[12].line, ' port_2 : in std_logic;')
self.assertEqual(oFileComment.lines[14].line, ' port_4 : out std_logic;')
def test_fix_rule_020(self):
oRule = component.rule_020()
oFileComment = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'component_comment_test_input.vhd'))
oRule.fix(oFileComment)
oRule.analyze(oFileComment)
self.assertEqual(oRule.violations, [])
self.assertEqual(oFileComment.lines[7].line, ' generic_1 : std_logic := \'0\'; -- This should be removed')
self.assertEqual(oFileComment.lines[12].line, ' port_2 : in std_logic; -- This should be removed')
self.assertEqual(oFileComment.lines[14].line, ' port_4 : out std_logic; -- This should be removed')

View File

@ -200,3 +200,14 @@ class testRuleComponentMethods(unittest.TestCase):
dExpected = [7,12,14]
oRule.analyze(oFileComment)
self.assertEqual(oRule.violations, dExpected)
def test_rule_020(self):
oRule = component.rule_020()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'component')
self.assertEqual(oRule.identifier, '020')
dExpected = ['5-16']
oFileComment = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'component_comment_test_input.vhd'))
oRule.analyze(oFileComment)
self.assertEqual(oRule.violations, dExpected)