Skip to content

Commit 955408c

Browse files
authored
Merge pull request #1494 from JHertz5/issue-1491
Issue#1491: New rules to handle whitespace around range keywords
2 parents 2291adb + 533c565 commit 955408c

24 files changed

+546
-2
lines changed

docs/configuring_whitespace_rules.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ Rules Enforcing Whitespace
212212
* `if_004 <if_rules.html#if-004>`_
213213
* `if_005 <if_rules.html#if-005>`_
214214
* `if_015 <if_rules.html#if-015>`_
215+
* `index_subtype_definition_100 <index_subtype_definition_rules.html#index-subtype-definition-100>`_
216+
* `index_subtype_definition_101 <index_subtype_definition_rules.html#index-subtype-definition-101>`_
215217
* `instantiation_002 <instantiation_rules.html#instantiation-002>`_
216218
* `instantiation_003 <instantiation_rules.html#instantiation-003>`_
217219
* `instantiation_032 <instantiation_rules.html#instantiation-032>`_
@@ -249,6 +251,8 @@ Rules Enforcing Whitespace
249251
* `process_014 <process_rules.html#process-014>`_
250252
* `process_024 <process_rules.html#process-024>`_
251253
* `process_025 <process_rules.html#process-025>`_
254+
* `range_constraint_100 <range_constraint_rules.html#range-constraint-100>`_
255+
* `range_constraint_101 <range_constraint_rules.html#range-constraint-101>`_
252256
* `record_type_definition_100 <record_type_definition_rules.html#record-type-definition-100>`_
253257
* `record_type_definition_101 <record_type_definition_rules.html#record-type-definition-101>`_
254258
* `report_statement_100 <report_statement_rules.html#report-statement-100>`_

docs/index_subtype_definition_rules.rst

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

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

docs/range_constraint_rules.rst

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

6+
range_constraint_100
7+
####################
8+
9+
|phase_2| |error| |whitespace|
10+
11+
This rule checks for a single space before the **range** keyword.
12+
13+
|configuring_whitespace_rules_link|
14+
15+
**Violation**
16+
17+
.. code-block:: vhdl
18+
19+
subtype my_range is natural range 0 to 7;
20+
21+
**Fix**
22+
23+
.. code-block:: vhdl
24+
25+
subtype my_range is natural range 0 to 7;
26+
27+
range_constraint_101
28+
####################
29+
30+
|phase_2| |error| |whitespace|
31+
32+
This rule checks for a single space after the **range** keyword.
33+
34+
|configuring_whitespace_rules_link|
35+
36+
**Violation**
37+
38+
.. code-block:: vhdl
39+
40+
subtype my_range is natural range 0 to 7;
41+
42+
**Fix**
43+
44+
.. code-block:: vhdl
45+
46+
subtype my_range is natural range 0 to 7;
47+
648
range_constraint_500
749
####################
850

docs/rule_groups/whitespace_rule_group.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ Rules Enforcing Whitespace Rule Group
106106
* `if_004 <../if_rules.html#if-004>`_
107107
* `if_005 <../if_rules.html#if-005>`_
108108
* `if_015 <../if_rules.html#if-015>`_
109+
* `index_subtype_definition_100 <../index_subtype_definition_rules.html#index-subtype-definition-100>`_
110+
* `index_subtype_definition_101 <../index_subtype_definition_rules.html#index-subtype-definition-101>`_
109111
* `instantiation_002 <../instantiation_rules.html#instantiation-002>`_
110112
* `instantiation_003 <../instantiation_rules.html#instantiation-003>`_
111113
* `instantiation_032 <../instantiation_rules.html#instantiation-032>`_
@@ -146,6 +148,8 @@ Rules Enforcing Whitespace Rule Group
146148
* `process_014 <../process_rules.html#process-014>`_
147149
* `process_024 <../process_rules.html#process-024>`_
148150
* `process_025 <../process_rules.html#process-025>`_
151+
* `range_constraint_100 <../range_constraint_rules.html#range-constraint-100>`_
152+
* `range_constraint_101 <../range_constraint_rules.html#range-constraint-101>`_
149153
* `record_type_definition_100 <../record_type_definition_rules.html#record-type-definition-100>`_
150154
* `record_type_definition_101 <../record_type_definition_rules.html#record-type-definition-101>`_
151155
* `report_statement_100 <../report_statement_rules.html#report-statement-100>`_
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
architecture RTL of FIFO is
3+
4+
-- Passing
5+
6+
type my_array is array (natural range <>) of std_logic_vector(7 downto 0);
7+
8+
-- Violation below
9+
10+
type my_array is array (natural range <>) of std_logic_vector(7 downto 0);
11+
12+
begin
13+
14+
end architecture RTL;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
architecture RTL of FIFO is
3+
4+
-- Passing
5+
6+
type my_array is array (natural range <>) of std_logic_vector(7 downto 0);
7+
8+
-- Violation below
9+
10+
type my_array is array (natural range <>) of std_logic_vector(7 downto 0);
11+
12+
begin
13+
14+
end architecture RTL;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
architecture RTL of FIFO is
3+
4+
-- Passing
5+
6+
type my_array is array (natural range <>) of std_logic_vector(7 downto 0);
7+
8+
-- Violation below
9+
10+
type my_array is array (natural range <>) of std_logic_vector(7 downto 0);
11+
12+
begin
13+
14+
end architecture RTL;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
architecture RTL of FIFO is
3+
4+
-- Passing
5+
6+
type my_array is array (natural range <>) of std_logic_vector(7 downto 0);
7+
8+
-- Violation below
9+
10+
type my_array is array (natural range <>) of std_logic_vector(7 downto 0);
11+
12+
begin
13+
14+
end architecture RTL;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 index_subtype_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+
lExpected = []
15+
lExpected.append("")
16+
utils.read_file(os.path.join(sTestDir, "rule_100_test_input.fixed.vhd"), lExpected)
17+
18+
19+
class test_rule(unittest.TestCase):
20+
def setUp(self):
21+
self.oFile = vhdlFile.vhdlFile(lFile)
22+
self.assertIsNone(eError)
23+
24+
def test_rule_100(self):
25+
oRule = index_subtype_definition.rule_100()
26+
self.assertTrue(oRule)
27+
self.assertEqual(oRule.name, "index_subtype_definition")
28+
self.assertEqual(oRule.identifier, "100")
29+
30+
lExpected = [10]
31+
32+
oRule.analyze(self.oFile)
33+
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
34+
35+
def test_fix_rule_100(self):
36+
oRule = index_subtype_definition.rule_100()
37+
38+
oRule.fix(self.oFile)
39+
40+
lActual = self.oFile.get_lines()
41+
42+
self.assertEqual(lExpected, lActual)
43+
44+
oRule.analyze(self.oFile)
45+
self.assertEqual(oRule.violations, [])
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 index_subtype_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+
lExpected = []
15+
lExpected.append("")
16+
utils.read_file(os.path.join(sTestDir, "rule_101_test_input.fixed.vhd"), lExpected)
17+
18+
19+
class test_rule(unittest.TestCase):
20+
def setUp(self):
21+
self.oFile = vhdlFile.vhdlFile(lFile)
22+
self.assertIsNone(eError)
23+
24+
def test_rule_101(self):
25+
oRule = index_subtype_definition.rule_101()
26+
self.assertTrue(oRule)
27+
self.assertEqual(oRule.name, "index_subtype_definition")
28+
self.assertEqual(oRule.identifier, "101")
29+
30+
lExpected = [10]
31+
32+
oRule.analyze(self.oFile)
33+
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
34+
35+
def test_fix_rule_101(self):
36+
oRule = index_subtype_definition.rule_101()
37+
38+
oRule.fix(self.oFile)
39+
40+
lActual = self.oFile.get_lines()
41+
42+
self.assertEqual(lExpected, lActual)
43+
44+
oRule.analyze(self.oFile)
45+
self.assertEqual(oRule.violations, [])

0 commit comments

Comments
 (0)