From c6a090e40f00fc0ee92a7f734d880abfb70f8180 Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 10:55:39 +0000 Subject: [PATCH 01/11] Issue#1330 Added rules for naming in package instantiations. --- vsg/rules/package_instantiation/rule_600.py | 35 ++++++++++++++++++++ vsg/rules/package_instantiation/rule_601.py | 36 +++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 vsg/rules/package_instantiation/rule_600.py create mode 100644 vsg/rules/package_instantiation/rule_601.py diff --git a/vsg/rules/package_instantiation/rule_600.py b/vsg/rules/package_instantiation/rule_600.py new file mode 100644 index 00000000..ae1a4be8 --- /dev/null +++ b/vsg/rules/package_instantiation/rule_600.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_suffix_between_tokens + +lTokens = [] +lTokens.append(token.identifier.identifier) + +oStart = token.package_instantiation_declaration.package_keyword +oEnd = token.package_instantiation_declaration.is_keyword + +class rule_600(token_suffix_between_tokens): + """ + This rule checks for valid suffixes on package identifiers. + The default package suffix is *_pkg*. + + |configuring_prefix_and_suffix_rules_link| + + **Violation** + + .. code-block:: vhdl + + package foo is new my_generic_pkg + + **Fix** + + .. code-block:: vhdl + + package foo_pkg is new my_generic_pkg + """ + + def __init__(self): + super().__init__(lTokens, oStart, oEnd) + self.suffixes = ["_pkg"] + self.solution = "Instantiated package identifier" diff --git a/vsg/rules/package_instantiation/rule_601.py b/vsg/rules/package_instantiation/rule_601.py new file mode 100644 index 00000000..557f156f --- /dev/null +++ b/vsg/rules/package_instantiation/rule_601.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_prefix_between_tokens + +lTokens = [] +lTokens.append(token.identifier.identifier) + +oStart = token.package_instantiation_declaration.package_keyword +oEnd = token.package_instantiation_declaration.is_keyword + + +class rule_601(token_prefix_between_tokens): + """ + This rule checks for valid prefixes on instantiated package identifiers. + The default package prefix is *pkg_*. + + |configuring_prefix_and_suffix_rules_link| + + **Violation** + + .. code-block:: vhdl + + package foo is new my_generic_pkg + + **Fix** + + .. code-block:: vhdl + + package pkg_foo is new my_generic_pkg + """ + + def __init__(self): + super().__init__(lTokens, oStart, oEnd) + self.prefixes = ["pkg_"] + # self.solution = "Instantiated package identifier" From b820d1f91476f648f01409ca4e7aa8f2d7910b9e Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 10:56:42 +0000 Subject: [PATCH 02/11] #1330: Update __init__.py in package_instantiation. --- vsg/rules/package_instantiation/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vsg/rules/package_instantiation/__init__.py b/vsg/rules/package_instantiation/__init__.py index 90c0eaba..c2f011a3 100644 --- a/vsg/rules/package_instantiation/__init__.py +++ b/vsg/rules/package_instantiation/__init__.py @@ -5,3 +5,5 @@ from .rule_501 import rule_501 from .rule_502 import rule_502 from .rule_503 import rule_503 from .rule_504 import rule_504 +from .rule_600 import rule_600 +from .rule_601 import rule_601 From 27051dd201db5b37739cc17ef8cc6d1f50c1903f Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 10:57:32 +0000 Subject: [PATCH 03/11] Issue#1330 Added tests for new package instantiation naming rules. --- .../rule_600_test_input.vhd | 15 ++++++++++ .../rule_601_test_input.vhd | 15 ++++++++++ tests/package_instantiation/test_rule_600.py | 29 +++++++++++++++++++ tests/package_instantiation/test_rule_601.py | 29 +++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 tests/package_instantiation/rule_600_test_input.vhd create mode 100644 tests/package_instantiation/rule_601_test_input.vhd create mode 100644 tests/package_instantiation/test_rule_600.py create mode 100644 tests/package_instantiation/test_rule_601.py diff --git a/tests/package_instantiation/rule_600_test_input.vhd b/tests/package_instantiation/rule_600_test_input.vhd new file mode 100644 index 00000000..c0773271 --- /dev/null +++ b/tests/package_instantiation/rule_600_test_input.vhd @@ -0,0 +1,15 @@ + +package foo is new my_generic_pkg + generic map ( + g_my_generic => 2 + ); + +package pkg_foo is new my_generic_pkg + generic map ( + g_my_generic => 2 + ); + +package foo_pkg is new my_generic_pkg + generic map ( + g_my_generic => 2 + ); diff --git a/tests/package_instantiation/rule_601_test_input.vhd b/tests/package_instantiation/rule_601_test_input.vhd new file mode 100644 index 00000000..c0773271 --- /dev/null +++ b/tests/package_instantiation/rule_601_test_input.vhd @@ -0,0 +1,15 @@ + +package foo is new my_generic_pkg + generic map ( + g_my_generic => 2 + ); + +package pkg_foo is new my_generic_pkg + generic map ( + g_my_generic => 2 + ); + +package foo_pkg is new my_generic_pkg + generic map ( + g_my_generic => 2 + ); diff --git a/tests/package_instantiation/test_rule_600.py b/tests/package_instantiation/test_rule_600.py new file mode 100644 index 00000000..36340416 --- /dev/null +++ b/tests/package_instantiation/test_rule_600.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import package_instantiation + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_600_test_input.vhd")) + + +class test_package_instantiation_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_600(self): + oRule = package_instantiation.rule_600() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "package_instantiation") + self.assertEqual(oRule.identifier, "600") + + lExpected = [2, 7] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/tests/package_instantiation/test_rule_601.py b/tests/package_instantiation/test_rule_601.py new file mode 100644 index 00000000..f1ff34ce --- /dev/null +++ b/tests/package_instantiation/test_rule_601.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import package_instantiation + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_601_test_input.vhd")) + + +class test_package_instantiation_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_601(self): + oRule = package_instantiation.rule_601() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "package_instantiation") + self.assertEqual(oRule.identifier, "601") + + lExpected = [2, 12] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) From 7bdfa766709a49c85c59e5c261f09e858da068f7 Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 10:59:05 +0000 Subject: [PATCH 04/11] Issue#1330 Updated package_instantiation_rules.rst --- docs/package_instantiation_rules.rst | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/docs/package_instantiation_rules.rst b/docs/package_instantiation_rules.rst index 656ca117..7c777604 100644 --- a/docs/package_instantiation_rules.rst +++ b/docs/package_instantiation_rules.rst @@ -107,3 +107,47 @@ This rule checks the uninstantiated package name has proper case. .. code-block:: vhdl package my_pkg is new my_generic_pkg + +package_instantiation_600 +######################### + +|phase_7| |disabled| |error| |unfixable| |naming| + +This rule checks for valid suffixes on package identifiers. +The default package suffix is *_pkg*. + +|configuring_prefix_and_suffix_rules_link| + +**Violation** + +.. code-block:: vhdl + + package foo is new my_generic_pkg + +**Fix** + +.. code-block:: vhdl + + package foo_pkg is new my_generic_pkg + +package_instantiation_601 +######################### + +|phase_7| |disabled| |error| |unfixable| |naming| + +This rule checks for valid prefixes on instantiated package identifiers. +The default package prefix is *pkg_*. + +|configuring_prefix_and_suffix_rules_link| + +**Violation** + +.. code-block:: vhdl + + package foo is new my_generic_pkg + +**Fix** + +.. code-block:: vhdl + + package pkg_foo is new my_generic_pkg From d508e775f5f12f3a4ac3b5afc757309ec27c54df Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 11:00:40 +0000 Subject: [PATCH 05/11] Issue#1330 Update naming_rule_group.rst --- docs/rule_groups/naming_rule_group.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/rule_groups/naming_rule_group.rst b/docs/rule_groups/naming_rule_group.rst index 67de2caf..2e7d3263 100644 --- a/docs/rule_groups/naming_rule_group.rst +++ b/docs/rule_groups/naming_rule_group.rst @@ -32,6 +32,8 @@ Rules Enforcing Naming Rule Group * `package_017 <../package_rules.html#package-017>`_ * `package_body_600 <../package_body_rules.html#package-body-600>`_ * `package_body_601 <../package_body_rules.html#package-body-601>`_ +* `package_instantiation_600 <../package_instantiation_rules.html#package-instantiation-600>`_ +* `package_instantiation_601 <../package_instantiation_rules.html#package-instantiation-601>`_ * `port_011 <../port_rules.html#port-011>`_ * `port_025 <../port_rules.html#port-025>`_ * `port_600 <../port_rules.html#port-600>`_ From f476959d48f0f413ca59fdce93aeda6196822c22 Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 11:01:51 +0000 Subject: [PATCH 06/11] Isue#1330 Update configuring_disabled_rules.rst --- docs/configuring_disabled_rules.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/configuring_disabled_rules.rst b/docs/configuring_disabled_rules.rst index d095205c..08762032 100644 --- a/docs/configuring_disabled_rules.rst +++ b/docs/configuring_disabled_rules.rst @@ -69,6 +69,8 @@ Rules Disabled by Default * `package_017 `_ * `package_body_600 `_ * `package_body_601 `_ +* `package_instantiation_600 `_ +* `package_instantiation_601 `_ * `port_011 `_ * `port_025 `_ * `port_600 `_ From 168501d64f8b532e0d16ad1910cc12e1af7d2514 Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 11:02:56 +0000 Subject: [PATCH 07/11] Issue#1330: Update unfixable_rules.rst --- docs/unfixable_rules.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/unfixable_rules.rst b/docs/unfixable_rules.rst index 5b89ec77..779b07c9 100644 --- a/docs/unfixable_rules.rst +++ b/docs/unfixable_rules.rst @@ -111,6 +111,8 @@ With multiple options available, the user is required to make the decision. * `package_017 `_ * `package_body_600 `_ * `package_body_601 `_ +* `package_instantiation_600 `_ +* `package_instantiation_601 `_ * `port_011 `_ * `port_025 `_ * `port_600 `_ From 38115813acb81463d42d66441daf9d63ab6522ac Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 11:05:15 +0000 Subject: [PATCH 08/11] Issue#1330: Update configuring_prefix_and_suffix_rules.rst --- docs/configuring_prefix_and_suffix_rules.rst | 76 ++++++++++---------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/docs/configuring_prefix_and_suffix_rules.rst b/docs/configuring_prefix_and_suffix_rules.rst index 87b01101..2312407f 100644 --- a/docs/configuring_prefix_and_suffix_rules.rst +++ b/docs/configuring_prefix_and_suffix_rules.rst @@ -62,40 +62,42 @@ The keywords are treated as case insensitive and support regular expressions. Rules Enforcing Prefixes and Suffixes ##################################### -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| **Element** | **Prefix Rule** | **Suffix Rule** | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Block Label | `block_601 `_ | `block_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Constant Identifier | `constant_015 `_ | `constant_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Function Designator | `function_600 `_ | `function_601 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Generate Label | `generate_017 `_ | `generate_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Generate Parameter Identifier | `generate_601 `_ | `generate_602 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Generic Identifier | `generic_020 `_ | `generic_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Generic Map Identifier | `generic_map_601 `_ | `generic_map_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Loop Label | `loop_600 `_ | `loop_601 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Loop Parameter Identifier | `loop_602 `_ | `loop_603 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Package Identifier | `package_017 `_ | `package_016 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Package Body Identifier | `package_body_601 `_ | `package_body_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Port Identifier | `port_011 `_ | `port_025 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Process Label | `process_036 `_ | `process_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Signal Identifier | `signal_008 `_ | `signal_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Subtype Identifier | `subtype_004 `_ | `subtype_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Type Identifier | `type_definition_015 `_ | `type_definition_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ -| Variable Identifier | `variable_012 `_ | `variable_600 `_ | -+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+ ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| **Element** | **Prefix Rule** | **Suffix Rule** | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Block Label | `block_601 `_ | `block_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Constant Identifier | `constant_015 `_ | `constant_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Function Designator | `function_600 `_ | `function_601 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Generate Label | `generate_017 `_ | `generate_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Generate Parameter Identifier | `generate_601 `_ | `generate_602 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Generic Identifier | `generic_020 `_ | `generic_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Generic Map Identifier | `generic_map_601 `_ | `generic_map_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Loop Label | `loop_600 `_ | `loop_601 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Loop Parameter Identifier | `loop_602 `_ | `loop_603 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Package Identifier | `package_017 `_ | `package_016 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Package Body Identifier | `package_body_601 `_ | `package_body_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Package Instantiation Identifier | `package_instantiation_601 `_ | `package_instantiation_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Port Identifier | `port_011 `_ | `port_025 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Process Label | `process_036 `_ | `process_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Signal Identifier | `signal_008 `_ | `signal_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Subtype Identifier | `subtype_004 `_ | `subtype_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Type Identifier | `type_definition_015 `_ | `type_definition_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ +| Variable Identifier | `variable_012 `_ | `variable_600 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ From 10839d7c102d778ed3f74a5f91f60dcc351b2a68 Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 11:11:25 +0000 Subject: [PATCH 09/11] Issue#1330: Updated formatting in rule_600.py --- vsg/rules/package_instantiation/rule_600.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vsg/rules/package_instantiation/rule_600.py b/vsg/rules/package_instantiation/rule_600.py index ae1a4be8..b43d158b 100644 --- a/vsg/rules/package_instantiation/rule_600.py +++ b/vsg/rules/package_instantiation/rule_600.py @@ -9,6 +9,7 @@ lTokens.append(token.identifier.identifier) oStart = token.package_instantiation_declaration.package_keyword oEnd = token.package_instantiation_declaration.is_keyword + class rule_600(token_suffix_between_tokens): """ This rule checks for valid suffixes on package identifiers. From fe4d57d4e4a4e2336aa856ad0ba71f2b48e593df Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 11:12:53 +0000 Subject: [PATCH 10/11] Issue#1330: Removed unused line from rule_601.py --- vsg/rules/package_instantiation/rule_601.py | 1 - 1 file changed, 1 deletion(-) diff --git a/vsg/rules/package_instantiation/rule_601.py b/vsg/rules/package_instantiation/rule_601.py index 557f156f..5aefb532 100644 --- a/vsg/rules/package_instantiation/rule_601.py +++ b/vsg/rules/package_instantiation/rule_601.py @@ -33,4 +33,3 @@ class rule_601(token_prefix_between_tokens): def __init__(self): super().__init__(lTokens, oStart, oEnd) self.prefixes = ["pkg_"] - # self.solution = "Instantiated package identifier" From 70e95863ea20b04a6074a50792e401ea27ea7489 Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Thu, 14 Nov 2024 11:13:24 +0000 Subject: [PATCH 11/11] Issue#1330: Removed unused line from rule_600.py --- vsg/rules/package_instantiation/rule_600.py | 1 - 1 file changed, 1 deletion(-) diff --git a/vsg/rules/package_instantiation/rule_600.py b/vsg/rules/package_instantiation/rule_600.py index b43d158b..fb90e1b1 100644 --- a/vsg/rules/package_instantiation/rule_600.py +++ b/vsg/rules/package_instantiation/rule_600.py @@ -33,4 +33,3 @@ class rule_600(token_suffix_between_tokens): def __init__(self): super().__init__(lTokens, oStart, oEnd) self.suffixes = ["_pkg"] - self.solution = "Instantiated package identifier"