diff --git a/vsg/rules/__init__.py b/vsg/rules/__init__.py index bb65230f..5b6ca11f 100644 --- a/vsg/rules/__init__.py +++ b/vsg/rules/__init__.py @@ -11,7 +11,6 @@ from .remove_blank_lines_above_rule import remove_blank_lines_above_rule from .remove_blank_lines_below_rule import remove_blank_lines_below_rule from .remove_spaces_before_character_rule import remove_spaces_before_character_rule from .lower_case_rule import lower_case_rule -from .lowercase_word_after_colon_rule import lowercase_word_after_colon_rule from .multiple_spaces_after_rule import multiple_spaces_after_rule from .search_for_and_replace_keyword_rule import search_for_and_replace_keyword_rule from .case_rule import case_rule diff --git a/vsg/rules/lowercase_word_after_colon_rule.py b/vsg/rules/lowercase_word_after_colon_rule.py deleted file mode 100644 index 4ee5bf9b..00000000 --- a/vsg/rules/lowercase_word_after_colon_rule.py +++ /dev/null @@ -1,54 +0,0 @@ - -from vsg import rule -from vsg import fix -from vsg import check -from vsg import utils - -import re - - -class lowercase_word_after_colon_rule(rule.rule): - ''' - This class checks the word after a : is lowercase. - - Parameters - ---------- - - name : string - The group the rule belongs to. - - identifier : string - unique identifier. Usually in the form of 00N. - - sTrigger : string - The line attribute the rule applies to. - - bVhdlKeyword : boolean - Check whether word is a VHDL keyword - - ''' - - def __init__(self, name=None, identifier=None, sTrigger=None, bVhdlKeyword=False): - rule.rule.__init__(self, name, identifier) - self.solution = None - self.phase = 6 - self.sTrigger = sTrigger - self.dVars = {} - self.bVhdlKeyword = bVhdlKeyword - - def _analyze(self, oFile, oLine, iLineNumber): - if oLine.__dict__[self.sTrigger] and re.match('^.*:\s*\w', oLine.lineLower): - sLine = oLine.line.split(':')[1].lstrip().split()[0].split('(')[0] - if self.bVhdlKeyword: - if utils.is_vhdl_keyword(sLine): - self.dVars[iLineNumber] = sLine - check.is_lowercase(self, sLine, iLineNumber) - else: - self.dVars[iLineNumber] = sLine - check.is_lowercase(self, sLine, iLineNumber) - - def _fix_violations(self, oFile): - for iLineNumber in self.violations: - oLine = oFile.lines[iLineNumber] - fix.lower_case(self, oLine, self.dVars[iLineNumber]) - self.dVars = {} diff --git a/vsg/rules/signal/rule_010.py b/vsg/rules/signal/rule_010.py index b6a8d376..ab1e4970 100644 --- a/vsg/rules/signal/rule_010.py +++ b/vsg/rules/signal/rule_010.py @@ -1,13 +1,14 @@ -from vsg.rules import lowercase_word_after_colon_rule +from vsg.rules import case_rule +from vsg import utils -class rule_010(lowercase_word_after_colon_rule): +class rule_010(case_rule): ''' - Signal rule 010 checks the signal type is lowercase. + Signal rule 010 checks the signal type has proper case. ''' def __init__(self): - lowercase_word_after_colon_rule.__init__(self, 'signal', '010', 'isSignal', True) - self.solution = 'Change signal type to lowercase.' + case_rule.__init__(self, 'signal', '010', 'isSignal', utils.extract_type_name_vhdl_only) + self.solution = 'Change signal type name to ' + self.case + 'case' self.disabled = True diff --git a/vsg/rules/signal/rule_011.py b/vsg/rules/signal/rule_011.py index f61d6fb8..06f4e145 100644 --- a/vsg/rules/signal/rule_011.py +++ b/vsg/rules/signal/rule_011.py @@ -1,12 +1,13 @@ -from vsg.rules import lowercase_word_after_colon_rule +from vsg.rules import case_rule +from vsg import utils -class rule_011(lowercase_word_after_colon_rule): +class rule_011(case_rule): ''' - Signal rule 010 checks the signal type is lowercase. + Signal rule 011 checks the signal type has proper case. ''' def __init__(self): - lowercase_word_after_colon_rule.__init__(self, 'signal', '011', 'isSignal', False) - self.solution = 'Change signal type to lowercase.' + case_rule.__init__(self, 'signal', '011', 'isSignal', utils.extract_type_name) + self.solution = 'Change signal type name to ' + self.case + 'case' diff --git a/vsg/tests/vsg_utils/test_utils.py b/vsg/tests/vsg_utils/test_utils.py index 28690e81..a7e75eea 100644 --- a/vsg/tests/vsg_utils/test_utils.py +++ b/vsg/tests/vsg_utils/test_utils.py @@ -250,6 +250,19 @@ class testExtractFunctions(unittest.TestCase): sActual = utils.extract_type_name(oLine) self.assertEqual(sExpected, sActual) + def test_extract_type_name_vhdl_only(self): + oLine = line.blank_line() + oLine.update_line('variable var1, var2 : integer := -32;') + sExpected = ['integer'] + sActual = utils.extract_type_name_vhdl_only(oLine) + self.assertEqual(sExpected, sActual) + + oLine = line.blank_line() + oLine.update_line('variable var1, var2 : my_type := -32;') + sExpected = [] + sActual = utils.extract_type_name_vhdl_only(oLine) + self.assertEqual(sExpected, sActual) + def test_extract_label(self): oLine = line.blank_line() oLine.update_line(' cp: CPU') diff --git a/vsg/utils.py b/vsg/utils.py index c9bef821..f4085322 100644 --- a/vsg/utils.py +++ b/vsg/utils.py @@ -596,6 +596,25 @@ def extract_type_name(oLine): return [sLine.split()[0]] +def extract_type_name_vhdl_only(oLine): + ''' + Returns the name of a VHDL only types in various declarations. + + Parameters: + + oLine: (line object) + + Returns: (one element or empty list of strings) + ''' + name = extract_type_name(oLine) + + if is_vhdl_keyword(name[0]): + return name + + return [] + + + def extract_type_identifier(oLine): ''' Returns the type identifier from type declaration.