Issue#1171: Adding rule whitespace_100 to enforce single spacing around relational operators. (#1172)
This commit is contained in:
parent
ba8bfa23e8
commit
aa7f10bd29
|
|
@ -150,3 +150,4 @@ Rules Enforcing Whitespace Rule Group
|
|||
* `whitespace_010 <../whitespace_rules.html#whitespace-010>`_
|
||||
* `whitespace_011 <../whitespace_rules.html#whitespace-011>`_
|
||||
* `whitespace_013 <../whitespace_rules.html#whitespace-013>`_
|
||||
* `whitespace_100 <../whitespace_rules.html#whitespace-013>`_
|
||||
|
|
|
|||
|
|
@ -248,6 +248,27 @@ This rule checks for at least a single space before and after logical operators.
|
|||
if (a = '1') and (b = '0')
|
||||
if (a = '0') or (b = '1')
|
||||
|
||||
whitespace_100
|
||||
##############
|
||||
|
||||
|phase_2| |error| |whitespace|
|
||||
|
||||
This rule checks for at least a single space before and after relational operators.
|
||||
|
||||
**Violation**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
if readAddr>=writeAddr then
|
||||
if readAddr >= writeAddr then
|
||||
|
||||
**Fix**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
if readAddr >= writeAddr then
|
||||
if readAddr >= writeAddr then
|
||||
|
||||
whitespace_200
|
||||
##############
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,7 @@ begin
|
|||
rr <= X"0000";
|
||||
ll <= X"0000";
|
||||
sp <= X"0000";
|
||||
elsif (CE = '1' and T2 = '1') then
|
||||
elsif (CE = '1' and T2 = '1') then
|
||||
if (WE_RR = '1') then
|
||||
rr <= zz;
|
||||
end if;
|
||||
|
|
|
|||
|
|
@ -93,21 +93,21 @@ begin
|
|||
p0_6 <= t_2neg_dx + dy;
|
||||
p0_7 <= t_2dx + neg_dy;
|
||||
p0_8 <= t_2neg_dy + dx;
|
||||
p_1 <= p + t_2dy when p(11)='1' else
|
||||
p_1 <= p + t_2dy when p(11) = '1' else
|
||||
p + t_2dy + t_2neg_dx;
|
||||
p_2 <= p + t_2dx when p(11)='1' else
|
||||
p_2 <= p + t_2dx when p(11) = '1' else
|
||||
p + t_2dx + t_2neg_dy;
|
||||
p_3 <= p + t_2neg_dx when p(11)='1' else
|
||||
p_3 <= p + t_2neg_dx when p(11) = '1' else
|
||||
p + t_2neg_dx + t_2neg_dy;
|
||||
p_4 <= p + t_2dy when p(11)='1' else
|
||||
p_4 <= p + t_2dy when p(11) = '1' else
|
||||
p + t_2dy + t_2dx;
|
||||
p_5 <= p + t_2neg_dy when p(11)='1' else
|
||||
p_5 <= p + t_2neg_dy when p(11) = '1' else
|
||||
p + t_2neg_dy + t_2dx;
|
||||
p_6 <= p + t_2neg_dx when p(11)='1' else
|
||||
p_6 <= p + t_2neg_dx when p(11) = '1' else
|
||||
p + t_2neg_dx + t_2dy;
|
||||
p_7 <= p + t_2dx when p(11)='1' else
|
||||
p_7 <= p + t_2dx when p(11) = '1' else
|
||||
p + t_2dx + t_2dy;
|
||||
p_8 <= p + t_2neg_dy when p(11)='1' else
|
||||
p_8 <= p + t_2neg_dy when p(11) = '1' else
|
||||
p + t_2neg_dy + t_2neg_dx;
|
||||
X <= ccounter(9 downto 0) when state = clear else
|
||||
myx1(9 downto 0);
|
||||
|
|
|
|||
|
|
@ -19,14 +19,14 @@ architecture BEHAVIORAL of DEBOUNCER is
|
|||
|
||||
begin
|
||||
|
||||
ncounter <= x"FFFFFF" when counter=x"FFFFFF" and BUTTON='1' else
|
||||
x"000000" when counter=x"000000" and BUTTON='0' else
|
||||
counter + 1 when BUTTON='1' else
|
||||
ncounter <= x"FFFFFF" when counter = x"FFFFFF" and BUTTON = '1' else
|
||||
x"000000" when counter = x"000000" and BUTTON = '0' else
|
||||
counter + 1 when BUTTON = '1' else
|
||||
counter - 1;
|
||||
nexthistory <= '0' when counter=x"000000" else
|
||||
nexthistory <= '0' when counter = x"000000" else
|
||||
'1';
|
||||
nbuttonhistory <= nexthistory & buttonhistory(1);
|
||||
DOUT <= '1' when buttonhistory="01" else
|
||||
DOUT <= '1' when buttonhistory = "01" else
|
||||
'0';
|
||||
|
||||
process (CLK) is
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ architecture BEHAVIORAL of POINTER is
|
|||
|
||||
begin
|
||||
|
||||
HERE <= '1' when SYNCX(9 downto 3)=rx(9 downto 3) and
|
||||
SYNCY(8 downto 3)=ry(8 downto 3) else
|
||||
HERE <= '1' when SYNCX(9 downto 3) = rx(9 downto 3) and
|
||||
SYNCY(8 downto 3) = ry(8 downto 3) else
|
||||
'0';
|
||||
X <= rx;
|
||||
Y <= ry;
|
||||
|
|
|
|||
|
|
@ -36,17 +36,17 @@ begin
|
|||
nx <= x + 1;
|
||||
ny <= y + 1;
|
||||
naddressofy <= addressofy + 1;
|
||||
HS <= '0' when xstate=tpw else
|
||||
HS <= '0' when xstate = tpw else
|
||||
'1';
|
||||
VS <= '0' when ystate=tpw else
|
||||
VS <= '0' when ystate = tpw else
|
||||
'1';
|
||||
enabledisplay <= '1' when xstate=tdp and ystate=tdp else
|
||||
enabledisplay <= '1' when xstate = tdp and ystate = tdp else
|
||||
'0';
|
||||
R <= DATAIN(0) when enabledisplay='1' else
|
||||
R <= DATAIN(0) when enabledisplay = '1' else
|
||||
'0';
|
||||
B <= DATAIN(1) when enabledisplay='1' else
|
||||
B <= DATAIN(1) when enabledisplay = '1' else
|
||||
'0';
|
||||
G <= DATAIN(2) when enabledisplay='1' else
|
||||
G <= DATAIN(2) when enabledisplay = '1' else
|
||||
'0';
|
||||
ADDRESSX <= x(10 downto 1);
|
||||
ADDRESSY <= addressofy - 30;
|
||||
|
|
@ -55,32 +55,32 @@ begin
|
|||
begin
|
||||
|
||||
if (CLK'event and CLK = '1') then
|
||||
if (xstate=tpw and x(7 downto 1)="1100000") then
|
||||
if (xstate = tpw and x(7 downto 1) = "1100000") then
|
||||
x <= (others => '0');
|
||||
xstate <= tbp;
|
||||
elsif (xstate=tbp and x(6 downto 1)="110000") then
|
||||
elsif (xstate = tbp and x(6 downto 1) = "110000") then
|
||||
x <= (others => '0');
|
||||
xstate <= tdp;
|
||||
elsif (xstate=tdp and x(10 downto 1)="1010000000") then
|
||||
elsif (xstate = tdp and x(10 downto 1) = "1010000000") then
|
||||
x <= (others => '0');
|
||||
xstate <= tfp;
|
||||
elsif (xstate=tfp and x(5 downto 1)="10000") then
|
||||
elsif (xstate = tfp and x(5 downto 1) = "10000") then
|
||||
x <= (others => '0');
|
||||
xstate <= tpw;
|
||||
addressofy <= naddressofy;
|
||||
else
|
||||
x <= nx;
|
||||
end if;
|
||||
if (ystate=tpw and y(12 downto 1)="11001000000") then
|
||||
if (ystate = tpw and y(12 downto 1) = "11001000000") then
|
||||
y <= (others => '0');
|
||||
ystate <= tbp;
|
||||
elsif (ystate=tbp and y(16 downto 1)="101101010100000") then
|
||||
elsif (ystate = tbp and y(16 downto 1) = "101101010100000") then
|
||||
y <= (others => '0');
|
||||
ystate <= tdp;
|
||||
elsif (ystate=tdp and y(20 downto 1)="1011101110000000000") then
|
||||
elsif (ystate = tdp and y(20 downto 1) = "1011101110000000000") then
|
||||
y <= (others => '0');
|
||||
ystate <= tfp;
|
||||
elsif (ystate=tfp and y(14 downto 1)="1111101000000") then
|
||||
elsif (ystate = tfp and y(14 downto 1) = "1111101000000") then
|
||||
y <= (others => '0');
|
||||
x <= (others => '0');
|
||||
ystate <= tpw;
|
||||
|
|
|
|||
|
|
@ -180,13 +180,13 @@ begin
|
|||
|
||||
LED <= bufferwrite;
|
||||
|
||||
R <= rt when (p1region='0' and p2region='0') else
|
||||
R <= rt when (p1region = '0' and p2region = '0') else
|
||||
not rt;
|
||||
|
||||
G <= gt when (p1region='0' and p2region='0') else
|
||||
G <= gt when (p1region = '0' and p2region = '0') else
|
||||
not gt;
|
||||
|
||||
B <= bt when (p1region='0' and p2region='0') else
|
||||
B <= bt when (p1region = '0' and p2region = '0') else
|
||||
not bt;
|
||||
|
||||
INST_SEVENSEGMENT : SEVENSEGMENT
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
|
||||
architecture RTL of FIFO is
|
||||
|
||||
begin
|
||||
|
||||
-- Passing
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- missing spaces after operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- missing spaces before operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- missing spaces before and after operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- extra spaces before operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- extra spaces after operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- extra spaces before and after operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
end architecture RTL;
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
|
||||
architecture RTL of FIFO is
|
||||
|
||||
begin
|
||||
|
||||
-- Passing
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- missing spaces after operator
|
||||
process begin
|
||||
if a =b then
|
||||
elsif a /=b then
|
||||
elsif a <b then
|
||||
elsif a <=b then
|
||||
elsif a >b then
|
||||
elsif a >=b then
|
||||
elsif a ?=b then
|
||||
elsif a ?/=b then
|
||||
elsif a ?<b then
|
||||
elsif a ?<=b then
|
||||
elsif a ?>b then
|
||||
elsif a ?>=b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- missing spaces before operator
|
||||
process begin
|
||||
if a= b then
|
||||
elsif a/= b then
|
||||
elsif a< b then
|
||||
elsif a<= b then
|
||||
elsif a> b then
|
||||
elsif a>= b then
|
||||
elsif a?= b then
|
||||
elsif a?/= b then
|
||||
elsif a?< b then
|
||||
elsif a?<= b then
|
||||
elsif a?> b then
|
||||
elsif a?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- missing spaces before and after operator
|
||||
process begin
|
||||
if a=b then
|
||||
elsif a/=b then
|
||||
elsif a<b then
|
||||
elsif a<=b then
|
||||
elsif a>b then
|
||||
elsif a>=b then
|
||||
elsif a?=b then
|
||||
elsif a?/=b then
|
||||
elsif a?<b then
|
||||
elsif a?<=b then
|
||||
elsif a?>b then
|
||||
elsif a?>=b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- extra spaces before operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- extra spaces after operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
-- extra spaces before and after operator
|
||||
process begin
|
||||
if a = b then
|
||||
elsif a /= b then
|
||||
elsif a < b then
|
||||
elsif a <= b then
|
||||
elsif a > b then
|
||||
elsif a >= b then
|
||||
elsif a ?= b then
|
||||
elsif a ?/= b then
|
||||
elsif a ?< b then
|
||||
elsif a ?<= b then
|
||||
elsif a ?> b then
|
||||
elsif a ?>= b then
|
||||
end if;
|
||||
end process;
|
||||
|
||||
end architecture RTL;
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from tests import utils
|
||||
from vsg import vhdlFile
|
||||
from vsg.rules import whitespace
|
||||
|
||||
sTestDir = os.path.dirname(__file__)
|
||||
|
||||
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_100_test_input.vhd"))
|
||||
lExpected = []
|
||||
lExpected.append("")
|
||||
utils.read_file(os.path.join(sTestDir, "rule_100_test_input.fixed.vhd"), lExpected)
|
||||
|
||||
|
||||
class test_rule(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.oFile = vhdlFile.vhdlFile(lFile)
|
||||
self.assertIsNone(eError)
|
||||
|
||||
def test_rule_100(self):
|
||||
oRule = whitespace.rule_100()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, "whitespace")
|
||||
self.assertEqual(oRule.identifier, "100")
|
||||
|
||||
lExpected = []
|
||||
lExpected.extend(range(25, 37))
|
||||
lExpected.extend(range(42, 54))
|
||||
lExpected.extend(range(59, 71))
|
||||
lExpected.extend(range(76, 88))
|
||||
lExpected.extend(range(93, 105))
|
||||
lExpected.extend(range(110, 122))
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
|
||||
|
||||
def test_fix_rule_100(self):
|
||||
oRule = whitespace.rule_100()
|
||||
|
||||
oRule.fix(self.oFile)
|
||||
|
||||
lActual = self.oFile.get_lines()
|
||||
|
||||
self.assertEqual(lExpected, lActual)
|
||||
|
||||
oRule.analyze(self.oFile)
|
||||
self.assertEqual(oRule.violations, [])
|
||||
|
|
@ -12,4 +12,5 @@ from .rule_010 import rule_010
|
|||
from .rule_011 import rule_011
|
||||
from .rule_012 import rule_012
|
||||
from .rule_013 import rule_013
|
||||
from .rule_100 import rule_100
|
||||
from .rule_200 import rule_200
|
||||
|
|
|
|||
|
|
@ -0,0 +1,43 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from vsg import token
|
||||
from vsg.rules import n_spaces_before_and_after_tokens
|
||||
|
||||
lTokens = []
|
||||
lTokens.append(token.relational_operator.equal)
|
||||
lTokens.append(token.relational_operator.not_equal)
|
||||
lTokens.append(token.relational_operator.less_than)
|
||||
lTokens.append(token.relational_operator.less_than_or_equal)
|
||||
lTokens.append(token.relational_operator.greater_than)
|
||||
lTokens.append(token.relational_operator.greater_than_or_equal)
|
||||
lTokens.append(token.relational_operator.question_equal)
|
||||
lTokens.append(token.relational_operator.question_not_equal)
|
||||
lTokens.append(token.relational_operator.question_less_than)
|
||||
lTokens.append(token.relational_operator.question_less_than_or_equal)
|
||||
lTokens.append(token.relational_operator.question_greater_than)
|
||||
lTokens.append(token.relational_operator.question_greater_than_or_equal)
|
||||
|
||||
|
||||
class rule_100(n_spaces_before_and_after_tokens):
|
||||
"""
|
||||
This rule checks for at least a single space before and after relational operators.
|
||||
|
||||
**Violation**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
if readAddr>=writeAddr then
|
||||
if readAddr >= writeAddr then
|
||||
|
||||
**Fix**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
if readAddr >= writeAddr then
|
||||
if readAddr >= writeAddr then
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(1, lTokens, bNIsMinimum=False)
|
||||
self.solution = "Ensure a single space before and after relational operator."
|
||||
self.configuration_documentation_link = None
|
||||
Loading…
Reference in New Issue