diff --git a/vsg/check.py b/vsg/check.py index dfe6c95d..8ae34e3d 100644 --- a/vsg/check.py +++ b/vsg/check.py @@ -30,3 +30,37 @@ def is_blank_line_before(self, oFile, iLineNumber): if not oFile.lines[iLineNumber - 1].isBlank: self.add_violation(iLineNumber) +def keyword_alignment(self, iStartGroupIndex, sKeyword, lGroup): + iKeywordAlignment = None + iMaximumKeywordColumn = 0 + sViolationRange = str(iStartGroupIndex) + '-' + str(iStartGroupIndex + len(lGroup) - 1) + self.dFix['violations'][sViolationRange] = {} + self.dFix['violations'][sViolationRange]['line'] = {} + + for iIndex, oGroupLine in enumerate(lGroup): + if sKeyword in oGroupLine.line: + self.dFix['violations'][sViolationRange]['line'][iStartGroupIndex + iIndex] = {} + self.dFix['violations'][sViolationRange]['line'][iStartGroupIndex + iIndex]['keywordColumn'] = oGroupLine.line.find(sKeyword) + + iMaximumKeywordColumn = get_maximum_keyword_column(oGroupLine, sKeyword, iMaximumKeywordColumn) + + iKeywordAlignment = update_keyword_alignment(oGroupLine, sKeyword, iKeywordAlignment) + + if not iKeywordAlignment == oGroupLine.line.find(sKeyword): + add_range_violation(self, sViolationRange) + + self.dFix['violations'][sViolationRange]['maximumKeywordColumn'] = iMaximumKeywordColumn + +def get_maximum_keyword_column(oLine, sKeyword, iMaximumKeywordColumn): + if oLine.line.find(sKeyword) > iMaximumKeywordColumn: + return oLine.line.find(sKeyword) + return iMaximumKeywordColumn + +def update_keyword_alignment(oLine, sKeyword, iKeywordAlignment): + if not iKeywordAlignment: + return oLine.line.find(sKeyword) + return iKeywordAlignment + +def add_range_violation(self, sViolationRange): + if not sViolationRange in self.violations: + self.add_violation(sViolationRange) diff --git a/vsg/rule.py b/vsg/rule.py index e68d1181..fd1407d5 100644 --- a/vsg/rule.py +++ b/vsg/rule.py @@ -99,27 +99,6 @@ class rule(): self.add_violation(iLineNumber) - def _check_keyword_alignment(self, iStartGroupIndex, sKeyword, lGroup): - iKeywordAlignment = None - iMaximumKeywordColumn = 0 - sViolationRange = str(iStartGroupIndex) + '-' + str(iStartGroupIndex + len(lGroup) - 1) - self.dFix['violations'][sViolationRange] = {} - self.dFix['violations'][sViolationRange]['line'] = {} - - for iIndex, oGroupLine in enumerate(lGroup): - if sKeyword in oGroupLine.line: - self.dFix['violations'][sViolationRange]['line'][iStartGroupIndex + iIndex] = {} - self.dFix['violations'][sViolationRange]['line'][iStartGroupIndex + iIndex]['keywordColumn'] = oGroupLine.line.find(sKeyword) - - iMaximumKeywordColumn = get_maximum_keyword_column(oGroupLine, sKeyword, iMaximumKeywordColumn) - - iKeywordAlignment = update_keyword_alignment(oGroupLine, sKeyword, iKeywordAlignment) - - if not iKeywordAlignment == oGroupLine.line.find(sKeyword): - add_range_violation(self, sViolationRange) - - self.dFix['violations'][sViolationRange]['maximumKeywordColumn'] = iMaximumKeywordColumn - def _fix_keyword_alignment(self, oFile): for sKey in self.dFix['violations']: iMaximumKeywordColumn = self.dFix['violations'][sKey]['maximumKeywordColumn'] @@ -198,18 +177,3 @@ class rule(): self.__dict__[sAttributeName] = dConfiguration['rule'][self.name + '_' + self.identifier][sAttributeName] except KeyError: pass - - -def get_maximum_keyword_column(oLine, sKeyword, iMaximumKeywordColumn): - if oLine.line.find(sKeyword) > iMaximumKeywordColumn: - return oLine.line.find(sKeyword) - return iMaximumKeywordColumn - -def update_keyword_alignment(oLine, sKeyword, iKeywordAlignment): - if not iKeywordAlignment: - return oLine.line.find(sKeyword) - return iKeywordAlignment - -def add_range_violation(self, sViolationRange): - if not sViolationRange in self.violations: - self.add_violation(sViolationRange) diff --git a/vsg/rules/architecture/rule_023.py b/vsg/rules/architecture/rule_023.py index 5904f6d6..88c0780b 100644 --- a/vsg/rules/architecture/rule_023.py +++ b/vsg/rules/architecture/rule_023.py @@ -1,6 +1,6 @@ from vsg.rules.architecture import architecture_rule - +from vsg import check from vsg import line @@ -26,7 +26,7 @@ class rule_023(architecture_rule): if oLine.isArchitectureBegin: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, '--', lGroup) + check.keyword_alignment(self, iStartGroupIndex, '--', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/comment/rule_003.py b/vsg/rules/comment/rule_003.py index 9d328ca5..767ace57 100644 --- a/vsg/rules/comment/rule_003.py +++ b/vsg/rules/comment/rule_003.py @@ -1,5 +1,6 @@ from vsg.rules.comment import comment_rule +from vsg import check from vsg import line @@ -23,7 +24,7 @@ class rule_003(comment_rule): if oLine.isEndProcess: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, '--', lGroup) + check.keyword_alignment(self, iStartGroupIndex, '--', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/component/rule_017.py b/vsg/rules/component/rule_017.py index 6a9adf82..9eb8afab 100644 --- a/vsg/rules/component/rule_017.py +++ b/vsg/rules/component/rule_017.py @@ -1,5 +1,6 @@ from vsg.rules.component import component_rule +from vsg import check from vsg import line @@ -27,7 +28,7 @@ class rule_017(component_rule): if oLine.isEndPortMap: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, ':', lGroup) + check.keyword_alignment(self, iStartGroupIndex, ':', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/concurrent/rule_006.py b/vsg/rules/concurrent/rule_006.py index e205b643..803efc26 100644 --- a/vsg/rules/concurrent/rule_006.py +++ b/vsg/rules/concurrent/rule_006.py @@ -1,5 +1,6 @@ from vsg.rules.concurrent import concurrent_rule +from vsg import check class rule_006(concurrent_rule): @@ -23,7 +24,7 @@ class rule_006(concurrent_rule): iStartGroupIndex = iLineNumber if not oLine.insideConcurrent and fGroupFound: fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, '<=', lGroup) + check.keyword_alignment(self, iStartGroupIndex, '<=', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/concurrent/rule_008.py b/vsg/rules/concurrent/rule_008.py index 1b7bca8d..5c6800d7 100644 --- a/vsg/rules/concurrent/rule_008.py +++ b/vsg/rules/concurrent/rule_008.py @@ -1,5 +1,6 @@ from vsg.rules.concurrent import concurrent_rule +from vsg import check class rule_008(concurrent_rule): @@ -23,7 +24,7 @@ class rule_008(concurrent_rule): iStartGroupIndex = iLineNumber if not oLine.insideConcurrent and fGroupFound: fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, '--', lGroup) + check.keyword_alignment(self, iStartGroupIndex, '--', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/constant/rule_009.py b/vsg/rules/constant/rule_009.py index 74f94e3d..fb65d5b1 100644 --- a/vsg/rules/constant/rule_009.py +++ b/vsg/rules/constant/rule_009.py @@ -1,6 +1,6 @@ from vsg.rules.constant import constant_rule - +from vsg import check from vsg import line @@ -26,7 +26,7 @@ class rule_009(constant_rule): if oLine.isEndArchitecture: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, ':', lGroup) + check.keyword_alignment(self, iStartGroupIndex, ':', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/entity/rule_017.py b/vsg/rules/entity/rule_017.py index 2f9ea7d9..7bfbac04 100644 --- a/vsg/rules/entity/rule_017.py +++ b/vsg/rules/entity/rule_017.py @@ -1,5 +1,6 @@ from vsg.rules.entity import entity_rule +from vsg import check from vsg import line @@ -25,7 +26,7 @@ class rule_017(entity_rule): if oLine.isEndPortMap and oLine.insideEntity: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, ':', lGroup) + check.keyword_alignment(self, iStartGroupIndex, ':', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/entity/rule_018.py b/vsg/rules/entity/rule_018.py index 0ada7e23..a638da80 100644 --- a/vsg/rules/entity/rule_018.py +++ b/vsg/rules/entity/rule_018.py @@ -1,5 +1,6 @@ from vsg.rules.entity import entity_rule +from vsg import check from vsg import line @@ -35,7 +36,7 @@ class rule_018(entity_rule): if oLine.isEndEntityDeclaration: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, '--', lGroup) + check.keyword_alignment(self, iStartGroupIndex, '--', lGroup) lGroup = [] iStartGroupIndex = None self._store_lines_for_group(fGroupFound, oLine, lGroup) diff --git a/vsg/rules/generic/rule_012.py b/vsg/rules/generic/rule_012.py index fe6a67fe..2189a3b5 100644 --- a/vsg/rules/generic/rule_012.py +++ b/vsg/rules/generic/rule_012.py @@ -1,5 +1,6 @@ from vsg.rules.generic import generic_rule +from vsg import check from vsg import line class rule_012(generic_rule): @@ -22,7 +23,7 @@ class rule_012(generic_rule): if oLine.isEndGenericMap and fGroupFound: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, ':', lGroup) + check.keyword_alignment(self, iStartGroupIndex, ':', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/generic/rule_015.py b/vsg/rules/generic/rule_015.py index 3f04e812..c7f922c7 100644 --- a/vsg/rules/generic/rule_015.py +++ b/vsg/rules/generic/rule_015.py @@ -1,5 +1,6 @@ from vsg.rules.generic import generic_rule +from vsg import check from vsg import line class rule_015(generic_rule): @@ -22,7 +23,7 @@ class rule_015(generic_rule): if oLine.isEndGenericMap and fGroupFound: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, ':=', lGroup) + check.keyword_alignment(self, iStartGroupIndex, ':=', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/instantiation/rule_010.py b/vsg/rules/instantiation/rule_010.py index 43dccd84..1b7441d7 100644 --- a/vsg/rules/instantiation/rule_010.py +++ b/vsg/rules/instantiation/rule_010.py @@ -1,5 +1,6 @@ from vsg.rules.instantiation import instantiation_rule +from vsg import check from vsg import line @@ -25,7 +26,7 @@ class rule_010(instantiation_rule): if oLine.isInstantiationPortEnd: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, '=>', lGroup) + check.keyword_alignment(self, iStartGroupIndex, '=>', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/instantiation/rule_015.py b/vsg/rules/instantiation/rule_015.py index ce1482e6..7c3d4787 100644 --- a/vsg/rules/instantiation/rule_015.py +++ b/vsg/rules/instantiation/rule_015.py @@ -1,5 +1,6 @@ from vsg.rules.instantiation import instantiation_rule +from vsg import check from vsg import line @@ -25,7 +26,7 @@ class rule_015(instantiation_rule): if oLine.isInstantiationGenericEnd: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, '=>', lGroup) + check.keyword_alignment(self, iStartGroupIndex, '=>', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/sequential/rule_005.py b/vsg/rules/sequential/rule_005.py index aabc76f3..4d21bdd0 100644 --- a/vsg/rules/sequential/rule_005.py +++ b/vsg/rules/sequential/rule_005.py @@ -1,5 +1,6 @@ from vsg.rules.sequential import sequential_rule +from vsg import check from vsg import line @@ -24,7 +25,7 @@ class rule_005(sequential_rule): iStartGroupIndex = iLineNumber if not oLine.insideSequential and fGroupFound: fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, '<=', lGroup) + check.keyword_alignment(self, iStartGroupIndex, '<=', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/signal/rule_009.py b/vsg/rules/signal/rule_009.py index 0a5e6bf7..e8bb1d0b 100644 --- a/vsg/rules/signal/rule_009.py +++ b/vsg/rules/signal/rule_009.py @@ -1,5 +1,6 @@ from vsg.rules.signal import signal_rule +from vsg import check from vsg import line @@ -25,7 +26,7 @@ class rule_009(signal_rule): if oLine.isEndArchitecture: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, ':', lGroup) + check.keyword_alignment(self, iStartGroupIndex, ':', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/variable/rule_009.py b/vsg/rules/variable/rule_009.py index d212645b..ed42627c 100644 --- a/vsg/rules/variable/rule_009.py +++ b/vsg/rules/variable/rule_009.py @@ -1,6 +1,7 @@ from vsg.rules.variable import variable_rule from vsg import line +from vsg import check class rule_009(variable_rule): @@ -25,7 +26,7 @@ class rule_009(variable_rule): if oLine.isEndArchitecture: lGroup.append(oLine) fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, ':', lGroup) + check.keyword_alignment(self, iStartGroupIndex, ':', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: diff --git a/vsg/rules/variable_assignment/rule_005.py b/vsg/rules/variable_assignment/rule_005.py index dea26871..8236ce12 100644 --- a/vsg/rules/variable_assignment/rule_005.py +++ b/vsg/rules/variable_assignment/rule_005.py @@ -1,5 +1,6 @@ from vsg.rules.variable_assignment import variable_assignment_rule +from vsg import check from vsg import line @@ -22,7 +23,7 @@ class rule_005(variable_assignment_rule): iStartGroupIndex = iLineNumber if not oLine.insideVariableAssignment and fGroupFound: fGroupFound = False - self._check_keyword_alignment(iStartGroupIndex, ':=', lGroup) + check.keyword_alignment(self, iStartGroupIndex, ':=', lGroup) lGroup = [] iStartGroupIndex = None if fGroupFound: