Merge pull request #1331 from JHertz5/issue-1330

Issue#1330: Added naming rules for package instantiation declarations.
This commit is contained in:
Jeremiah Leary 2024-12-13 07:31:07 -06:00 committed by GitHub
commit add3736ffd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 249 additions and 37 deletions

View File

@ -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>`_

View File

@ -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>`_ |
+----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+

View File

@ -187,3 +187,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

View File

@ -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>`_

View File

@ -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>`_

View File

@ -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
);

View File

@ -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
);

View File

@ -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))

View File

@ -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))

View File

@ -9,3 +9,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

View File

@ -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"]

View File

@ -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_"]