Skip to content

Commit 2291adb

Browse files
authored
Merge pull request #1493 from JHertz5/issue-1490
Issue#1490: Added whitespace rules for direction keywords
2 parents 3cc968d + 8403331 commit 2291adb

File tree

12 files changed

+288
-0
lines changed

12 files changed

+288
-0
lines changed

docs/configuring_whitespace_rules.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,5 @@ Rules Enforcing Whitespace
288288
* `variable_assignment_002 <variable_assignment_rules.html#variable-assignment-002>`_
289289
* `variable_assignment_003 <variable_assignment_rules.html#variable-assignment-003>`_
290290
* `whitespace_007 <whitespace_rules.html#whitespace-007>`_
291+
* `whitespace_102 <whitespace_rules.html#whitespace-102>`_
292+
* `whitespace_103 <whitespace_rules.html#whitespace-103>`_

docs/rule_groups/whitespace_rule_group.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,5 @@ Rules Enforcing Whitespace Rule Group
197197
* `whitespace_013 <../whitespace_rules.html#whitespace-013>`_
198198
* `whitespace_100 <../whitespace_rules.html#whitespace-100>`_
199199
* `whitespace_101 <../whitespace_rules.html#whitespace-101>`_
200+
* `whitespace_102 <../whitespace_rules.html#whitespace-102>`_
201+
* `whitespace_103 <../whitespace_rules.html#whitespace-103>`_

docs/whitespace_rules.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,52 @@ This rule checks for at least a single space before and after logical operators.
290290
if (a = '1') sll (b = '0')
291291
if (a = '0') rol (b = '1')
292292
293+
whitespace_102
294+
##############
295+
296+
|phase_2| |error| |whitespace|
297+
298+
This rule checks for a single space before direction keywords.
299+
300+
|configuring_whitespace_rules_link|
301+
302+
**Violation**
303+
304+
.. code-block:: vhdl
305+
306+
x <= y(7 downto 0);
307+
x <= y(0 to 7);
308+
309+
**Fix**
310+
311+
.. code-block:: vhdl
312+
313+
x <= y(7 downto 0);
314+
x <= y(0 to 7);
315+
316+
whitespace_103
317+
##############
318+
319+
|phase_2| |error| |whitespace|
320+
321+
This rule checks for a single space after direction keywords.
322+
323+
|configuring_whitespace_rules_link|
324+
325+
**Violation**
326+
327+
.. code-block:: vhdl
328+
329+
x <= y(7 downto 0);
330+
x <= y(0 to 7);
331+
332+
**Fix**
333+
334+
.. code-block:: vhdl
335+
336+
x <= y(7 downto 0);
337+
x <= y(0 to 7);
338+
293339
whitespace_200
294340
##############
295341

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
entity b is
3+
port (
4+
c : in std_logic_vector(7 downto 0)
5+
);
6+
end entity b;
7+
8+
architecture a of b is
9+
10+
type my_array2 is array (natural range 0 to 7) of std_logic_vector(7 downto 0);
11+
12+
subtype my_array3 is my_array2(open)(7 downto 0);
13+
14+
subtype my_array4 is natural range 0 to 7;
15+
16+
begin
17+
18+
x <= y(7 downto 0);
19+
20+
end architecture a;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
entity b is
3+
port (
4+
c : in std_logic_vector(7 downto 0)
5+
);
6+
end entity b;
7+
8+
architecture a of b is
9+
10+
type my_array2 is array (natural range 0 to 7) of std_logic_vector(7 downto 0);
11+
12+
subtype my_array3 is my_array2(open)(7 downto 0);
13+
14+
subtype my_array4 is natural range 0 to 7;
15+
16+
begin
17+
18+
x <= y(7 downto 0);
19+
20+
end architecture a;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
entity b is
3+
port (
4+
c : in std_logic_vector(7 downto 0)
5+
);
6+
end entity b;
7+
8+
architecture a of b is
9+
10+
type my_array2 is array (natural range 0 to 7) of std_logic_vector(7 downto 0);
11+
12+
subtype my_array3 is my_array2(open)(7 downto 0);
13+
14+
subtype my_array4 is natural range 0 to 7;
15+
16+
begin
17+
18+
x <= y(7 downto 0);
19+
20+
end architecture a;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
entity b is
3+
port (
4+
c : in std_logic_vector(7 downto 0)
5+
);
6+
end entity b;
7+
8+
architecture a of b is
9+
10+
type my_array2 is array (natural range 0 to 7) of std_logic_vector(7 downto 0);
11+
12+
subtype my_array3 is my_array2(open)(7 downto 0);
13+
14+
subtype my_array4 is natural range 0 to 7;
15+
16+
begin
17+
18+
x <= y(7 downto 0);
19+
20+
end architecture a;

tests/whitespace/test_rule_102.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import unittest
5+
6+
from tests import utils
7+
from vsg import vhdlFile
8+
from vsg.rules import whitespace
9+
10+
sTestDir = os.path.dirname(__file__)
11+
12+
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_102_test_input.vhd"))
13+
lExpected = []
14+
lExpected.append("")
15+
utils.read_file(os.path.join(sTestDir, "rule_102_test_input.fixed.vhd"), lExpected)
16+
17+
18+
class test_rule(unittest.TestCase):
19+
def setUp(self):
20+
self.oFile = vhdlFile.vhdlFile(lFile)
21+
self.assertIsNone(eError)
22+
23+
def test_rule_102(self):
24+
oRule = whitespace.rule_102()
25+
self.assertTrue(oRule)
26+
self.assertEqual(oRule.name, "whitespace")
27+
self.assertEqual(oRule.identifier, "102")
28+
29+
lExpected = [4, 10, 10, 12, 14, 18]
30+
31+
oRule.analyze(self.oFile)
32+
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
33+
34+
def test_fix_rule_102(self):
35+
oRule = whitespace.rule_102()
36+
37+
oRule.fix(self.oFile)
38+
39+
lActual = self.oFile.get_lines()
40+
41+
self.assertEqual(lExpected, lActual)
42+
43+
oRule.analyze(self.oFile)
44+
self.assertEqual(oRule.violations, [])

tests/whitespace/test_rule_103.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import os
4+
import unittest
5+
6+
from tests import utils
7+
from vsg import vhdlFile
8+
from vsg.rules import whitespace
9+
10+
sTestDir = os.path.dirname(__file__)
11+
12+
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_103_test_input.vhd"))
13+
lExpected = []
14+
lExpected.append("")
15+
utils.read_file(os.path.join(sTestDir, "rule_103_test_input.fixed.vhd"), lExpected)
16+
17+
18+
class test_rule(unittest.TestCase):
19+
def setUp(self):
20+
self.oFile = vhdlFile.vhdlFile(lFile)
21+
self.assertIsNone(eError)
22+
23+
def test_rule_103(self):
24+
oRule = whitespace.rule_103()
25+
self.assertTrue(oRule)
26+
self.assertEqual(oRule.name, "whitespace")
27+
self.assertEqual(oRule.identifier, "103")
28+
29+
lExpected = [4, 10, 10, 12, 14, 18]
30+
31+
oRule.analyze(self.oFile)
32+
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
33+
34+
def test_fix_rule_103(self):
35+
oRule = whitespace.rule_103()
36+
37+
oRule.fix(self.oFile)
38+
39+
lActual = self.oFile.get_lines()
40+
41+
self.assertEqual(lExpected, lActual)
42+
43+
oRule.analyze(self.oFile)
44+
self.assertEqual(oRule.violations, [])

vsg/rules/whitespace/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
from .rule_013 import rule_013
1515
from .rule_100 import rule_100
1616
from .rule_101 import rule_101
17+
from .rule_102 import rule_102
18+
from .rule_103 import rule_103
1719
from .rule_200 import rule_200

0 commit comments

Comments
 (0)