Updates for issue #90

1)  Moving _check_keyword_alignment to check.py
This commit is contained in:
Jeremiah C Leary 2017-11-28 19:26:34 -06:00
parent 99319d04d2
commit eee146f5c4
18 changed files with 66 additions and 54 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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)

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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: