Make architecture rules inherit from case rule.
This commit is contained in:
parent
a069c85afb
commit
985ea8da9c
|
|
@ -62,7 +62,7 @@ architecture_004
|
|||
|
||||
This rule checks the proper case of the **architecture** keyword in the architecture declaration.
|
||||
|
||||
.. NOTE:: The default is lowercase.
|
||||
.. NOTE:: The default is lowercase.
|
||||
|
||||
Refer to the section `Configuring Uppercase and Lowercase Rules <configuring_case.html>`_ for information on changing the default case.
|
||||
|
||||
|
|
@ -159,7 +159,9 @@ This rule checks for spaces before the **end architecture** keywords.
|
|||
architecture_009
|
||||
################
|
||||
|
||||
This rule checks the **end** and **architecture** keywords are lower case.
|
||||
This rule checks the **end** and **architecture** keywords have proper case.
|
||||
|
||||
.. NOTE:: The default is lowercase.
|
||||
|
||||
**Violation**
|
||||
|
||||
|
|
@ -200,7 +202,7 @@ architecture_011
|
|||
|
||||
This rule checks the architecture name case in the **end architecture** statement.
|
||||
|
||||
.. NOTE:: The default is uppercase.
|
||||
.. NOTE:: The default is uppercase.
|
||||
|
||||
Refer to the section `Configuring Uppercase and Lowercase Rules <configuring_case.html>`_ for information on changing the default case.
|
||||
|
||||
|
|
@ -239,7 +241,7 @@ architecture_013
|
|||
|
||||
This rule checks the case of the architecture name in the architecture declaration.
|
||||
|
||||
.. NOTE:: The default is uppercase.
|
||||
.. NOTE:: The default is uppercase.
|
||||
|
||||
Refer to the section `Configuring Uppercase and Lowercase Rules <configuring_case.html>`_ for information on changing the default case.
|
||||
|
||||
|
|
@ -261,7 +263,7 @@ architecture_014
|
|||
|
||||
This rule checks the case of the entity name in the architecture declaration.
|
||||
|
||||
.. NOTE:: The default is uppercase.
|
||||
.. NOTE:: The default is uppercase.
|
||||
|
||||
Refer to the section `Configuring Uppercase and Lowercase Rules <configuring_case.html>`_ for information on changing the default case.
|
||||
|
||||
|
|
@ -370,7 +372,7 @@ architecture_019
|
|||
|
||||
This rule checks the proper case of the **of** keyword in the architecture declaration.
|
||||
|
||||
.. NOTE:: The default is lowercase.
|
||||
.. NOTE:: The default is lowercase.
|
||||
|
||||
Refer to the section `Configuring Uppercase and Lowercase Rules <configuring_case.html>`_ for information on changing the default case.
|
||||
|
||||
|
|
@ -391,7 +393,7 @@ architecture_020
|
|||
|
||||
This rule checks the proper case of the **is** keyword in the architecture declaration.
|
||||
|
||||
.. NOTE:: The default is lowercase.
|
||||
.. NOTE:: The default is lowercase.
|
||||
|
||||
Refer to the section `Configuring Uppercase and Lowercase Rules <configuring_case.html>`_ for information on changing the default case.
|
||||
|
||||
|
|
@ -412,7 +414,7 @@ architecture_021
|
|||
|
||||
This rule checks the proper case of the **begin** keyword.
|
||||
|
||||
.. NOTE:: The default is lowercase.
|
||||
.. NOTE:: The default is lowercase.
|
||||
|
||||
Refer to the section `Configuring Uppercase and Lowercase Rules <configuring_case.html>`_ for information on changing the default case.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
from .architecture_case_rule import architecture_case_rule
|
||||
|
||||
from .rule_001 import rule_001
|
||||
from .rule_002 import rule_002
|
||||
from .rule_003 import rule_003
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
|
||||
from vsg import rule
|
||||
from vsg import check
|
||||
|
||||
import re
|
||||
|
||||
|
||||
class architecture_case_rule(rule.rule):
|
||||
'''
|
||||
Architecture rule 013 checks the architecture name is upper case in the architecture declaration.
|
||||
'''
|
||||
|
||||
def __init__(self, name=None, identifier=None, iIndex=None):
|
||||
rule.rule.__init__(self, name, identifier)
|
||||
self.case = 'upper'
|
||||
self.phase = 6
|
||||
self.configuration.append('case')
|
||||
self.iIndex = iIndex
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isArchitectureKeyword and re.match('^\s*\S+\s\s*\S+\s\s*of\s\s*\S+\s\s*is', oLine.lineLower):
|
||||
lLine = oLine.line.split()
|
||||
if self.case == 'upper':
|
||||
check.is_uppercase(self, lLine[self.iIndex], iLineNumber)
|
||||
else:
|
||||
check.is_lowercase(self, lLine[self.iIndex], iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber in self.violations:
|
||||
oLine = oFile.lines[iLineNumber]
|
||||
sLine = oLine.lineNoComment
|
||||
if self.case == 'upper':
|
||||
sWord = sLine.split()[self.iIndex].upper()
|
||||
else:
|
||||
sWord = sLine.split()[self.iIndex].lower()
|
||||
iIndex = sLine.rfind(sLine.split()[self.iIndex])
|
||||
sLine = sLine[:iIndex] + sWord + sLine[iIndex + len(sWord):]
|
||||
oLine.update_line(sLine)
|
||||
|
||||
def _get_solution(self, iLineNumber):
|
||||
return self.case + 'case ' + self.solution
|
||||
|
|
@ -1,25 +1,16 @@
|
|||
|
||||
from vsg import rule
|
||||
from vsg import fix
|
||||
|
||||
import re
|
||||
from vsg.rules import case_rule
|
||||
from vsg import utils
|
||||
|
||||
|
||||
class rule_009(rule.rule):
|
||||
'''Architecture rule 009 checks for the "end" and "architecture" keyword are lower case.'''
|
||||
class rule_009(case_rule):
|
||||
'''
|
||||
Architecture rule 009 checks the "end" and "architecture" keywords have proper case.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
rule.rule.__init__(self, 'architecture', '009')
|
||||
self.solution = 'Ensure "end" and "architecture" keywords are lower case.'
|
||||
self.phase = 6
|
||||
case_rule.__init__(self, 'architecture', '009', 'isEndArchitecture')
|
||||
self.solution = 'Change "end" and "architecture" keywords to '
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isEndArchitecture and \
|
||||
re.match('^\s*end\s\s*architecture', oLine.lineLower) and \
|
||||
not re.match('^\s*end\s\s*architecture', oLine.line):
|
||||
self.add_violation(iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber in self.violations:
|
||||
fix.lower_case(oFile.lines[iLineNumber], 'end')
|
||||
fix.lower_case(oFile.lines[iLineNumber], 'architecture')
|
||||
def _extract(self, oLine):
|
||||
return utils.extract_words(oLine, ['end', 'architecture'])
|
||||
|
|
|
|||
|
|
@ -1,51 +1,18 @@
|
|||
|
||||
import re
|
||||
|
||||
from vsg import rule
|
||||
from vsg import fix
|
||||
from vsg import check
|
||||
|
||||
|
||||
class rule_011(rule.rule):
|
||||
from vsg.rules import case_rule
|
||||
from vsg import utils
|
||||
|
||||
|
||||
class rule_011(case_rule):
|
||||
'''
|
||||
Architecture rule 011 checks the architecture name case on the closing "end architecture" line.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
rule.rule.__init__(self, 'architecture', '011')
|
||||
self.solution = 'Uppercase architecture name.'
|
||||
case_rule.__init__(self, 'architecture', '011', 'isEndArchitecture')
|
||||
self.case = 'upper'
|
||||
self.phase = 6
|
||||
self.configuration.append('case')
|
||||
self.solution = 'Change architecture name to '
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.isEndArchitecture and re.match('^\s*end\s+architecture\s+\w+', oLine.line, re.IGNORECASE):
|
||||
lLine = oLine.line.split()
|
||||
if self.case == 'upper':
|
||||
check.is_uppercase(self, lLine[2], iLineNumber)
|
||||
else:
|
||||
check.is_lowercase(self, lLine[2], iLineNumber)
|
||||
self.dFix[iLineNumber] = 2
|
||||
elif oLine.isEndArchitecture and re.match('^\s*end\s+\w+', oLine.line, re.IGNORECASE):
|
||||
lLine = oLine.line.split()
|
||||
self.dFix[iLineNumber] = 2
|
||||
if not lLine[1].lower().startswith('architecture'):
|
||||
self.dFix[iLineNumber] = 1
|
||||
if self.case == 'upper':
|
||||
check.is_uppercase(self, lLine[1], iLineNumber)
|
||||
else:
|
||||
check.is_lowercase(self, lLine[1], iLineNumber)
|
||||
|
||||
def _fix_violations(self, oFile):
|
||||
for iLineNumber in self.violations:
|
||||
iIndex = self.dFix[iLineNumber]
|
||||
if self.case == 'upper':
|
||||
fix.upper_case(oFile.lines[iLineNumber], oFile.lines[iLineNumber].line.split()[iIndex])
|
||||
else:
|
||||
fix.lower_case(oFile.lines[iLineNumber], oFile.lines[iLineNumber].line.split()[iIndex])
|
||||
|
||||
def _get_solution(self, iLineNumber):
|
||||
if self.case == 'upper':
|
||||
return 'Uppercase architecture name.'
|
||||
else:
|
||||
return 'Lowercase architecture name.'
|
||||
def _extract(self, oLine):
|
||||
return utils.extract_architecture_identifier(oLine)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
|
||||
from vsg.rules.architecture import architecture_case_rule
|
||||
from vsg.rules import case_rule
|
||||
from vsg import utils
|
||||
|
||||
|
||||
class rule_013(architecture_case_rule):
|
||||
class rule_013(case_rule):
|
||||
'''
|
||||
Architecture rule 013 checks the architecture name is upper case in the architecture declaration.
|
||||
Architecture rule 013 checks the architecture name has proper case in the architecture declaration.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
architecture_case_rule.__init__(self, 'architecture', '013', 1)
|
||||
self.solution = 'architecture name.'
|
||||
case_rule.__init__(self, 'architecture', '013', 'isArchitectureKeyword')
|
||||
self.case = 'upper'
|
||||
self.solution = 'Change architecture name to '
|
||||
|
||||
def _extract(self, oLine):
|
||||
return utils.extract_architecture_identifier(oLine)
|
||||
|
|
|
|||
|
|
@ -1,12 +1,20 @@
|
|||
|
||||
from vsg.rules.architecture import architecture_case_rule
|
||||
from vsg.rules import case_rule
|
||||
|
||||
|
||||
class rule_014(architecture_case_rule):
|
||||
class rule_014(case_rule):
|
||||
'''
|
||||
Architecture rule 014 checks the entity name is upper case in the architecture declaration.
|
||||
Architecture rule 014 checks the entity name has proper case in the architecture declaration.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
architecture_case_rule.__init__(self, 'architecture', '014', 3)
|
||||
self.solution = 'entity name.'
|
||||
case_rule.__init__(self, 'architecture', '014', 'isArchitectureKeyword')
|
||||
self.case = 'upper'
|
||||
self.solution = 'Change entity name to '
|
||||
|
||||
def _extract(self, oLine):
|
||||
sLine = oLine.lineNoComment.split()
|
||||
if sLine[-1].lower() == 'is':
|
||||
return [sLine[-2]]
|
||||
|
||||
return []
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ end;
|
|||
|
||||
-- Comment
|
||||
|
||||
architecture ARCH of arch is
|
||||
architecture ARCH of ent is
|
||||
|
||||
begin
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ class testFixRuleArchitectureMethods(unittest.TestCase):
|
|||
|
||||
self.assertEqual(self.oFile.lines[24].line, ' eND architecture ARCH')
|
||||
|
||||
self.assertEqual('Uppercase architecture name.', oRule._get_solution(24))
|
||||
self.assertEqual('Change architecture name to uppercase.', oRule._get_solution(24))
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
|
@ -126,7 +126,7 @@ class testFixRuleArchitectureMethods(unittest.TestCase):
|
|||
|
||||
self.assertEqual(self.oFile.lines[7].line, 'End architecture arch;')
|
||||
|
||||
self.assertEqual('Lowercase architecture name.', oRule._get_solution(24))
|
||||
self.assertEqual('Change architecture name to lowercase.', oRule._get_solution(24))
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
|
@ -146,7 +146,7 @@ class testFixRuleArchitectureMethods(unittest.TestCase):
|
|||
self.assertEqual(self.oFile.lines[3].line, 'architecture ARCH of ENTITY is')
|
||||
self.assertEqual(self.oFile.lines[20].line, ' Architecture ARCH Of entity Is')
|
||||
|
||||
self.assertEqual('uppercase architecture name.', oRule._get_solution(3))
|
||||
self.assertEqual('Change architecture name to uppercase.', oRule._get_solution(3))
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
|
@ -160,7 +160,7 @@ class testFixRuleArchitectureMethods(unittest.TestCase):
|
|||
self.assertEqual(self.oFile.lines[3].line, 'architecture arch of ENTITY is')
|
||||
self.assertEqual(self.oFile.lines[20].line, ' Architecture arch Of entity Is')
|
||||
|
||||
self.assertEqual('lowercase architecture name.', oRule._get_solution(3))
|
||||
self.assertEqual('Change architecture name to lowercase.', oRule._get_solution(3))
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
|
@ -169,7 +169,7 @@ class testFixRuleArchitectureMethods(unittest.TestCase):
|
|||
oRule = architecture.rule_014()
|
||||
dExpected = []
|
||||
oRule.fix(self.oFile)
|
||||
self.assertEqual(self.oFile.lines[81].line, 'architecture ARCH of ARCH is')
|
||||
self.assertEqual(self.oFile.lines[81].line, 'architecture ARCH of ENT is')
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
|
|
|||
|
|
@ -181,14 +181,14 @@ class testRuleArchitectureMethods(unittest.TestCase):
|
|||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'architecture')
|
||||
self.assertEqual(oRule.identifier, '013')
|
||||
dExpected = [3,20]
|
||||
dExpected = [3,20,26]
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
def test_rule_013_lowercase(self):
|
||||
oRule = architecture.rule_013()
|
||||
oRule.case = 'lower'
|
||||
dExpected = [3,9,14,20,33,37,47,59,81]
|
||||
dExpected = [3,9,14,20,26,33,37,47,59,81]
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, dExpected)
|
||||
|
||||
|
|
|
|||
24
vsg/utils.py
24
vsg/utils.py
|
|
@ -886,6 +886,30 @@ def extract_generics(oLine):
|
|||
return sLine
|
||||
|
||||
|
||||
def extract_architecture_identifier(oLine):
|
||||
'''
|
||||
Returns architecture name from architecture declaration or end.
|
||||
|
||||
Parameters:
|
||||
|
||||
oLine: (line object)
|
||||
|
||||
Returns: (one element or empty list of strings)
|
||||
'''
|
||||
sLine = oLine.lineNoComment.replace(';', '').split()
|
||||
if sLine[0].lower() == 'architecture':
|
||||
if len(sLine) > 1:
|
||||
return [sLine[1]]
|
||||
elif len(sLine) > 1 and sLine[1].lower() == 'architecture':
|
||||
if len(sLine) > 2:
|
||||
return [sLine[2]]
|
||||
elif sLine[0].lower() == 'end':
|
||||
if len(sLine) > 1:
|
||||
return [sLine[1]]
|
||||
|
||||
return []
|
||||
|
||||
|
||||
def remove_comment_attributes_from_line(oLine):
|
||||
'''
|
||||
Sets all comment attributes on a line to indicate no comment is present.
|
||||
|
|
|
|||
Loading…
Reference in New Issue