Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from vsg import rule
from vsg import utils
class rule_010(rule.rule):
'''
General rule 010 checks capitalization consistency of function names.
'''
def __init__(self):
rule.rule.__init__(self, 'function', '010')
self.fixable = True
self.solution = 'Inconsistent capitalization of word'
self.phase = 6
self.dDatabase = create_database()
def _analyze(self, oFile, oLine, iLineNumber):
if oLine.isFunctionKeyword:
self.dDatabase['function'].append(oLine.line.split()[1]) # TODO: Think if this can be solved in better way.
if oLine.insideArchitecture:
if oLine.insideProcess or oLine.insideConcurrent:
def _analyze(self, oFile, oLine, iLineNumber):
if oLine.isArchitectureKeyword:
self.sLabel = oLine.line.split()[1]
if oLine.isEndArchitecture and not re.match('^\s*end\s+architecture\s+\w+', oLine.line, re.IGNORECASE):
if re.match('^\s*end\s+architecture', oLine.line, re.IGNORECASE):
dViolation = utils.create_violation_dict(iLineNumber)
dViolation['label'] = self.sLabel
self.add_violation(dViolation)
elif not re.match('^\s*end\s+\w+', oLine.line, re.IGNORECASE):
dViolation = utils.create_violation_dict(iLineNumber)
dViolation['label'] = self.sLabel
self.add_violation(dViolation)
from vsg.rules import case_rule
class rule_028(case_rule):
'''
Instantiation rule 028 checks the entity name is uppercase in direct instantiations.
'''
def __init__(self):
case_rule.__init__(self, 'instantiation', '028', 'isDirectInstantiationDeclaration')
self.solution = 'Change entity name to '
def _extract(self, oLine):
return [oLine.line.replace('.', ' ').split()[-1]]
def _fix_violations(self, oFile):
for dViolation in self.violations[::-1]:
iLineNumber = utils.get_violation_linenumber(dViolation)
utils.copy_line(oFile, iLineNumber)
oLine = oFile.lines[iLineNumber]
oLine.update_line(oLine.line.split('(')[0] + '(')
oLine.isFunctionParameter = False
oLine = oFile.lines[iLineNumber + 1]
oLine.update_line(' ' + oLine.line.split('(')[1])
oLine.isFunctionKeyword = False
oLine.indentLevel = oFile.lines[iLineNumber].indentLevel + 1
def __init__(self):
rule.rule.__init__(self, 'case', '020')
self.phase = 1
self.solution = 'Remove label after the "end case" keywords'
from vsg import rule
from vsg import utils
from vsg import parser
class case_item_rule(rule.rule):
'''
Checks the case for words.
Parameters
----------
name : string
The group the rule belongs to.
identifier : string
unique identifier. Usually in the form of 00N.
trigger : parser object type
object type to apply the case check against
'''
def __init__(self):
rule.rule.__init__(self, 'semicolon', '001')
self.phase = 1
self.solution = 'Remove consecutive semicolons.'
from vsg import rule
from vsg import check
from vsg import fix
from vsg import utils
class rule_001(rule.rule):
'''Case rule 001 checks for the proper indentation at the beginning of the line.'''
def __init__(self):
rule.rule.__init__(self, 'case', '001')
self.solution = 'Ensure proper indentation.'
self.phase = 4
def _analyze(self, oFile, oLine, iLineNumber):
if oLine.isCaseKeyword or oLine.isCaseWhenKeyword or oLine.isEndCaseKeyword:
check.indent(self, oLine, iLineNumber)
def _fix_violations(self, oFile):
for dViolation in self.violations:
fix.indent(self, utils.get_violating_line(oFile, dViolation))
def __init__(self):
rule.rule.__init__(self)
self.name = 'function'
from vsg import rule
from vsg import check
from vsg import fix
from vsg import utils
import re
class rule_022(rule.rule):
'''
Architecture rule 022 checks for a single space after the "end architecture" keywords and the architecture name.
'''
def __init__(self):
rule.rule.__init__(self, 'architecture', '022')
self.solution = 'Ensure a single space exists between "architecture" and the architecture name.'
self.phase = 2
def _analyze(self, oFile, oLine, iLineNumber):
if oLine.isEndArchitecture and re.match('^\s*end\s+architecture\s+\w', oLine.lineLower):
check.is_single_space_after(self, 'architecture', oLine, iLineNumber)
def _fix_violations(self, oFile):
for dViolation in self.violations:
fix.enforce_one_space_after_word(self, utils.get_violating_line(oFile, dViolation), 'architecture')