diff --git a/docs/array_constraint_rules.rst b/docs/array_constraint_rules.rst index 7d6bddc9a..24b8e5523 100644 --- a/docs/array_constraint_rules.rst +++ b/docs/array_constraint_rules.rst @@ -3,6 +3,27 @@ Array Constraint Rules ---------------------- +array_constraint_100 +#################### + +|phase_2| |error| |whitespace| + +This rule checks for whitespace before the opening parenthesis. + +|configuring_whitespace_rules_link| + +**Violation** + +.. code-block:: vhdl + + subtype my_array3 is my_array2 (open)(7 downto 0); + +**Fix** + +.. code-block:: vhdl + + subtype my_array3 is my_array2(open)(7 downto 0); + array_constraint_500 #################### diff --git a/docs/configuring_whitespace_rules.rst b/docs/configuring_whitespace_rules.rst index eaf6afec6..bb9cc140a 100644 --- a/docs/configuring_whitespace_rules.rst +++ b/docs/configuring_whitespace_rules.rst @@ -122,6 +122,7 @@ Rules Enforcing Whitespace * `architecture_031 `_ * `architecture_032 `_ * `architecture_033 `_ +* `array_constraint_100 `_ * `assert_100 `_ * `assert_101 `_ * `assert_102 `_ @@ -212,6 +213,7 @@ Rules Enforcing Whitespace * `if_004 `_ * `if_005 `_ * `if_015 `_ +* `index_constraint_100 `_ * `index_subtype_definition_100 `_ * `index_subtype_definition_101 `_ * `instantiation_002 `_ diff --git a/docs/index_constraint_rules.rst b/docs/index_constraint_rules.rst new file mode 100644 index 000000000..6f6dd87f1 --- /dev/null +++ b/docs/index_constraint_rules.rst @@ -0,0 +1,25 @@ +.. include:: includes.rst + +Index Constraint Rules +---------------------- + +index_constraint_100 +#################### + +|phase_2| |error| |whitespace| + +This rule checks for whitespace before the opening parenthesis. + +|configuring_whitespace_rules_link| + +**Violation** + +.. code-block:: vhdl + + subtype my_array3 is my_array2(open) (7 downto 0); + +**Fix** + +.. code-block:: vhdl + + subtype my_array3 is my_array2(open)(7 downto 0); diff --git a/docs/rule_groups/whitespace_rule_group.rst b/docs/rule_groups/whitespace_rule_group.rst index 3f6304dcf..ac52e45e4 100644 --- a/docs/rule_groups/whitespace_rule_group.rst +++ b/docs/rule_groups/whitespace_rule_group.rst @@ -15,6 +15,7 @@ Rules Enforcing Whitespace Rule Group * `architecture_031 <../architecture_rules.html#architecture-031>`_ * `architecture_032 <../architecture_rules.html#architecture-032>`_ * `architecture_033 <../architecture_rules.html#architecture-033>`_ +* `array_constraint_100 <../array_constraint_rules.html#array-constraint-100>`_ * `assert_100 <../assert_rules.html#assert-100>`_ * `assert_101 <../assert_rules.html#assert-101>`_ * `assert_102 <../assert_rules.html#assert-102>`_ @@ -106,6 +107,7 @@ Rules Enforcing Whitespace Rule Group * `if_004 <../if_rules.html#if-004>`_ * `if_005 <../if_rules.html#if-005>`_ * `if_015 <../if_rules.html#if-015>`_ +* `index_constraint_100 <../index_constraint_rules.html#index-constraint-100>`_ * `index_subtype_definition_100 <../index_subtype_definition_rules.html#index-subtype-definition-100>`_ * `index_subtype_definition_101 <../index_subtype_definition_rules.html#index-subtype-definition-101>`_ * `instantiation_002 <../instantiation_rules.html#instantiation-002>`_ @@ -195,7 +197,6 @@ Rules Enforcing Whitespace Rule Group * `whitespace_005 <../whitespace_rules.html#whitespace-005>`_ * `whitespace_006 <../whitespace_rules.html#whitespace-006>`_ * `whitespace_007 <../whitespace_rules.html#whitespace-007>`_ -* `whitespace_008 <../whitespace_rules.html#whitespace-008>`_ * `whitespace_010 <../whitespace_rules.html#whitespace-010>`_ * `whitespace_011 <../whitespace_rules.html#whitespace-011>`_ * `whitespace_013 <../whitespace_rules.html#whitespace-013>`_ diff --git a/docs/whitespace_rules.rst b/docs/whitespace_rules.rst index 1d991f507..3ce9c224e 100644 --- a/docs/whitespace_rules.rst +++ b/docs/whitespace_rules.rst @@ -157,23 +157,7 @@ This rule checks for spaces after a comma. whitespace_008 ############## -|phase_2| |error| |whitespace| - -This rule checks for spaces after the **std_logic_vector** keyword. - -**Violation** - -.. code-block:: vhdl - - signal data : std_logic_vector (7 downto 0); - signal counter : std_logic_vector (7 downto 0); - -**Fix** - -.. code-block:: vhdl - - signal data : std_logic_vector(7 downto 0); - signal counter : std_logic_vector(7 downto 0); +This rule has been deprecated and replaced with rule `index_constraint_100 `_. whitespace_010 ############## diff --git a/tests/array_constraint/rule_100_test_input.fixed.vhd b/tests/array_constraint/rule_100_test_input.fixed.vhd new file mode 100644 index 000000000..0b70d8697 --- /dev/null +++ b/tests/array_constraint/rule_100_test_input.fixed.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + subtype t_my_array is t_array(open)(t_range); + subtype t_my_array is t_array(open)(t_range); + subtype t_my_array is t_array(open)(t_range); + +begin + +end architecture rtl; diff --git a/tests/array_constraint/rule_100_test_input.vhd b/tests/array_constraint/rule_100_test_input.vhd new file mode 100644 index 000000000..4ea37c09e --- /dev/null +++ b/tests/array_constraint/rule_100_test_input.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + subtype t_my_array is t_array (open)(t_range); + subtype t_my_array is t_array (open)(t_range); + subtype t_my_array is t_array(open)(t_range); + +begin + +end architecture rtl; diff --git a/tests/array_constraint/test_rule_100.py b/tests/array_constraint/test_rule_100.py new file mode 100644 index 000000000..c083a3f37 --- /dev/null +++ b/tests/array_constraint/test_rule_100.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import array_constraint + +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 = array_constraint.rule_100() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "array_constraint") + self.assertEqual(oRule.identifier, "100") + + lExpected = [4, 5] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_100(self): + oRule = array_constraint.rule_100() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/index_constraint/__init__.py b/tests/index_constraint/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/index_constraint/rule_100_test_input.fixed.vhd b/tests/index_constraint/rule_100_test_input.fixed.vhd new file mode 100644 index 000000000..fa9355685 --- /dev/null +++ b/tests/index_constraint/rule_100_test_input.fixed.vhd @@ -0,0 +1,19 @@ + +entity fifo is + port ( + i_data : in signed(15 downto 0); + i_data : in signed(15 downto 0); + i_data : in signed(15 downto 0) + ); +end entity fifo; + + +architecture rtl of fifo is + + subtype t_my_array is t_array(open)(t_range); + subtype t_my_array is t_array(open)(t_range); + subtype t_my_array is t_array(open)(t_range); + +begin + +end architecture rtl; diff --git a/tests/index_constraint/rule_100_test_input.vhd b/tests/index_constraint/rule_100_test_input.vhd new file mode 100644 index 000000000..092d51965 --- /dev/null +++ b/tests/index_constraint/rule_100_test_input.vhd @@ -0,0 +1,19 @@ + +entity fifo is + port ( + i_data : in signed (15 downto 0); + i_data : in signed (15 downto 0); + i_data : in signed(15 downto 0) + ); +end entity fifo; + + +architecture rtl of fifo is + + subtype t_my_array is t_array(open) (t_range); + subtype t_my_array is t_array(open) (t_range); + subtype t_my_array is t_array(open)(t_range); + +begin + +end architecture rtl; diff --git a/tests/index_constraint/test_rule_100.py b/tests/index_constraint/test_rule_100.py new file mode 100644 index 000000000..0aca5faf8 --- /dev/null +++ b/tests/index_constraint/test_rule_100.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import index_constraint + +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 = index_constraint.rule_100() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "index_constraint") + self.assertEqual(oRule.identifier, "100") + + lExpected = [4, 5, 13, 14] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_100(self): + oRule = index_constraint.rule_100() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/tests/rule_list/extract_violation_dictionary_w_all_phases_enabled.json b/tests/rule_list/extract_violation_dictionary_w_all_phases_enabled.json index cf49e7b70..ee38b0576 100644 --- a/tests/rule_list/extract_violation_dictionary_w_all_phases_enabled.json +++ b/tests/rule_list/extract_violation_dictionary_w_all_phases_enabled.json @@ -2646,6 +2646,60 @@ "severity": "Error", "solution": "Insert blank line above" }, + { + "rule": "index_constraint_100", + "linenumber": 191, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, + { + "rule": "index_constraint_100", + "linenumber": 195, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, + { + "rule": "index_constraint_100", + "linenumber": 202, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, + { + "rule": "index_constraint_100", + "linenumber": 207, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, + { + "rule": "index_constraint_100", + "linenumber": 243, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, + { + "rule": "index_constraint_100", + "linenumber": 244, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, + { + "rule": "index_constraint_100", + "linenumber": 248, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, + { + "rule": "index_constraint_100", + "linenumber": 260, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, + { + "rule": "index_constraint_100", + "linenumber": 261, + "severity": "Error", + "solution": "Change the number of space(s) between std_logic_vector and ( to 0" + }, { "rule": "length_001", "linenumber": 12, @@ -5250,60 +5304,6 @@ "severity": "Error", "solution": "Remove spaces before close )." }, - { - "rule": "whitespace_008", - "linenumber": 191, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, - { - "rule": "whitespace_008", - "linenumber": 195, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, - { - "rule": "whitespace_008", - "linenumber": 202, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, - { - "rule": "whitespace_008", - "linenumber": 207, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, - { - "rule": "whitespace_008", - "linenumber": 243, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, - { - "rule": "whitespace_008", - "linenumber": 244, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, - { - "rule": "whitespace_008", - "linenumber": 248, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, - { - "rule": "whitespace_008", - "linenumber": 260, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, - { - "rule": "whitespace_008", - "linenumber": 261, - "severity": "Error", - "solution": "Remove spaces after std_logic_vector" - }, { "rule": "whitespace_011", "linenumber": 191, diff --git a/tests/styles/jcl/PIC.fixed.vhd b/tests/styles/jcl/PIC.fixed.vhd index bd000f4de..093a1121b 100644 --- a/tests/styles/jcl/PIC.fixed.vhd +++ b/tests/styles/jcl/PIC.fixed.vhd @@ -67,7 +67,7 @@ architecture BEHAVIORAL of PIC is signal int_type : unsigned(1 downto 0) := "01"; signal int_index, count_cmd : integer := 0; - type prior_table is array (0 to 7) of unsigned(2 downto 0); + type prior_table is array(0 to 7) of unsigned(2 downto 0); signal pt : prior_table := (others => (others => '0')); signal int_pt : unsigned(2 downto 0) := "000"; diff --git a/tests/styles/jcl/graphicsaccelerator/FrameBuffer2.fixed.vhd b/tests/styles/jcl/graphicsaccelerator/FrameBuffer2.fixed.vhd index cd574665c..6073ecddf 100644 --- a/tests/styles/jcl/graphicsaccelerator/FrameBuffer2.fixed.vhd +++ b/tests/styles/jcl/graphicsaccelerator/FrameBuffer2.fixed.vhd @@ -19,7 +19,7 @@ end entity FRAMEBUFFER; architecture BEHAVIORAL of FRAMEBUFFER is - type fbuffer is array (0 to 524288 / 16 - 1) of std_logic_vector(2 downto 0); + type fbuffer is array(0 to 524288 / 16 - 1) of std_logic_vector(2 downto 0); impure function initfb return fbuffer is diff --git a/tests/whitespace/rule_008_test_input.fixed.vhd b/tests/whitespace/rule_008_test_input.fixed.vhd deleted file mode 100644 index ed19cb33c..000000000 --- a/tests/whitespace/rule_008_test_input.fixed.vhd +++ /dev/null @@ -1,32 +0,0 @@ - -entity FIFO is - port ( - READ : std_logic_vector(3 downto 0) - ); -end; - - -architecture RTL of FIFO is - - signal data : std_logic_vector(3 downto 0); - -begin - -end architecture RTL; - --- Violations below - -entity FIFO is - port ( - READ : std_logic_vector(3 downto 0) - ); -end; - - -architecture RTL of FIFO is - - signal data : std_logic_vector(3 downto 0); - -begin - -end architecture RTL; diff --git a/tests/whitespace/rule_008_test_input.vhd b/tests/whitespace/rule_008_test_input.vhd deleted file mode 100644 index dc31d675b..000000000 --- a/tests/whitespace/rule_008_test_input.vhd +++ /dev/null @@ -1,32 +0,0 @@ - -entity FIFO is - port ( - READ : std_logic_vector(3 downto 0) - ); -end; - - -architecture RTL of FIFO is - - signal data : std_logic_vector(3 downto 0); - -begin - -end architecture RTL; - --- Violations below - -entity FIFO is - port ( - READ : std_logic_vector (3 downto 0) - ); -end; - - -architecture RTL of FIFO is - - signal data : std_logic_vector (3 downto 0); - -begin - -end architecture RTL; diff --git a/tests/whitespace/test_rule_008.py b/tests/whitespace/test_rule_008.py index cf1611eac..4ae478bf6 100644 --- a/tests/whitespace/test_rule_008.py +++ b/tests/whitespace/test_rule_008.py @@ -1,45 +1,14 @@ # -*- 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_008_test_input.vhd")) -lExpected = [] -lExpected.append("") -utils.read_file(os.path.join(sTestDir, "rule_008_test_input.fixed.vhd"), lExpected) - class test_rule(unittest.TestCase): - def setUp(self): - self.oFile = vhdlFile.vhdlFile(lFile) - self.assertIsNone(eError) - def test_rule_008(self): oRule = whitespace.rule_008() self.assertTrue(oRule) self.assertEqual(oRule.name, "whitespace") self.assertEqual(oRule.identifier, "008") - self.assertEqual(oRule.groups, ["whitespace"]) - - lExpected = [21, 28] - - oRule.analyze(self.oFile) - self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) - - def test_fix_rule_008(self): - oRule = whitespace.rule_008() - - oRule.fix(self.oFile) - - lActual = self.oFile.get_lines() - - self.assertEqual(lExpected, lActual) - - oRule.analyze(self.oFile) - self.assertEqual(oRule.violations, []) + self.assertTrue(oRule.deprecated) diff --git a/vsg/rules/__init__.py b/vsg/rules/__init__.py index aad0a093e..d56d42e43 100644 --- a/vsg/rules/__init__.py +++ b/vsg/rules/__init__.py @@ -154,6 +154,7 @@ from vsg.rules import ieee from vsg.rules import if_statement from vsg.rules import if_generate_statement +from vsg.rules import index_constraint from vsg.rules import index_subtype_definition from vsg.rules import instantiation from vsg.rules import interface_incomplete_type_declaration diff --git a/vsg/rules/array_constraint/__init__.py b/vsg/rules/array_constraint/__init__.py index c5c1c6e60..977654aa0 100644 --- a/vsg/rules/array_constraint/__init__.py +++ b/vsg/rules/array_constraint/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- +from .rule_100 import rule_100 from .rule_500 import rule_500 diff --git a/vsg/rules/array_constraint/rule_100.py b/vsg/rules/array_constraint/rule_100.py new file mode 100644 index 000000000..7d1fee413 --- /dev/null +++ b/vsg/rules/array_constraint/rule_100.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules.whitespace_before_token import Rule + +lTokens = [] +lTokens.append(token.array_constraint.open_parenthesis) + + +class rule_100(Rule): + """ + This rule checks for whitespace before the opening parenthesis. + + |configuring_whitespace_rules_link| + + **Violation** + + .. code-block:: vhdl + + subtype my_array3 is my_array2 (open)(7 downto 0); + + **Fix** + + .. code-block:: vhdl + + subtype my_array3 is my_array2(open)(7 downto 0); + """ + + def __init__(self): + super().__init__(lTokens) + self.number_of_spaces = 0 diff --git a/vsg/rules/index_constraint/__init__.py b/vsg/rules/index_constraint/__init__.py new file mode 100644 index 000000000..03df9542d --- /dev/null +++ b/vsg/rules/index_constraint/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from .rule_100 import rule_100 diff --git a/vsg/rules/index_constraint/rule_100.py b/vsg/rules/index_constraint/rule_100.py new file mode 100644 index 000000000..b7a1ba829 --- /dev/null +++ b/vsg/rules/index_constraint/rule_100.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules.whitespace_before_token import Rule + +lTokens = [] +lTokens.append(token.index_constraint.open_parenthesis) + + +class rule_100(Rule): + """ + This rule checks for whitespace before the opening parenthesis. + + |configuring_whitespace_rules_link| + + **Violation** + + .. code-block:: vhdl + + subtype my_array3 is my_array2(open) (7 downto 0); + + **Fix** + + .. code-block:: vhdl + + subtype my_array3 is my_array2(open)(7 downto 0); + """ + + def __init__(self): + super().__init__(lTokens) + self.number_of_spaces = 0 diff --git a/vsg/rules/whitespace/rule_008.py b/vsg/rules/whitespace/rule_008.py index b3119bb5d..11659d674 100644 --- a/vsg/rules/whitespace/rule_008.py +++ b/vsg/rules/whitespace/rule_008.py @@ -1,50 +1,13 @@ # -*- coding: utf-8 -*- -from vsg import parser, violation -from vsg.rule_group import whitespace -from vsg.vhdlFile import utils +from vsg.deprecated_rule import Rule -class rule_008(whitespace.Rule): +class rule_008(Rule): """ - This rule checks for spaces after the **std_logic_vector** keyword. - - **Violation** - - .. code-block:: vhdl - - signal data : std_logic_vector (7 downto 0); - signal counter : std_logic_vector (7 downto 0); - - **Fix** - - .. code-block:: vhdl - - signal data : std_logic_vector(7 downto 0); - signal counter : std_logic_vector(7 downto 0); + This rule has been deprecated and replaced with rule `index_constraint_100 `_. """ def __init__(self): - super().__init__() - self.solution = "Remove spaces after std_logic_vector" - self.configuration_documentation_link = None - - def _get_tokens_of_interest(self, oFile): - return [oFile.get_all_tokens()] - - def _analyze(self, lToi): - oToi = lToi[0] - iLine, lTokens = utils.get_toi_parameters(oToi) - for iToken, oToken in enumerate(lTokens[: len(lTokens) - 2]): - iLine = utils.increment_line_number(iLine, oToken) - - if oToken.get_lower_value() == "std_logic_vector": - if utils.are_next_consecutive_token_types([parser.whitespace, parser.open_parenthesis], iToken + 1, lTokens): - lExtractedTokens = oToi.extract_tokens(iToken, iToken + 1) - oViolation = violation.New(iLine, lExtractedTokens, self.solution) - self.add_violation(oViolation) - - def _fix_violation(self, oViolation): - lTokens = oViolation.get_tokens() - lTokens.pop() - oViolation.set_tokens(lTokens) + Rule.__init__(self) + self.message.append("Rule " + self.unique_id + " has been replaced with index_constraint_100.")