1) Comments after "when" statement are indented one level from "when" 2) Comments in entities are indented at the same level as ports
This commit is contained in:
parent
8d58d5c50d
commit
4e3ffd895a
|
|
@ -24,32 +24,11 @@ class rule_001(comment_rule):
|
|||
def analyze(self, oFile):
|
||||
for iLineNumber, oLine in enumerate(oFile.lines):
|
||||
if oLine.isComment:
|
||||
if oFile.lines[iLineNumber - 1].hasComment:
|
||||
if oFile.lines[iLineNumber - 1].isComment:
|
||||
if not oLine.commentColumn == (oLine.indentLevel * self.indentSize):
|
||||
self.add_violation(iLineNumber)
|
||||
self.correctCommentColumn.append(oLine.indentLevel * self.indentSize)
|
||||
else:
|
||||
try:
|
||||
if oFile.lines[iLineNumber + 1].isCaseWhenKeyword:
|
||||
if not oLine.commentColumn == (oLine.indentLevel * self.indentSize) and not oLine.commentColumn == ((oLine.indentLevel - 1) * self.indentSize):
|
||||
self.add_violation(iLineNumber)
|
||||
self.correctCommentColumn.append(oLine.indentLevel * self.indentSize)
|
||||
else:
|
||||
if not oLine.commentColumn == (oLine.indentLevel * self.indentSize):
|
||||
self.add_violation(iLineNumber)
|
||||
self.correctCommentColumn.append(oLine.indentLevel * self.indentSize)
|
||||
except IndexError:
|
||||
pass
|
||||
self._check_indent(oLine, iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iViolationIndex, iLineNumber in enumerate(self.violations):
|
||||
oLine = oFile.lines[iLineNumber]
|
||||
oLine.line = ' ' * self.correctCommentColumn[iViolationIndex] + oLine.line.lstrip()
|
||||
oLine.lineLower = oLine.line.lower()
|
||||
oLine.commentColumn = self.correctCommentColumn[iViolationIndex]
|
||||
|
||||
self.correctCommentColumn = []
|
||||
for iLineNumber in self.violations:
|
||||
self._fix_indent(oFile.lines[iLineNumber])
|
||||
|
||||
|
||||
# class rule_002(comment_rule):
|
||||
|
|
|
|||
|
|
@ -8,19 +8,20 @@ begin
|
|||
|
||||
case CASE1 is
|
||||
|
||||
when a => --
|
||||
when a => -- Comment
|
||||
-- Comment
|
||||
x <= y;
|
||||
z <= a;
|
||||
--
|
||||
when b => --
|
||||
-- Comment
|
||||
when b => -- Comment
|
||||
x <= y;
|
||||
z <= a;
|
||||
--
|
||||
when b => --
|
||||
when b => -- Comment
|
||||
x <= y;
|
||||
z <= a;
|
||||
-- Comment
|
||||
when b => --
|
||||
when b => -- Comment
|
||||
x <= y;
|
||||
z <= a;
|
||||
-- Comment
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class testRuleCommentMethods(unittest.TestCase):
|
|||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'comment')
|
||||
self.assertEqual(oRule.identifier, '001')
|
||||
dExpected = [3,7,12,13,21,23]
|
||||
dExpected = [3,7,12,13,17,19,21,23,27,30,45,49,64,68]
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
|
|
@ -26,7 +26,7 @@ class testRuleCommentMethods(unittest.TestCase):
|
|||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'comment')
|
||||
self.assertEqual(oRule.identifier, '001')
|
||||
dExpected = [22,26]
|
||||
dExpected = [19,23,27]
|
||||
oRule.analyze(oFileCase)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import unittest
|
|||
from vsg import vhdlFile
|
||||
|
||||
oFile = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'..','comment','comment_test_input.vhd'))
|
||||
oFileCase = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'..','comment','comment_case_test_input.vhd'))
|
||||
|
||||
class testVhdlFileCommentAssignments(unittest.TestCase):
|
||||
|
||||
|
|
@ -37,3 +38,15 @@ class testVhdlFileCommentAssignments(unittest.TestCase):
|
|||
lActual.append(oLine.commentColumn)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_comment_indent_assignment(self):
|
||||
# [12,15,17,23,27]
|
||||
lExpected = [ 4, 3, 3, 3, 4]
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFileCase.lines):
|
||||
if oLine.isComment:
|
||||
lActual.append(oLine.indentLevel)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
|
|
|
|||
|
|
@ -361,6 +361,8 @@ class vhdlFile():
|
|||
oLine.isCaseWhenKeyword = True
|
||||
oLine.indentLevel = iCurrentIndentLevel - 1
|
||||
fInsideCaseWhen = True
|
||||
if self.lines[-1].isComment:
|
||||
self.lines[-1].indentLevel -= 1
|
||||
if fInsideCaseWhen:
|
||||
oLine.insideCaseWhen = True
|
||||
if re.match('^\s*.*=>', oLine.line):
|
||||
|
|
|
|||
Loading…
Reference in New Issue