vhdl-style-guide/vsg/rules/whitespace/rule_006.py

35 lines
1.1 KiB
Python

from vsg import rule
from vsg import utils
import re
class rule_006(rule.rule):
'''Whitespace rule 006 checks for spaces before a close parenthesis.'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'whitespace'
self.identifier = '006'
self.phase = 2
self.solution = 'Remove spaces before close ).'
def _analyze(self, oFile, oLine, iLineNumber):
sLine = oLine.lineNoComment
if re.match('^.*\s+\)', sLine) and not re.match('^\s+\)', sLine):
dViolation = utils.create_violation_dict(iLineNumber)
self.add_violation(dViolation)
def _fix_violations(self, oFile):
for dViolation in self.violations:
oLine = utils.get_violating_line(oFile, dViolation)
iCommentIndex = oLine.line.find('--')
if iCommentIndex == -1:
oLine.update_line(re.sub(r'\s+\)', r')', oLine.line))
else:
sLine = oLine.line[:iCommentIndex]
sLine = re.sub(r'\s+\)', r')', sLine)
sLine = sLine + oLine.line[iCommentIndex:]
oLine.update_line(sLine)