Repository: jeremiah-c-leary/vhdl-style-guide (language: python)

Issue:
Add naming rules for package instantiation declarations
Subtask of #1306. Implement naming rules for package instantiation declarations.

I'd like prefix and suffix rules for the instantiated package identifier, equivalent to `package_016` and `package_017`.
Issue#1322: Added case rules for package instantiation declarations
Resolves #1322.


Discussion / hints:

Fix patch:
diff --git a/docs/configuring_disabled_rules.rst b/docs/configuring_disabled_rules.rst
index d095205c3..087620325 100644
--- a/docs/configuring_disabled_rules.rst
+++ b/docs/configuring_disabled_rules.rst
@@ -69,6 +69,8 @@ Rules Disabled by Default
 * `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>`_
diff --git a/docs/configuring_prefix_and_suffix_rules.rst b/docs/configuring_prefix_and_suffix_rules.rst
index 87b01101d..2312407f9 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_rules.html#block-601>`_                      | `block_600 <block_rules.html#block-600>`_                      |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Constant Identifier           | `constant_015 <constant_rules.html#constant-015>`_             | `constant_600 <constant_rules.html#constant-600>`_             |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Function Designator           | `function_600 <function_rules.html#function-600>`_             | `function_601 <function_rules.html#function-601>`_             |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Generate Label                | `generate_017 <generate_rules.html#generate-017>`_             | `generate_600 <generate_rules.html#generate-600>`_             |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Generate Parameter Identifier | `generate_601 <generate_rules.html#generate-601>`_             | `generate_602 <generate_rules.html#generate-602>`_             |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Generic Identifier            | `generic_020 <generic_rules.html#generic-020>`_                | `generic_600 <generic_rules.html#generic-600>`_                |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Generic Map Identifier        | `generic_map_601 <generic_map_rules.html#generic-map-601>`_    | `generic_map_600 <generic_map_rules.html#generic-map-600>`_    |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Loop Label                    | `loop_600 <loop_statement_rules.html#loop-statement-600>`_     | `loop_601 <loop_statement_rules.html#loop-statement-601>`_     |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Loop Parameter Identifier     | `loop_602 <loop_statement_rules.html#loop-statement-602>`_     | `loop_603 <loop_statement_rules.html#loop-statement-603>`_     |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Package Identifier            | `package_017 <package_rules.html#package-017>`_                | `package_016 <package_rules.html#package-016>`_                |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Package Body Identifier       | `package_body_601 <package_body_rules.html#package-body-601>`_ | `package_body_600 <package_body_rules.html#package-body-600>`_ |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Port Identifier               | `port_011 <port_rules.html#port-011>`_                         | `port_025 <port_rules.html#port-025>`_                         |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Process Label                 | `process_036 <process_rules.html#process-036>`_                | `process_600 <process_rules.html#process-600>`_                |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Signal Identifier             | `signal_008 <signal_rules.html#signal-008>`_                   | `signal_600 <signal_rules.html#signal-600>`_                   |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Subtype Identifier            | `subtype_004 <subtype_rules.html#subtype-004>`_                | `subtype_600 <subtype_rules.html#subtype-600>`_                |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Type Identifier               | `type_definition_015 <type_rules.html#type-015>`_              | `type_definition_600 <type_rules.html#type-600>`_              |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
-| Variable Identifier           | `variable_012 <variable_rules.html#variable-012>`_             | `variable_600 <variable_rules.html#variable-600>`_             |
-+-------------------------------+----------------------------------------------------------------+----------------------------------------------------------------+
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| **Element**                      | **Prefix Rule**                                                                           |  **Suffix Rule**                                                                          |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Block Label                      | `block_601 <block_rules.html#block-601>`_                                                 | `block_600 <block_rules.html#block-600>`_                                                 |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Constant Identifier              | `constant_015 <constant_rules.html#constant-015>`_                                        | `constant_600 <constant_rules.html#constant-600>`_                                        |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Function Designator              | `function_600 <function_rules.html#function-600>`_                                        | `function_601 <function_rules.html#function-601>`_                                        |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Generate Label                   | `generate_017 <generate_rules.html#generate-017>`_                                        | `generate_600 <generate_rules.html#generate-600>`_                                        |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Generate Parameter Identifier    | `generate_601 <generate_rules.html#generate-601>`_                                        | `generate_602 <generate_rules.html#generate-602>`_                                        |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Generic Identifier               | `generic_020 <generic_rules.html#generic-020>`_                                           | `generic_600 <generic_rules.html#generic-600>`_                                           |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Generic Map Identifier           | `generic_map_601 <generic_map_rules.html#generic-map-601>`_                               | `generic_map_600 <generic_map_rules.html#generic-map-600>`_                               |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Loop Label                       | `loop_600 <loop_statement_rules.html#loop-statement-600>`_                                | `loop_601 <loop_statement_rules.html#loop-statement-601>`_                                |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Loop Parameter Identifier        | `loop_602 <loop_statement_rules.html#loop-statement-602>`_                                | `loop_603 <loop_statement_rules.html#loop-statement-603>`_                                |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Package Identifier               | `package_017 <package_rules.html#package-017>`_                                           | `package_016 <package_rules.html#package-016>`_                                           |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Package Body Identifier          | `package_body_601 <package_body_rules.html#package-body-601>`_                            | `package_body_600 <package_body_rules.html#package-body-600>`_                            |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Package Instantiation Identifier | `package_instantiation_601 <package_instantiation_rules.html#package-instantiation-601>`_ | `package_instantiation_600 <package_instantiation_rules.html#package-instantiation-600>`_ |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Port Identifier                  | `port_011 <port_rules.html#port-011>`_                                                    | `port_025 <port_rules.html#port-025>`_                                                    |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Process Label                    | `process_036 <process_rules.html#process-036>`_                                           | `process_600 <process_rules.html#process-600>`_                                           |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Signal Identifier                | `signal_008 <signal_rules.html#signal-008>`_                                              | `signal_600 <signal_rules.html#signal-600>`_                                              |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Subtype Identifier               | `subtype_004 <subtype_rules.html#subtype-004>`_                                           | `subtype_600 <subtype_rules.html#subtype-600>`_                                           |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Type Identifier                  | `type_definition_015 <type_rules.html#type-015>`_                                         | `type_definition_600 <type_rules.html#type-600>`_                                         |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
+| Variable Identifier              | `variable_012 <variable_rules.html#variable-012>`_                                        | `variable_600 <variable_rules.html#variable-600>`_                                        |
++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+
diff --git a/docs/package_instantiation_rules.rst b/docs/package_instantiation_rules.rst
index 656ca117e..7c777604d 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
diff --git a/docs/rule_groups/naming_rule_group.rst b/docs/rule_groups/naming_rule_group.rst
index 67de2cafd..2e7d32636 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>`_
diff --git a/docs/unfixable_rules.rst b/docs/unfixable_rules.rst
index 5b89ec776..779b07c93 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_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>`_
diff --git a/vsg/rules/package_instantiation/__init__.py b/vsg/rules/package_instantiation/__init__.py
index 90c0eabab..c2f011a36 100644
--- a/vsg/rules/package_instantiation/__init__.py
+++ b/vsg/rules/package_instantiation/__init__.py
@@ -5,3 +5,5 @@
 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
diff --git a/vsg/rules/package_instantiation/rule_600.py b/vsg/rules/package_instantiation/rule_600.py
new file mode 100644
index 000000000..fb90e1b13
--- /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"]
diff --git a/vsg/rules/package_instantiation/rule_601.py b/vsg/rules/package_instantiation/rule_601.py
new file mode 100644
index 000000000..5aefb5323
--- /dev/null
+++ b/vsg/rules/package_instantiation/rule_601.py
@@ -0,0 +1,35 @@
+# -*- 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_"]


Test patch:
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 000000000..c07732715
--- /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 000000000..c07732715
--- /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 000000000..36340416f
--- /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 000000000..f1ff34ce1
--- /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))