Skip to content

Commit a26f66b

Browse files
authored
Merge pull request #1495 from JHertz5/issue-1492
Issue#1492: New rules to handle whitespace in array definitions
2 parents cb4eb92 + dabc7b2 commit a26f66b

26 files changed

+623
-0
lines changed

docs/configuring_whitespace_rules.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ Rules Enforcing Whitespace
161161
* `constant_010 <constant_rules.html#constant-010>`_
162162
* `constant_100 <constant_rules.html#constant-100>`_
163163
* `constant_101 <constant_rules.html#constant-101>`_
164+
* `constrained_array_definition_100 <constrained_array_definition_rules.html#constrained-array-definition-100>`_
165+
* `constrained_array_definition_101 <constrained_array_definition_rules.html#constrained-array-definition-101>`_
164166
* `context_002 <context_rules.html#context-002>`_
165167
* `context_017 <context_rules.html#context-017>`_
166168
* `context_018 <context_rules.html#context-018>`_
@@ -285,6 +287,9 @@ Rules Enforcing Whitespace
285287
* `type_006 <type_rules.html#type-006>`_
286288
* `type_007 <type_rules.html#type-007>`_
287289
* `type_100 <type_rules.html#type-100>`_
290+
* `unbounded_array_definition_100 <unbounded_array_definition_rules.html#unbounded-array-definition-100>`_
291+
* `unbounded_array_definition_101 <unbounded_array_definition_rules.html#unbounded-array-definition-101>`_
292+
* `unbounded_array_definition_102 <unbounded_array_definition_rules.html#unbounded-array-definition-102>`_
288293
* `variable_005 <variable_rules.html#variable-005>`_
289294
* `variable_006 <variable_rules.html#variable-006>`_
290295
* `variable_100 <variable_rules.html#variable-100>`_

docs/constrained_array_definition_rules.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,48 @@
33
Constrained Array Definition Rules
44
----------------------------------
55

6+
constrained_array_definition_100
7+
################################
8+
9+
|phase_2| |error| |whitespace|
10+
11+
This rule checks for a single space before the **of** keyword.
12+
13+
|configuring_whitespace_rules_link|
14+
15+
**Violation**
16+
17+
.. code-block:: vhdl
18+
19+
type t_u_array is array(1 downto 0) of unsigned;
20+
21+
**Fix**
22+
23+
.. code-block:: vhdl
24+
25+
type t_u_array is array(1 downto 0) of unsigned;
26+
27+
constrained_array_definition_101
28+
################################
29+
30+
|phase_2| |error| |whitespace|
31+
32+
This rule checks for a single space after the **of** keyword.
33+
34+
|configuring_whitespace_rules_link|
35+
36+
**Violation**
37+
38+
.. code-block:: vhdl
39+
40+
type t_u_array is array(1 downto 0) of unsigned;
41+
42+
**Fix**
43+
44+
.. code-block:: vhdl
45+
46+
type t_u_array is array(1 downto 0) of unsigned;
47+
648
constrained_array_definition_500
749
################################
850

docs/rule_groups/whitespace_rule_group.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Rules Enforcing Whitespace Rule Group
5555
* `constant_010 <../constant_rules.html#constant-010>`_
5656
* `constant_100 <../constant_rules.html#constant-100>`_
5757
* `constant_101 <../constant_rules.html#constant-101>`_
58+
* `constrained_array_definition_100 <../constrained_array_definition_rules.html#constrained-array-definition-100>`_
59+
* `constrained_array_definition_101 <../constrained_array_definition_rules.html#constrained-array-definition-101>`_
5860
* `context_002 <../context_rules.html#context-002>`_
5961
* `context_017 <../context_rules.html#context-017>`_
6062
* `context_018 <../context_rules.html#context-018>`_
@@ -182,6 +184,9 @@ Rules Enforcing Whitespace Rule Group
182184
* `type_006 <../type_rules.html#type-006>`_
183185
* `type_007 <../type_rules.html#type-007>`_
184186
* `type_100 <../type_rules.html#type-100>`_
187+
* `unbounded_array_definition_100 <../unbounded_array_definition_rules.html#unbounded-array-definition-100>`_
188+
* `unbounded_array_definition_101 <../unbounded_array_definition_rules.html#unbounded-array-definition-101>`_
189+
* `unbounded_array_definition_102 <../unbounded_array_definition_rules.html#unbounded-array-definition-102>`_
185190
* `variable_005 <../variable_rules.html#variable-005>`_
186191
* `variable_006 <../variable_rules.html#variable-006>`_
187192
* `variable_100 <../variable_rules.html#variable-100>`_

docs/unbounded_array_definition_rules.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,71 @@
33
Unbounded Array Definition Rules
44
--------------------------------
55

6+
unbounded_array_definition_100
7+
##############################
8+
9+
|phase_2| |error| |whitespace|
10+
11+
This rule checks for whitespace after the **array** keyword.
12+
13+
|configuring_whitespace_rules_link|
14+
15+
**Violation**
16+
17+
.. code-block:: vhdl
18+
19+
type t_u_array_unconstrained is array (natural range <>) of unsigned;
20+
type t_u_array_unconstrained is array (natural range <>) of unsigned;
21+
22+
**Fix**
23+
24+
.. code-block:: vhdl
25+
26+
type t_u_array_unconstrained is array(natural range <>) of unsigned;
27+
type t_u_array_unconstrained is array(natural range <>) of unsigned;
28+
29+
unbounded_array_definition_101
30+
##############################
31+
32+
|phase_2| |error| |whitespace|
33+
34+
This rule checks for a single space before the **of** keyword.
35+
36+
|configuring_whitespace_rules_link|
37+
38+
**Violation**
39+
40+
.. code-block:: vhdl
41+
42+
type t_u_array_unconstrained is array(natural range <>) of unsigned;
43+
44+
**Fix**
45+
46+
.. code-block:: vhdl
47+
48+
type t_u_array_unconstrained is array(natural range <>) of unsigned;
49+
50+
unbounded_array_definition_102
51+
##############################
52+
53+
|phase_2| |error| |whitespace|
54+
55+
This rule checks for a single space after the **of** keyword.
56+
57+
|configuring_whitespace_rules_link|
58+
59+
**Violation**
60+
61+
.. code-block:: vhdl
62+
63+
type t_u_array_unconstrained is array(natural range <>) of unsigned;
64+
65+
**Fix**
66+
67+
.. code-block:: vhdl
68+
69+
type t_u_array_unconstrained is array(natural range <>) of unsigned;
70+
671
unbounded_array_definition_500
772
##############################
873

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
architecture RTL of FIFO is
3+
4+
type my_array is array(natural range 0 to 7) of std_logic_vector(7 downto 0);
5+
type my_array is array(natural range 0 to 7) of std_logic_vector(7 downto 0);
6+
7+
type my_array is array(0 to 7) of std_logic_vector(7 downto 0);
8+
type my_array is array(0 to 7) of std_logic_vector(7 downto 0);
9+
10+
begin
11+
12+
end architecture RTL;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
architecture RTL of FIFO is
3+
4+
type my_array is array(natural range 0 to 7) of std_logic_vector(7 downto 0);
5+
type my_array is array(natural range 0 to 7) of std_logic_vector(7 downto 0);
6+
7+
type my_array is array(0 to 7) of std_logic_vector(7 downto 0);
8+
type my_array is array(0 to 7) of std_logic_vector(7 downto 0);
9+
10+
begin
11+
12+
end architecture RTL;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
architecture RTL of FIFO is
3+
4+
type my_array is array(natural range 0 to 7) of std_logic_vector(7 downto 0);
5+
type my_array is array(natural range 0 to 7) of std_logic_vector(7 downto 0);
6+
7+
type my_array is array(0 to 7) of std_logic_vector(7 downto 0);
8+
type my_array is array(0 to 7) of std_logic_vector(7 downto 0);
9+
10+
begin
11+
12+
end architecture RTL;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
architecture RTL of FIFO is
3+
4+
type my_array is array(natural range 0 to 7) of std_logic_vector(7 downto 0);
5+
type my_array is array(natural range 0 to 7) of std_logic_vector(7 downto 0);
6+
7+
type my_array is array(0 to 7) of std_logic_vector(7 downto 0);
8+
type my_array is array(0 to 7) of std_logic_vector(7 downto 0);
9+
10+
begin
11+
12+
end architecture RTL;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 constrained_array_definition
9+
10+
sTestDir = os.path.dirname(__file__)
11+
12+
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_100_test_input.vhd"))
13+
14+
dIndentMap = utils.read_indent_file()
15+
16+
lExpected = []
17+
lExpected.append("")
18+
utils.read_file(os.path.join(sTestDir, "rule_100_test_input.fixed.vhd"), lExpected)
19+
20+
21+
class test_rule(unittest.TestCase):
22+
def setUp(self):
23+
self.oFile = vhdlFile.vhdlFile(lFile)
24+
self.assertIsNone(eError)
25+
self.oFile.set_indent_map(dIndentMap)
26+
27+
def test_rule_100(self):
28+
oRule = constrained_array_definition.rule_100()
29+
self.assertTrue(oRule)
30+
self.assertEqual(oRule.name, "constrained_array_definition")
31+
self.assertEqual(oRule.identifier, "100")
32+
33+
lExpected = [4, 7]
34+
35+
oRule.analyze(self.oFile)
36+
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
37+
38+
def test_fix_rule_100(self):
39+
oRule = constrained_array_definition.rule_100()
40+
41+
oRule.fix(self.oFile)
42+
43+
lActual = self.oFile.get_lines()
44+
45+
self.assertEqual(lExpected, lActual)
46+
47+
oRule.analyze(self.oFile)
48+
self.assertEqual(oRule.violations, [])
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 constrained_array_definition
9+
10+
sTestDir = os.path.dirname(__file__)
11+
12+
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_101_test_input.vhd"))
13+
14+
dIndentMap = utils.read_indent_file()
15+
16+
lExpected = []
17+
lExpected.append("")
18+
utils.read_file(os.path.join(sTestDir, "rule_101_test_input.fixed.vhd"), lExpected)
19+
20+
21+
class test_rule(unittest.TestCase):
22+
def setUp(self):
23+
self.oFile = vhdlFile.vhdlFile(lFile)
24+
self.assertIsNone(eError)
25+
self.oFile.set_indent_map(dIndentMap)
26+
27+
def test_rule_101(self):
28+
oRule = constrained_array_definition.rule_101()
29+
self.assertTrue(oRule)
30+
self.assertEqual(oRule.name, "constrained_array_definition")
31+
self.assertEqual(oRule.identifier, "101")
32+
33+
lExpected = [4, 7]
34+
35+
oRule.analyze(self.oFile)
36+
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
37+
38+
def test_fix_rule_101(self):
39+
oRule = constrained_array_definition.rule_101()
40+
41+
oRule.fix(self.oFile)
42+
43+
lActual = self.oFile.get_lines()
44+
45+
self.assertEqual(lExpected, lActual)
46+
47+
oRule.analyze(self.oFile)
48+
self.assertEqual(oRule.violations, [])

0 commit comments

Comments
 (0)