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 `_ 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 `_ | ++----------------------------------+-------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------+ diff --git a/docs/package_instantiation_rules.rst b/docs/package_instantiation_rules.rst index 4e6b1515..5bd44043 100644 --- a/docs/package_instantiation_rules.rst +++ b/docs/package_instantiation_rules.rst @@ -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 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>`_ 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 `_ 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)) diff --git a/vsg/rules/package_instantiation/__init__.py b/vsg/rules/package_instantiation/__init__.py index c10673d7..b8b687b4 100644 --- a/vsg/rules/package_instantiation/__init__.py +++ b/vsg/rules/package_instantiation/__init__.py @@ -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 diff --git a/vsg/rules/package_instantiation/rule_600.py b/vsg/rules/package_instantiation/rule_600.py new file mode 100644 index 00000000..fb90e1b1 --- /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 00000000..5aefb532 --- /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_"]