From 6845559968ff65e21821f07385fc27059e841ded Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Sun, 17 Nov 2024 01:10:10 +0000 Subject: [PATCH 1/3] Issue#1279: Added case rule for `others` keyword in aggregates (#1299) * Issue#1279: Added rule aggregate_500 * Issue#1279: Added tests for rule aggregate_500 * Issue#1279: Added documentation for rule aggregate_500 * Issue#1279: Minor rewording in docstring. --- docs/aggregate_rules.rst | 25 +++ ...figuring_uppercase_and_lowercase_rules.rst | 2 + docs/rule_groups/case_keyword_rule_group.rst | 1 + docs/rule_groups/case_rule_group.rst | 1 + docs/rules.rst | 1 + tests/aggregate/__init__.py | 0 .../rule_500_test_input.fixed_lower.vhd | 148 ++++++++++++++++++ .../rule_500_test_input.fixed_upper.vhd | 148 ++++++++++++++++++ tests/aggregate/rule_500_test_input.vhd | 148 ++++++++++++++++++ tests/aggregate/test_rule_500.py | 73 +++++++++ vsg/rules/__init__.py | 1 + vsg/rules/aggregate/__init__.py | 3 + vsg/rules/aggregate/rule_500.py | 34 ++++ 13 files changed, 585 insertions(+) create mode 100644 docs/aggregate_rules.rst create mode 100644 tests/aggregate/__init__.py create mode 100644 tests/aggregate/rule_500_test_input.fixed_lower.vhd create mode 100644 tests/aggregate/rule_500_test_input.fixed_upper.vhd create mode 100644 tests/aggregate/rule_500_test_input.vhd create mode 100644 tests/aggregate/test_rule_500.py create mode 100644 vsg/rules/aggregate/__init__.py create mode 100644 vsg/rules/aggregate/rule_500.py diff --git a/docs/aggregate_rules.rst b/docs/aggregate_rules.rst new file mode 100644 index 00000000..114455d7 --- /dev/null +++ b/docs/aggregate_rules.rst @@ -0,0 +1,25 @@ +.. include:: includes.rst + +Aggregate Rules +--------------- + +aggregate_500 +############# + +|phase_6| |error| |case| |case_keyword| + +This rule checks the *others* keyword in aggregates has proper case. + +|configuring_uppercase_and_lowercase_rules_link| + +**Violation** + +.. code-block:: vhdl + + signal counter : t_counter := (OTHERS => '1'); + +**Fix** + +.. code-block:: vhdl + + signal counter : t_counter := (others => '1'); diff --git a/docs/configuring_uppercase_and_lowercase_rules.rst b/docs/configuring_uppercase_and_lowercase_rules.rst index 0be0a5fc..d530db3d 100644 --- a/docs/configuring_uppercase_and_lowercase_rules.rst +++ b/docs/configuring_uppercase_and_lowercase_rules.rst @@ -221,6 +221,8 @@ For example, if you want to uppercase everything except the entity name, you cou Rules Enforcing Case #################### +* `aggregate_500 `_ + * `alias_declaration_500 `_ * `alias_declaration_501 `_ * `alias_declaration_502 `_ diff --git a/docs/rule_groups/case_keyword_rule_group.rst b/docs/rule_groups/case_keyword_rule_group.rst index 7abe71d3..d185cfa7 100644 --- a/docs/rule_groups/case_keyword_rule_group.rst +++ b/docs/rule_groups/case_keyword_rule_group.rst @@ -5,6 +5,7 @@ Case::Keyword Rule Group Rules Enforcing Case::Keyword Rule Group ######################################## +* `aggregate_500 <../aggregate_rules.html#aggregate-500>`_ * `alias_declaration_500 <../alias_declaration_rules.html#alias-declaration-500>`_ * `alias_declaration_501 <../alias_declaration_rules.html#alias-declaration-501>`_ * `architecture_004 <../architecture_rules.html#architecture-004>`_ diff --git a/docs/rule_groups/case_rule_group.rst b/docs/rule_groups/case_rule_group.rst index 36ad0bc3..99204e52 100644 --- a/docs/rule_groups/case_rule_group.rst +++ b/docs/rule_groups/case_rule_group.rst @@ -5,6 +5,7 @@ Case Rule Group Rules Enforcing Case Rule Group ############################### +* `aggregate_500 <../aggregate_rules.html#aggregate-500>`_ * `alias_declaration_500 <../alias_declaration_rules.html#alias-declaration-500>`_ * `alias_declaration_501 <../alias_declaration_rules.html#alias-declaration-501>`_ * `alias_declaration_502 <../alias_declaration_rules.html#alias-declaration-502>`_ diff --git a/docs/rules.rst b/docs/rules.rst index 812c4cbe..171902ce 100644 --- a/docs/rules.rst +++ b/docs/rules.rst @@ -7,6 +7,7 @@ The rules are divided into categories depending on the part of the VHDL code bei :maxdepth: 2 after_rules.rst + aggregate_rules.rst alias_declaration_rules.rst architecture_rules.rst assert_rules.rst diff --git a/tests/aggregate/__init__.py b/tests/aggregate/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/aggregate/rule_500_test_input.fixed_lower.vhd b/tests/aggregate/rule_500_test_input.fixed_lower.vhd new file mode 100644 index 00000000..b8062a65 --- /dev/null +++ b/tests/aggregate/rule_500_test_input.fixed_lower.vhd @@ -0,0 +1,148 @@ + +architecture rtl of test is + + signal sig : signed := (others => '0'); + + function my_func ( + test : t_counter := (others => '0') + ) return integer is + begin + return (others => '0'); + end function; + +begin + + a <= + ( + 1 => '1', + others => '0' + ); + a <= ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a <= + (others => '1') when x, + (others => '0') when others; + + process is + + constant con : signed := (others => '0'); + variable var : signed := (others => '0'); + + begin + + a <= + ( + 1 => '1', + others => '0' + ); + a <= ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a <= + (others => '1') when x, + (others => '0') when others; + + a := + ( + 1 => '1', + others => '0' + ); + a := ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a := + (others => '1') when x, + (others => '0') when others; + + case expression is + + when others => + + null; + + end case; + + end process; + +end architecture rtl; + +architecture rtl of test is + + signal sig : signed := (others => '0'); + + function my_func ( + test : t_counter := (others => '0') + ) return integer is + begin + return (others => '0'); + end function; + +begin + + a <= + ( + 1 => '1', + others => '0' + ); + a <= ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a <= + (others => '1') when x, + (others => '0') when others; + + process is + + constant con : signed := (others => '0'); + variable var : signed := (others => '0'); + + begin + + a <= + ( + 1 => '1', + others => '0' + ); + a <= ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a <= + (others => '1') when x, + (others => '0') when others; + + a := + ( + 1 => '1', + others => '0' + ); + a := ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a := + (others => '1') when x, + (others => '0') when others; + + case expression is + + when others => + + null; + + end case; + + end process; + +end architecture rtl; diff --git a/tests/aggregate/rule_500_test_input.fixed_upper.vhd b/tests/aggregate/rule_500_test_input.fixed_upper.vhd new file mode 100644 index 00000000..fad935ee --- /dev/null +++ b/tests/aggregate/rule_500_test_input.fixed_upper.vhd @@ -0,0 +1,148 @@ + +architecture rtl of test is + + signal sig : signed := (OTHERS => '0'); + + function my_func ( + test : t_counter := (OTHERS => '0') + ) return integer is + begin + return (OTHERS => '0'); + end function; + +begin + + a <= + ( + 1 => '1', + OTHERS => '0' + ); + a <= ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a <= + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + process is + + constant con : signed := (OTHERS => '0'); + variable var : signed := (OTHERS => '0'); + + begin + + a <= + ( + 1 => '1', + OTHERS => '0' + ); + a <= ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a <= + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + a := + ( + 1 => '1', + OTHERS => '0' + ); + a := ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a := + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + case expression is + + when others => + + null; + + end case; + + end process; + +end architecture rtl; + +architecture rtl of test is + + signal sig : signed := (OTHERS => '0'); + + function my_func ( + test : t_counter := (OTHERS => '0') + ) return integer is + begin + return (OTHERS => '0'); + end function; + +begin + + a <= + ( + 1 => '1', + OTHERS => '0' + ); + a <= ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a <= + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + process is + + constant con : signed := (OTHERS => '0'); + variable var : signed := (OTHERS => '0'); + + begin + + a <= + ( + 1 => '1', + OTHERS => '0' + ); + a <= ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a <= + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + a := + ( + 1 => '1', + OTHERS => '0' + ); + a := ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a := + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + case expression is + + when others => + + null; + + end case; + + end process; + +end architecture rtl; diff --git a/tests/aggregate/rule_500_test_input.vhd b/tests/aggregate/rule_500_test_input.vhd new file mode 100644 index 00000000..1b3d6edc --- /dev/null +++ b/tests/aggregate/rule_500_test_input.vhd @@ -0,0 +1,148 @@ + +architecture rtl of test is + + signal sig : signed := (others => '0'); + + function my_func ( + test : t_counter := (others => '0') + ) return integer is + begin + return (others => '0'); + end function; + +begin + + a <= + ( + 1 => '1', + others => '0' + ); + a <= ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a <= + (others => '1') when x, + (others => '0') when others; + + process is + + constant con : signed := (others => '0'); + variable var : signed := (others => '0'); + + begin + + a <= + ( + 1 => '1', + others => '0' + ); + a <= ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a <= + (others => '1') when x, + (others => '0') when others; + + a := + ( + 1 => '1', + others => '0' + ); + a := ( + 1 => '1', + others => '0' + ) when condition else + (others => '0'); + with condition select a := + (others => '1') when x, + (others => '0') when others; + + case expression is + + when others => + + null; + + end case; + + end process; + +end architecture rtl; + +architecture rtl of test is + + signal sig : signed := (OTHERS => '0'); + + function my_func ( + test : t_counter := (OTHERS => '0') + ) return integer is + begin + return (OTHERS => '0'); + end function; + +begin + + a <= + ( + 1 => '1', + OTHERS => '0' + ); + a <= ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a <= + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + process is + + constant con : signed := (OTHERS => '0'); + variable var : signed := (OTHERS => '0'); + + begin + + a <= + ( + 1 => '1', + OTHERS => '0' + ); + a <= ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a <= + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + a := + ( + 1 => '1', + OTHERS => '0' + ); + a := ( + 1 => '1', + OTHERS => '0' + ) when condition else + (OTHERS => '0'); + with condition select a := + (OTHERS => '1') when x, + (OTHERS => '0') when others; + + case expression is + + when others => + + null; + + end case; + + end process; + +end architecture rtl; diff --git a/tests/aggregate/test_rule_500.py b/tests/aggregate/test_rule_500.py new file mode 100644 index 00000000..04b61c12 --- /dev/null +++ b/tests/aggregate/test_rule_500.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import aggregate + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_500_test_input.vhd")) + +lExpected_lower = [] +lExpected_lower.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_lower.vhd"), lExpected_lower) + +lExpected_upper = [] +lExpected_upper.append("") +utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_upper.vhd"), lExpected_upper) + + +class test_aggregate_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + + def test_rule_500_lower(self): + oRule = aggregate.rule_500() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "aggregate") + self.assertEqual(oRule.identifier, "500") + + lExpected = [78, 81, 84, 92, 96, 98, 100, 101, 105, 106, 113, 117, 119, 121, 122, 127, 131, 133, 135, 136] + + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_rule_500_upper(self): + oRule = aggregate.rule_500() + oRule.case = "upper" + self.assertTrue(oRule) + self.assertEqual(oRule.name, "aggregate") + self.assertEqual(oRule.identifier, "500") + + lExpected = [4, 7, 10, 18, 22, 24, 26, 27, 31, 32, 39, 43, 45, 47, 48, 53, 57, 59, 61, 62] + oRule.analyze(self.oFile) + self.assertEqual(utils.extract_violation_lines_from_violation_object(oRule.violations), lExpected) + + def test_fix_rule_500_lower(self): + oRule = aggregate.rule_500() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_lower, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) + + def test_fix_rule_500_upper(self): + oRule = aggregate.rule_500() + oRule.case = "upper" + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected_upper, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/vsg/rules/__init__.py b/vsg/rules/__init__.py index 2d750b2c..cb750085 100644 --- a/vsg/rules/__init__.py +++ b/vsg/rules/__init__.py @@ -100,6 +100,7 @@ from .experiment import Rule as experiment from vsg.rules import alias_declaration from vsg.rules import after +from vsg.rules import aggregate from vsg.rules import architecture from vsg.rules import assert_statement from vsg.rules import attribute diff --git a/vsg/rules/aggregate/__init__.py b/vsg/rules/aggregate/__init__.py new file mode 100644 index 00000000..c5c1c6e6 --- /dev/null +++ b/vsg/rules/aggregate/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from .rule_500 import rule_500 diff --git a/vsg/rules/aggregate/rule_500.py b/vsg/rules/aggregate/rule_500.py new file mode 100644 index 00000000..fa481470 --- /dev/null +++ b/vsg/rules/aggregate/rule_500.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_case_in_range_bounded_by_tokens as Rule + +lTokens = [] +lTokens.append(token.choice.others_keyword) + +oStart = token.aggregate.open_parenthesis +oEnd = token.aggregate.close_parenthesis + + +class rule_500(Rule): + """ + This rule checks the *others* keyword in aggregates has proper case. + + |configuring_uppercase_and_lowercase_rules_link| + + **Violation** + + .. code-block:: vhdl + + signal counter : t_counter := (OTHERS => '1'); + + **Fix** + + .. code-block:: vhdl + + signal counter : t_counter := (others => '1'); + """ + + def __init__(self): + super().__init__(lTokens, oStart, oEnd) + self.groups.append("case::keyword") From 1f3502431f160782091fdb4e00e58d37391fe10c Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Sun, 17 Nov 2024 01:19:30 +0000 Subject: [PATCH 2/3] Issue#1283: Split indent rules to treat labels separately from keywords (#1292) * Issue#1283: Added rule case_300 * Issue#1283: Added tests for rule case_300 * Issue#1283: Added rule next_301. * Issue#1283: Added tests for rule next_301. * Issue#1283: Removed label checking from rule next_300. * Issue#1283: Updated tests for rule next_300. * Issue#1283: Indentation correction. * Issue#1283: Added rule exit_301. * Issue#1283: Added tests for rule exit_301. * Issue#1283: Removed label checking from rule exit_300. * Issue#1283: Updated tests for rule exit_300. * Issue#1283: Added rule null_301. * Issue#1283: Removed label checking from rule null_300. * Issue#1283: Added tests for rule null_301. * Issue#1283: Updated tests for rule null_statement_300. * Issue#1283: Added rule wait_300. * Issue#1283: Removed label checking from rule wait_001. * Issue#1283: Added tests for rule wait_300. * Issue#1283: Updated docs. * Issue#1283: Update indent_rule_group.rst to remove deprecated rule --- docs/case_rules.rst | 22 +++++++++ docs/exit_statement_rules.rst | 23 +++++++++ docs/next_statement_rules.rst | 21 ++++++++ docs/null_statement_rules.rst | 21 ++++++++ docs/rule_groups/indent_rule_group.rst | 5 ++ docs/wait_rules.rst | 26 ++++++++++ tests/case/rule_300_test_input.fixed.vhd | 43 +++++++++++++++++ tests/case/rule_300_test_input.vhd | 43 +++++++++++++++++ tests/case/test_rule_300.py | 48 +++++++++++++++++++ .../rule_300_test_input.fixed.vhd | 4 +- tests/exit_statement/rule_300_test_input.vhd | 4 +- .../rule_301_test_input.fixed.vhd | 15 ++++++ tests/exit_statement/rule_301_test_input.vhd | 15 ++++++ tests/exit_statement/test_rule_300.py | 2 +- tests/exit_statement/test_rule_301.py | 48 +++++++++++++++++++ .../rule_300_test_input.fixed.vhd | 4 -- tests/next_statement/rule_300_test_input.vhd | 4 -- .../rule_301_test_input.fixed.vhd | 28 +++++++++++ tests/next_statement/rule_301_test_input.vhd | 28 +++++++++++ tests/next_statement/test_rule_300.py | 2 +- tests/next_statement/test_rule_301.py | 48 +++++++++++++++++++ .../rule_300_test_input.fixed.vhd | 3 -- tests/null_statement/rule_300_test_input.vhd | 3 -- .../rule_301_test_input.fixed.vhd | 27 +++++++++++ tests/null_statement/rule_301_test_input.vhd | 27 +++++++++++ tests/null_statement/test_rule_300.py | 2 +- tests/null_statement/test_rule_301.py | 48 +++++++++++++++++++ tests/wait/rule_300_test_input.fixed.vhd | 48 +++++++++++++++++++ tests/wait/rule_300_test_input.vhd | 48 +++++++++++++++++++ tests/wait/test_rule_300.py | 48 +++++++++++++++++++ vsg/rules/case/__init__.py | 1 + vsg/rules/case/rule_300.py | 31 ++++++++++++ vsg/rules/exit_statement/__init__.py | 1 + vsg/rules/exit_statement/rule_300.py | 1 - vsg/rules/exit_statement/rule_301.py | 32 +++++++++++++ vsg/rules/next_statement/__init__.py | 1 + vsg/rules/next_statement/rule_300.py | 1 - vsg/rules/next_statement/rule_301.py | 30 ++++++++++++ vsg/rules/null_statement/__init__.py | 1 + vsg/rules/null_statement/rule_300.py | 1 - vsg/rules/null_statement/rule_301.py | 30 ++++++++++++ vsg/rules/wait/__init__.py | 1 + vsg/rules/wait/rule_001.py | 1 - vsg/rules/wait/rule_300.py | 35 ++++++++++++++ 44 files changed, 848 insertions(+), 27 deletions(-) create mode 100644 tests/case/rule_300_test_input.fixed.vhd create mode 100644 tests/case/rule_300_test_input.vhd create mode 100644 tests/case/test_rule_300.py create mode 100644 tests/exit_statement/rule_301_test_input.fixed.vhd create mode 100644 tests/exit_statement/rule_301_test_input.vhd create mode 100644 tests/exit_statement/test_rule_301.py create mode 100644 tests/next_statement/rule_301_test_input.fixed.vhd create mode 100644 tests/next_statement/rule_301_test_input.vhd create mode 100644 tests/next_statement/test_rule_301.py create mode 100644 tests/null_statement/rule_301_test_input.fixed.vhd create mode 100644 tests/null_statement/rule_301_test_input.vhd create mode 100644 tests/null_statement/test_rule_301.py create mode 100644 tests/wait/rule_300_test_input.fixed.vhd create mode 100644 tests/wait/rule_300_test_input.vhd create mode 100644 tests/wait/test_rule_300.py create mode 100644 vsg/rules/case/rule_300.py create mode 100644 vsg/rules/exit_statement/rule_301.py create mode 100644 vsg/rules/next_statement/rule_301.py create mode 100644 vsg/rules/null_statement/rule_301.py create mode 100644 vsg/rules/wait/rule_300.py diff --git a/docs/case_rules.rst b/docs/case_rules.rst index 1bfc34a4..3a278790 100644 --- a/docs/case_rules.rst +++ b/docs/case_rules.rst @@ -533,6 +533,28 @@ The default style is :code:`allow_comment`. -- Comment when 4 => +case_300 +######## + +|phase_4| |error| |indent| + +This rule checks the indentation of the label. +**Violation** + +.. code-block:: vhdl + + case_label : case data is + + end case; + +**Fix** + +.. code-block:: vhdl + + case_label : case data is + + end case; + case_500 ######## diff --git a/docs/exit_statement_rules.rst b/docs/exit_statement_rules.rst index f48115ec..23419feb 100644 --- a/docs/exit_statement_rules.rst +++ b/docs/exit_statement_rules.rst @@ -26,6 +26,29 @@ This rule checks the indent of the **exit** keyword. exit; +exit_statement_301 +################## + +|phase_4| |error| |indent| + +This rule checks the indent of the label. + +**Violation** + +.. code-block:: vhdl + + end if; + + exit_label : exit; + +**Fix** + +.. code-block:: vhdl + + end if; + + exit_label : exit; + exit_statement_500 ################## diff --git a/docs/next_statement_rules.rst b/docs/next_statement_rules.rst index 5c589df0..311c7cf8 100644 --- a/docs/next_statement_rules.rst +++ b/docs/next_statement_rules.rst @@ -24,6 +24,27 @@ This rule checks the indentation of the **next** keyword. next when condition; end function; +next_statement_301 +################## + +|phase_4| |error| |indent| + +This rule checks the indentation of the label. + +**Violation** + +.. code-block:: vhdl + + next_label : next when condition; + end function; + +**Fix** + +.. code-block:: vhdl + + next_label : next when condition; + end function; + next_statement_500 ################## diff --git a/docs/null_statement_rules.rst b/docs/null_statement_rules.rst index 48307fce..59ded0b9 100644 --- a/docs/null_statement_rules.rst +++ b/docs/null_statement_rules.rst @@ -24,6 +24,27 @@ This rule checks the indentation of the **null** keyword. null; end loop; +null_statement_301 +################## + +|phase_4| |error| |indent| + +This rule checks the indentation of the label. + +**Violation** + +.. code-block:: vhdl + + null_label : null; + end loop; + +**Fix** + +.. code-block:: vhdl + + null_label : null; + end loop; + null_statement_500 ################## diff --git a/docs/rule_groups/indent_rule_group.rst b/docs/rule_groups/indent_rule_group.rst index 03c5b868..c932b25d 100644 --- a/docs/rule_groups/indent_rule_group.rst +++ b/docs/rule_groups/indent_rule_group.rst @@ -16,6 +16,7 @@ Rules Enforcing Indent Rule Group * `block_301 <../block_rules.html#block-301>`_ * `block_302 <../block_rules.html#block-302>`_ * `case_001 <../case_rules.html#case-001>`_ +* `case_300 <../case_rules.html#case-300>`_ * `comment_010 <../comment_rules.html#comment-010>`_ * `component_001 <../component_rules.html#component-001>`_ * `component_009 <../component_rules.html#component-009>`_ @@ -28,6 +29,7 @@ Rules Enforcing Indent Rule Group * `entity_009 <../entity_rules.html#entity-009>`_ * `entity_300 <../entity_rules.html#entity-300>`_ * `exit_statement_300 <../exit_statement_rules.html#exit-statement-300>`_ +* `exit_statement_301 <../exit_statement_rules.html#exit-statement-301>`_ * `file_001 <../file_rules.html#file-001>`_ * `function_001 <../function_rules.html#function-001>`_ * `function_008 <../function_rules.html#function-008>`_ @@ -56,7 +58,9 @@ Rules Enforcing Indent Rule Group * `loop_statement_301 <../loop_statement_rules.html#loop-statement-301>`_ * `loop_statement_302 <../loop_statement_rules.html#loop-statement-302>`_ * `next_statement_300 <../next_statement_rules.html#next-statement-300>`_ +* `next_statement_301 <../next_statement_rules.html#next-statement-301>`_ * `null_statement_300 <../null_statement_rules.html#null-statement-300>`_ +* `null_statement_301 <../null_statement_rules.html#null-statement-301>`_ * `package_001 <../package_rules.html#package-001>`_ * `package_015 <../package_rules.html#package-015>`_ * `package_body_300 <../package_body_rules.html#package-body-300>`_ @@ -93,3 +97,4 @@ Rules Enforcing Indent Rule Group * `variable_001 <../variable_rules.html#variable-001>`_ * `variable_assignment_001 <../variable_assignment_rules.html#variable-assignment-001>`_ * `wait_001 <../wait_rules.html#wait-001>`_ +* `wait_300 <../wait_rules.html#wait-300>`_ diff --git a/docs/wait_rules.rst b/docs/wait_rules.rst index f97514b7..ff426f41 100644 --- a/docs/wait_rules.rst +++ b/docs/wait_rules.rst @@ -31,6 +31,32 @@ Proper indentation enhances comprehension. wait on a,b; wait until a = '0'; +wait_300 +######## + +|phase_4| |error| |indent| + +This rule checks for indentation of the label. +Proper indentation enhances comprehension. + +**Violation** + +.. code-block:: vhdl + + begin + + wait on a,b; + wait_label : wait until a = '0'; + +**Fix** + +.. code-block:: vhdl + + begin + + wait on a,b; + wait_label : wait until a = '0'; + wait_500 ######## diff --git a/tests/case/rule_300_test_input.fixed.vhd b/tests/case/rule_300_test_input.fixed.vhd new file mode 100644 index 00000000..833bbdc9 --- /dev/null +++ b/tests/case/rule_300_test_input.fixed.vhd @@ -0,0 +1,43 @@ + +architecture ARCH of ENTITY is + +begin + + PROC_1 : process (a, b, c) is + begin + + my_case_statement_label : case boolean_1 is + + when STATE_1 => + + a <= b; + b <= c; + c <= d; + + end case; + + -- Violations below + + my_case_statement_label : case boolean_1 is + + when STATE_1 => + + a <= b; + b <= c; + c <= d; + + end case; + + my_case_statement_label : case boolean_1 is + + when STATE_1 => + + a <= b; + b <= c; + c <= d; + + end case; + + end process PROC_1; + +end architecture ARCH; diff --git a/tests/case/rule_300_test_input.vhd b/tests/case/rule_300_test_input.vhd new file mode 100644 index 00000000..4c3aa9f3 --- /dev/null +++ b/tests/case/rule_300_test_input.vhd @@ -0,0 +1,43 @@ + +architecture ARCH of ENTITY is + +begin + + PROC_1 : process (a, b, c) is + begin + + my_case_statement_label : case boolean_1 is + + when STATE_1 => + + a <= b; + b <= c; + c <= d; + + end case; + + -- Violations below + + my_case_statement_label : case boolean_1 is + + when STATE_1 => + + a <= b; + b <= c; + c <= d; + + end case; + +my_case_statement_label : case boolean_1 is + + when STATE_1 => + + a <= b; + b <= c; + c <= d; + + end case; + + end process PROC_1; + +end architecture ARCH; diff --git a/tests/case/test_rule_300.py b/tests/case/test_rule_300.py new file mode 100644 index 00000000..db488180 --- /dev/null +++ b/tests/case/test_rule_300.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import case + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_300_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_300_test_input.fixed.vhd"), lExpected) + + +class test_case_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_300(self): + oRule = case.rule_300() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "case") + self.assertEqual(oRule.identifier, "300") + + lExpected = [21, 31] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_300(self): + oRule = case.rule_300() + + 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/exit_statement/rule_300_test_input.fixed.vhd b/tests/exit_statement/rule_300_test_input.fixed.vhd index 506af699..31e37a8c 100644 --- a/tests/exit_statement/rule_300_test_input.fixed.vhd +++ b/tests/exit_statement/rule_300_test_input.fixed.vhd @@ -8,9 +8,7 @@ begin exit; - exit_label : exit; - - exit_label : exit; + exit; end process; diff --git a/tests/exit_statement/rule_300_test_input.vhd b/tests/exit_statement/rule_300_test_input.vhd index 2101467f..fdac3e2e 100644 --- a/tests/exit_statement/rule_300_test_input.vhd +++ b/tests/exit_statement/rule_300_test_input.vhd @@ -8,9 +8,7 @@ begin exit; - exit_label : exit; - - exit_label : exit; + exit; end process; diff --git a/tests/exit_statement/rule_301_test_input.fixed.vhd b/tests/exit_statement/rule_301_test_input.fixed.vhd new file mode 100644 index 00000000..47f4f12e --- /dev/null +++ b/tests/exit_statement/rule_301_test_input.fixed.vhd @@ -0,0 +1,15 @@ + +architecture rtl of fifo is + +begin + + process is begin + exit_label : exit; + + exit_label : exit; + + exit_label : exit; + + end process; + +end architecture rtl; diff --git a/tests/exit_statement/rule_301_test_input.vhd b/tests/exit_statement/rule_301_test_input.vhd new file mode 100644 index 00000000..641fabb5 --- /dev/null +++ b/tests/exit_statement/rule_301_test_input.vhd @@ -0,0 +1,15 @@ + +architecture rtl of fifo is + +begin + + process is begin + exit_label : exit; + + exit_label : exit; + + exit_label : exit; + + end process; + +end architecture rtl; diff --git a/tests/exit_statement/test_rule_300.py b/tests/exit_statement/test_rule_300.py index 32a86cb8..9d9b64c6 100644 --- a/tests/exit_statement/test_rule_300.py +++ b/tests/exit_statement/test_rule_300.py @@ -30,7 +30,7 @@ class test_exit_statement_rule(unittest.TestCase): self.assertEqual(oRule.name, "exit_statement") self.assertEqual(oRule.identifier, "300") - lExpected = [9, 13] + lExpected = [9, 11] oRule.analyze(self.oFile) self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/tests/exit_statement/test_rule_301.py b/tests/exit_statement/test_rule_301.py new file mode 100644 index 00000000..18b23c86 --- /dev/null +++ b/tests/exit_statement/test_rule_301.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import exit_statement + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_301_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_301_test_input.fixed.vhd"), lExpected, False) + + +class test_exit_statement_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_301(self): + oRule = exit_statement.rule_301() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "exit_statement") + self.assertEqual(oRule.identifier, "301") + + lExpected = [9, 11] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_301(self): + oRule = exit_statement.rule_301() + + 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/next_statement/rule_300_test_input.fixed.vhd b/tests/next_statement/rule_300_test_input.fixed.vhd index 038fad2f..e69c62ba 100644 --- a/tests/next_statement/rule_300_test_input.fixed.vhd +++ b/tests/next_statement/rule_300_test_input.fixed.vhd @@ -5,8 +5,6 @@ architecture RTL of FIFO is loop - next_label : next my_loop when condition; - next_label : next my_loop when condition; next my_loop when condition; next my_loop when condition; next when condition; @@ -22,8 +20,6 @@ architecture RTL of FIFO is loop - next_label : next my_loop when condition; - next_label : next my_loop when condition; next my_loop when condition; next my_loop when condition; next when condition; diff --git a/tests/next_statement/rule_300_test_input.vhd b/tests/next_statement/rule_300_test_input.vhd index 65c828e5..677e95e1 100644 --- a/tests/next_statement/rule_300_test_input.vhd +++ b/tests/next_statement/rule_300_test_input.vhd @@ -5,8 +5,6 @@ architecture RTL of FIFO is loop - next_label : next my_loop when condition; - next_label : next my_loop when condition; next my_loop when condition; next my_loop when condition; next when condition; @@ -22,8 +20,6 @@ architecture RTL of FIFO is loop - next_label : next my_loop when condition; -next_label : next my_loop when condition; next my_loop when condition; next my_loop when condition; next when condition; diff --git a/tests/next_statement/rule_301_test_input.fixed.vhd b/tests/next_statement/rule_301_test_input.fixed.vhd new file mode 100644 index 00000000..7b4ca6ef --- /dev/null +++ b/tests/next_statement/rule_301_test_input.fixed.vhd @@ -0,0 +1,28 @@ + +architecture RTL of FIFO is + + function func1 return integer is begin + + loop + + next_label : next my_loop when condition; + next_label : next my_loop when condition; + + end loop; + + end function func1; + + function func1 return integer is begin + + loop + + next_label : next my_loop when condition; + next_label : next my_loop when condition; + + end loop; + + end function func1; + +begin + +end architecture RTL; diff --git a/tests/next_statement/rule_301_test_input.vhd b/tests/next_statement/rule_301_test_input.vhd new file mode 100644 index 00000000..8943040b --- /dev/null +++ b/tests/next_statement/rule_301_test_input.vhd @@ -0,0 +1,28 @@ + +architecture RTL of FIFO is + + function func1 return integer is begin + + loop + + next_label : next my_loop when condition; + next_label : next my_loop when condition; + + end loop; + + end function func1; + + function func1 return integer is begin + + loop + +next_label : next my_loop when condition; + next_label : next my_loop when condition; + + end loop; + + end function func1; + +begin + +end architecture RTL; diff --git a/tests/next_statement/test_rule_300.py b/tests/next_statement/test_rule_300.py index c946800f..ee1d7348 100644 --- a/tests/next_statement/test_rule_300.py +++ b/tests/next_statement/test_rule_300.py @@ -30,7 +30,7 @@ class test_return_statement_rule(unittest.TestCase): self.assertEqual(oRule.name, "next_statement") self.assertEqual(oRule.identifier, "300") - lExpected = [25, 26, 27, 28, 29, 30, 31, 32] + lExpected = [23, 24, 25, 26, 27, 28] oRule.analyze(self.oFile) self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/tests/next_statement/test_rule_301.py b/tests/next_statement/test_rule_301.py new file mode 100644 index 00000000..91427864 --- /dev/null +++ b/tests/next_statement/test_rule_301.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import next_statement + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_301_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_301_test_input.fixed.vhd"), lExpected) + + +class test_return_statement_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_301(self): + oRule = next_statement.rule_301() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "next_statement") + self.assertEqual(oRule.identifier, "301") + + lExpected = [19, 20] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_301(self): + oRule = next_statement.rule_301() + + 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/null_statement/rule_300_test_input.fixed.vhd b/tests/null_statement/rule_300_test_input.fixed.vhd index e596bccd..b59b9dc9 100644 --- a/tests/null_statement/rule_300_test_input.fixed.vhd +++ b/tests/null_statement/rule_300_test_input.fixed.vhd @@ -6,7 +6,6 @@ architecture RTL of FIFO is loop null; - null_label : null; end loop; @@ -17,9 +16,7 @@ architecture RTL of FIFO is loop null; - null_label : null; null; - null_label : null; end loop; diff --git a/tests/null_statement/rule_300_test_input.vhd b/tests/null_statement/rule_300_test_input.vhd index 436bc8eb..d8769085 100644 --- a/tests/null_statement/rule_300_test_input.vhd +++ b/tests/null_statement/rule_300_test_input.vhd @@ -6,7 +6,6 @@ architecture RTL of FIFO is loop null; - null_label : null; end loop; @@ -17,9 +16,7 @@ architecture RTL of FIFO is loop null; - null_label : null; null; - null_label : null; end loop; diff --git a/tests/null_statement/rule_301_test_input.fixed.vhd b/tests/null_statement/rule_301_test_input.fixed.vhd new file mode 100644 index 00000000..a2d67b45 --- /dev/null +++ b/tests/null_statement/rule_301_test_input.fixed.vhd @@ -0,0 +1,27 @@ + +architecture RTL of FIFO is + + function func1 return integer is begin + + loop + + null_label : null; + + end loop; + + end function func1; + + function func1 return integer is begin + + loop + + null_label : null; + null_label : null; + + end loop; + + end function func1; + +begin + +end architecture RTL; diff --git a/tests/null_statement/rule_301_test_input.vhd b/tests/null_statement/rule_301_test_input.vhd new file mode 100644 index 00000000..69b3ebb1 --- /dev/null +++ b/tests/null_statement/rule_301_test_input.vhd @@ -0,0 +1,27 @@ + +architecture RTL of FIFO is + + function func1 return integer is begin + + loop + + null_label : null; + + end loop; + + end function func1; + + function func1 return integer is begin + + loop + + null_label : null; + null_label : null; + + end loop; + + end function func1; + +begin + +end architecture RTL; diff --git a/tests/null_statement/test_rule_300.py b/tests/null_statement/test_rule_300.py index bafd7aba..661e601c 100644 --- a/tests/null_statement/test_rule_300.py +++ b/tests/null_statement/test_rule_300.py @@ -30,7 +30,7 @@ class test_null_statement_rule(unittest.TestCase): self.assertEqual(oRule.name, "null_statement") self.assertEqual(oRule.identifier, "300") - lExpected = [19, 20, 21, 22] + lExpected = [18, 19] oRule.analyze(self.oFile) self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/tests/null_statement/test_rule_301.py b/tests/null_statement/test_rule_301.py new file mode 100644 index 00000000..661e601c --- /dev/null +++ b/tests/null_statement/test_rule_301.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import null_statement + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_300_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_300_test_input.fixed.vhd"), lExpected) + + +class test_null_statement_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_300(self): + oRule = null_statement.rule_300() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "null_statement") + self.assertEqual(oRule.identifier, "300") + + lExpected = [18, 19] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_300(self): + oRule = null_statement.rule_300() + + 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/wait/rule_300_test_input.fixed.vhd b/tests/wait/rule_300_test_input.fixed.vhd new file mode 100644 index 00000000..c94276c4 --- /dev/null +++ b/tests/wait/rule_300_test_input.fixed.vhd @@ -0,0 +1,48 @@ + +entity ENTITY1 is + generic ( + wait_generic : std_logic := '0' + ); + port ( + wait_port : std_logic := '1' + ); +end entity ENTITY1; + +architecture ARCH of ENTITY1 is + + signal wait_for_something : std_logic; + + component ENTITY2 is + generic ( + wait_generic : std_logic := '0' + ); + port ( + wait_port : std_logic := '1' + ); + end component ENTITY2; + + +begin + + PROC1 : process (wait_for_something) is + + -- wait <-- this should not be classified as a wait + variable wait_for_other_thing : std_logic; + + begin + + wait_label : wait for 10ns; + wait_label : wait on a,b; + wait_label : wait until a = '0'; + + end process PROC1; + + U_ENTITY2 : ENTITY2 + generic map ( + wait_generic => '0' + ) + port map ( + wait_port => '1' + ); + +end architecture ARCH; diff --git a/tests/wait/rule_300_test_input.vhd b/tests/wait/rule_300_test_input.vhd new file mode 100644 index 00000000..13079d29 --- /dev/null +++ b/tests/wait/rule_300_test_input.vhd @@ -0,0 +1,48 @@ + +entity ENTITY1 is + generic ( + wait_generic : std_logic := '0' + ); + port ( + wait_port : std_logic := '1' + ); +end entity ENTITY1; + +architecture ARCH of ENTITY1 is + + signal wait_for_something : std_logic; + + component ENTITY2 is + generic ( + wait_generic : std_logic := '0' + ); + port ( + wait_port : std_logic := '1' + ); + end component ENTITY2; + + +begin + + PROC1 : process (wait_for_something) is + + -- wait <-- this should not be classified as a wait + variable wait_for_other_thing : std_logic; + + begin + + wait_label : wait for 10ns; + wait_label : wait on a,b; + wait_label : wait until a = '0'; + + end process PROC1; + + U_ENTITY2 : ENTITY2 + generic map ( + wait_generic => '0' + ) + port map ( + wait_port => '1' + ); + +end architecture ARCH; diff --git a/tests/wait/test_rule_300.py b/tests/wait/test_rule_300.py new file mode 100644 index 00000000..bb98bc86 --- /dev/null +++ b/tests/wait/test_rule_300.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import wait + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_300_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_300_test_input.fixed.vhd"), lExpected) + + +class test_wait_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_300(self): + oRule = wait.rule_300() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "wait") + self.assertEqual(oRule.identifier, "300") + + lExpected = [34, 36] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_300(self): + oRule = wait.rule_300() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/vsg/rules/case/__init__.py b/vsg/rules/case/__init__.py index 17032ba9..27b12176 100644 --- a/vsg/rules/case/__init__.py +++ b/vsg/rules/case/__init__.py @@ -23,4 +23,5 @@ from .rule_020 import rule_020 from .rule_021 import rule_021 from .rule_200 import rule_200 from .rule_201 import rule_201 +from .rule_300 import rule_300 from .rule_500 import rule_500 diff --git a/vsg/rules/case/rule_300.py b/vsg/rules/case/rule_300.py new file mode 100644 index 00000000..2995f954 --- /dev/null +++ b/vsg/rules/case/rule_300.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_indent + +lTokens = [] +lTokens.append(token.case_statement.case_label) + + +class rule_300(token_indent): + """ + This rule checks the indentation of the label. + **Violation** + + .. code-block:: vhdl + + case_label : case data is + + end case; + + **Fix** + + .. code-block:: vhdl + + case_label : case data is + + end case; + """ + + def __init__(self): + super().__init__(lTokens) diff --git a/vsg/rules/exit_statement/__init__.py b/vsg/rules/exit_statement/__init__.py index 467f257f..e7292365 100644 --- a/vsg/rules/exit_statement/__init__.py +++ b/vsg/rules/exit_statement/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from .rule_300 import rule_300 +from .rule_301 import rule_301 from .rule_500 import rule_500 from .rule_501 import rule_501 diff --git a/vsg/rules/exit_statement/rule_300.py b/vsg/rules/exit_statement/rule_300.py index d2cd9493..6643e246 100644 --- a/vsg/rules/exit_statement/rule_300.py +++ b/vsg/rules/exit_statement/rule_300.py @@ -4,7 +4,6 @@ from vsg import token from vsg.rules import token_indent lTokens = [] -lTokens.append(token.exit_statement.label) lTokens.append(token.exit_statement.exit_keyword) diff --git a/vsg/rules/exit_statement/rule_301.py b/vsg/rules/exit_statement/rule_301.py new file mode 100644 index 00000000..40d07e87 --- /dev/null +++ b/vsg/rules/exit_statement/rule_301.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_indent + +lTokens = [] +lTokens.append(token.exit_statement.label) + + +class rule_301(token_indent): + """ + This rule checks the indent of the label. + + **Violation** + + .. code-block:: vhdl + + end if; + + exit_label : exit; + + **Fix** + + .. code-block:: vhdl + + end if; + + exit_label : exit; + """ + + def __init__(self): + super().__init__(lTokens) diff --git a/vsg/rules/next_statement/__init__.py b/vsg/rules/next_statement/__init__.py index 467f257f..e7292365 100644 --- a/vsg/rules/next_statement/__init__.py +++ b/vsg/rules/next_statement/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from .rule_300 import rule_300 +from .rule_301 import rule_301 from .rule_500 import rule_500 from .rule_501 import rule_501 diff --git a/vsg/rules/next_statement/rule_300.py b/vsg/rules/next_statement/rule_300.py index 3df9f70f..5ca0d87e 100644 --- a/vsg/rules/next_statement/rule_300.py +++ b/vsg/rules/next_statement/rule_300.py @@ -4,7 +4,6 @@ from vsg import token from vsg.rules import token_indent as Rule lTokens = [] -lTokens.append(token.next_statement.label) lTokens.append(token.next_statement.next_keyword) diff --git a/vsg/rules/next_statement/rule_301.py b/vsg/rules/next_statement/rule_301.py new file mode 100644 index 00000000..dab72a1c --- /dev/null +++ b/vsg/rules/next_statement/rule_301.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_indent as Rule + +lTokens = [] +lTokens.append(token.next_statement.label) + + +class rule_301(Rule): + """ + This rule checks the indentation of the label. + + **Violation** + + .. code-block:: vhdl + + next_label : next when condition; + end function; + + **Fix** + + .. code-block:: vhdl + + next_label : next when condition; + end function; + """ + + def __init__(self): + super().__init__(lTokens) diff --git a/vsg/rules/null_statement/__init__.py b/vsg/rules/null_statement/__init__.py index 9b8ebfff..aa0062f8 100644 --- a/vsg/rules/null_statement/__init__.py +++ b/vsg/rules/null_statement/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- from .rule_300 import rule_300 +from .rule_301 import rule_301 from .rule_500 import rule_500 diff --git a/vsg/rules/null_statement/rule_300.py b/vsg/rules/null_statement/rule_300.py index b51dede7..04daccac 100644 --- a/vsg/rules/null_statement/rule_300.py +++ b/vsg/rules/null_statement/rule_300.py @@ -4,7 +4,6 @@ from vsg import token from vsg.rules import token_indent as Rule lTokens = [] -lTokens.append(token.null_statement.label) lTokens.append(token.null_statement.null_keyword) diff --git a/vsg/rules/null_statement/rule_301.py b/vsg/rules/null_statement/rule_301.py new file mode 100644 index 00000000..0fac8ea7 --- /dev/null +++ b/vsg/rules/null_statement/rule_301.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_indent as Rule + +lTokens = [] +lTokens.append(token.null_statement.label) + + +class rule_301(Rule): + """ + This rule checks the indentation of the label. + + **Violation** + + .. code-block:: vhdl + + null_label : null; + end loop; + + **Fix** + + .. code-block:: vhdl + + null_label : null; + end loop; + """ + + def __init__(self): + super().__init__(lTokens) diff --git a/vsg/rules/wait/__init__.py b/vsg/rules/wait/__init__.py index 13a39efd..12f3c0de 100644 --- a/vsg/rules/wait/__init__.py +++ b/vsg/rules/wait/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from .rule_001 import rule_001 +from .rule_300 import rule_300 from .rule_500 import rule_500 from .rule_501 import rule_501 from .rule_502 import rule_502 diff --git a/vsg/rules/wait/rule_001.py b/vsg/rules/wait/rule_001.py index 7b9cfc05..06e34088 100644 --- a/vsg/rules/wait/rule_001.py +++ b/vsg/rules/wait/rule_001.py @@ -5,7 +5,6 @@ from vsg.rules import token_indent lTokens = [] lTokens.append(token.wait_statement.wait_keyword) -lTokens.append(token.wait_statement.label) class rule_001(token_indent): diff --git a/vsg/rules/wait/rule_300.py b/vsg/rules/wait/rule_300.py new file mode 100644 index 00000000..63e3bfc0 --- /dev/null +++ b/vsg/rules/wait/rule_300.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_indent + +lTokens = [] +lTokens.append(token.wait_statement.label) + + +class rule_300(token_indent): + """ + This rule checks for indentation of the label. + Proper indentation enhances comprehension. + + **Violation** + + .. code-block:: vhdl + + begin + + wait on a,b; + wait_label : wait until a = '0'; + + **Fix** + + .. code-block:: vhdl + + begin + + wait on a,b; + wait_label : wait until a = '0'; + """ + + def __init__(self): + super().__init__(lTokens) From 4ab01fe454f84c99e21e6ebcd4408fda1e8375d1 Mon Sep 17 00:00:00 2001 From: Jukka Hertzog Date: Sun, 17 Nov 2024 01:24:43 +0000 Subject: [PATCH 3/3] Issue#1288: Added indent rules for protected type declarations and bodies (#1294) * Issue#1285: Added case rules for protected type declarations. * Issue#1285: Added case rules for protected type body declarations. * Issue#1285: Correction in protected_type_502 * Issue#1285: Added protected_type and protected_type_body to top-level rules object * Issue#1285: Added tests for protected_type rules * Issue#1285: Whitespace changes in test cases. * Issue#1285: Updated protected_type tests. * Issue#1285: Added tests for protected_type_body rules * Issue#1285: Updated documentation for protected_type and protected_type_body rules. * Issue#1288: Some corrections in next statement test names * Issue#1288: Added rule protected_type_300. * Issue#1288: Added tests for rule protected_type_300. * Issue#1288: Added rule protected_type_body_300. * Issue#1288: Added tests for rule protected_type_body_300. * Issue#1288: Updated documentation. * Issue#1288: Corrected test cases --- docs/protected_type_body_rules.rst | 21 ++++++++ docs/protected_type_rules.rst | 21 ++++++++ docs/rule_groups/indent_rule_group.rst | 2 + tests/next_statement/test_rule_300.py | 2 +- tests/next_statement/test_rule_500.py | 2 +- tests/next_statement/test_rule_501.py | 2 +- .../rule_300_test_input.fixed.vhd | 28 +++++++++++ tests/protected_type/rule_300_test_input.vhd | 28 +++++++++++ tests/protected_type/test_rule_300.py | 48 +++++++++++++++++++ .../rule_300_test_input.fixed.vhd | 28 +++++++++++ .../rule_300_test_input.vhd | 28 +++++++++++ tests/protected_type_body/test_rule_300.py | 48 +++++++++++++++++++ vsg/rules/protected_type/__init__.py | 1 + vsg/rules/protected_type/rule_300.py | 30 ++++++++++++ vsg/rules/protected_type_body/__init__.py | 1 + vsg/rules/protected_type_body/rule_300.py | 30 ++++++++++++ 16 files changed, 317 insertions(+), 3 deletions(-) create mode 100644 tests/protected_type/rule_300_test_input.fixed.vhd create mode 100644 tests/protected_type/rule_300_test_input.vhd create mode 100644 tests/protected_type/test_rule_300.py create mode 100644 tests/protected_type_body/rule_300_test_input.fixed.vhd create mode 100644 tests/protected_type_body/rule_300_test_input.vhd create mode 100644 tests/protected_type_body/test_rule_300.py create mode 100644 vsg/rules/protected_type/rule_300.py create mode 100644 vsg/rules/protected_type_body/rule_300.py diff --git a/docs/protected_type_body_rules.rst b/docs/protected_type_body_rules.rst index 9e07ed3d..0faca905 100644 --- a/docs/protected_type_body_rules.rst +++ b/docs/protected_type_body_rules.rst @@ -3,6 +3,27 @@ Protected Type Body Rules ------------------------- +protected_type_body_300 +####################### + +|phase_4| |error| |indent| + +This rule checks the indent of the end protected type body declaration. + +**Violation** + +.. code-block:: vhdl + + type flag_pt is protected body + end protected body; + +**Fix** + +.. code-block:: vhdl + + type flag_pt is protected body + end protected body; + protected_type_body_500 ####################### diff --git a/docs/protected_type_rules.rst b/docs/protected_type_rules.rst index 03677848..5371789e 100644 --- a/docs/protected_type_rules.rst +++ b/docs/protected_type_rules.rst @@ -3,6 +3,27 @@ Protected Type Rules -------------------- +protected_type_300 +################## + +|phase_4| |error| |indent| + +This rule checks the indent of the end protected type declaration. + +**Violation** + +.. code-block:: vhdl + + type flag_pt is protected + end protected; + +**Fix** + +.. code-block:: vhdl + + type flag_pt is protected + end protected; + protected_type_500 ################## diff --git a/docs/rule_groups/indent_rule_group.rst b/docs/rule_groups/indent_rule_group.rst index c932b25d..204bd806 100644 --- a/docs/rule_groups/indent_rule_group.rst +++ b/docs/rule_groups/indent_rule_group.rst @@ -81,6 +81,8 @@ Rules Enforcing Indent Rule Group * `process_001 <../process_rules.html#process-001>`_ * `process_003 <../process_rules.html#process-003>`_ * `process_006 <../process_rules.html#process-006>`_ +* `protected_type_300 <../protected_type_rules.html#protected-type-300>`_ +* `protected_type_body_300 <../protected_type_body_rules.html#protected-type-body-300>`_ * `record_type_definition_300 <../record_type_definition_rules.html#record-type-definition-300>`_ * `record_type_definition_301 <../record_type_definition_rules.html#record-type-definition-301>`_ * `report_statement_300 <../report_statement_rules.html#report-statement-300>`_ diff --git a/tests/next_statement/test_rule_300.py b/tests/next_statement/test_rule_300.py index ee1d7348..8901c395 100644 --- a/tests/next_statement/test_rule_300.py +++ b/tests/next_statement/test_rule_300.py @@ -18,7 +18,7 @@ lExpected.append("") utils.read_file(os.path.join(sTestDir, "rule_300_test_input.fixed.vhd"), lExpected) -class test_return_statement_rule(unittest.TestCase): +class test_next_statement_rule(unittest.TestCase): def setUp(self): self.oFile = vhdlFile.vhdlFile(lFile) self.assertIsNone(eError) diff --git a/tests/next_statement/test_rule_500.py b/tests/next_statement/test_rule_500.py index e565f805..2024de16 100644 --- a/tests/next_statement/test_rule_500.py +++ b/tests/next_statement/test_rule_500.py @@ -20,7 +20,7 @@ lExpected_upper.append("") utils.read_file(os.path.join(sTestDir, "rule_500_test_input.fixed_upper.vhd"), lExpected_upper) -class test_return_statement_rule(unittest.TestCase): +class test_next_statement_rule(unittest.TestCase): def setUp(self): self.oFile = vhdlFile.vhdlFile(lFile) self.assertIsNone(eError) diff --git a/tests/next_statement/test_rule_501.py b/tests/next_statement/test_rule_501.py index 62738ef4..8b055e3e 100644 --- a/tests/next_statement/test_rule_501.py +++ b/tests/next_statement/test_rule_501.py @@ -20,7 +20,7 @@ lExpected_upper.append("") utils.read_file(os.path.join(sTestDir, "rule_501_test_input.fixed_upper.vhd"), lExpected_upper) -class test_return_statement_rule(unittest.TestCase): +class test_next_statement_rule(unittest.TestCase): def setUp(self): self.oFile = vhdlFile.vhdlFile(lFile) self.assertIsNone(eError) diff --git a/tests/protected_type/rule_300_test_input.fixed.vhd b/tests/protected_type/rule_300_test_input.fixed.vhd new file mode 100644 index 00000000..605ae64f --- /dev/null +++ b/tests/protected_type/rule_300_test_input.fixed.vhd @@ -0,0 +1,28 @@ + +package test is + + type flag_pt is protected + end protected; + + type flag_pt is protected + end protected; + + type flag_pt is protected + end protected; + +end package test; + +architecture rtl of test is + + type flag_pt is protected + end protected; + + type flag_pt is protected + end protected; + + type flag_pt is protected + end protected; + +begin + +end architecture rtl; diff --git a/tests/protected_type/rule_300_test_input.vhd b/tests/protected_type/rule_300_test_input.vhd new file mode 100644 index 00000000..dcd7c3aa --- /dev/null +++ b/tests/protected_type/rule_300_test_input.vhd @@ -0,0 +1,28 @@ + +package test is + + type flag_pt is protected + end protected; + + type flag_pt is protected + end protected; + + type flag_pt is protected +end protected; + +end package test; + +architecture rtl of test is + + type flag_pt is protected + end protected; + + type flag_pt is protected + end protected; + + type flag_pt is protected +end protected; + +begin + +end architecture rtl; diff --git a/tests/protected_type/test_rule_300.py b/tests/protected_type/test_rule_300.py new file mode 100644 index 00000000..e1a2f7ef --- /dev/null +++ b/tests/protected_type/test_rule_300.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import protected_type + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_300_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_300_test_input.fixed.vhd"), lExpected) + + +class test_protected_type_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_300(self): + oRule = protected_type.rule_300() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "protected_type") + self.assertEqual(oRule.identifier, "300") + + lExpected = [8, 11, 21, 24] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_300(self): + oRule = protected_type.rule_300() + + 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/protected_type_body/rule_300_test_input.fixed.vhd b/tests/protected_type_body/rule_300_test_input.fixed.vhd new file mode 100644 index 00000000..3746b5f7 --- /dev/null +++ b/tests/protected_type_body/rule_300_test_input.fixed.vhd @@ -0,0 +1,28 @@ + +package body test is + + type flag_pt is protected body + end protected body; + + type flag_pt is protected body + end protected body; + + type flag_pt is protected body + end protected body; + +end package body test; + +architecture rtl of test is + + type flag_pt is protected body + end protected body; + + type flag_pt is protected body + end protected body; + + type flag_pt is protected body + end protected body; + +begin + +end architecture rtl; diff --git a/tests/protected_type_body/rule_300_test_input.vhd b/tests/protected_type_body/rule_300_test_input.vhd new file mode 100644 index 00000000..cbd8e6a1 --- /dev/null +++ b/tests/protected_type_body/rule_300_test_input.vhd @@ -0,0 +1,28 @@ + +package body test is + + type flag_pt is protected body + end protected body; + + type flag_pt is protected body + end protected body; + + type flag_pt is protected body +end protected body; + +end package body test; + +architecture rtl of test is + + type flag_pt is protected body + end protected body; + + type flag_pt is protected body + end protected body; + + type flag_pt is protected body +end protected body; + +begin + +end architecture rtl; diff --git a/tests/protected_type_body/test_rule_300.py b/tests/protected_type_body/test_rule_300.py new file mode 100644 index 00000000..d52c1d95 --- /dev/null +++ b/tests/protected_type_body/test_rule_300.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import protected_type_body + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_300_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_300_test_input.fixed.vhd"), lExpected) + + +class test_protected_type_body_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_300(self): + oRule = protected_type_body.rule_300() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "protected_type_body") + self.assertEqual(oRule.identifier, "300") + + lExpected = [8, 11, 21, 24] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_300(self): + oRule = protected_type_body.rule_300() + + oRule.fix(self.oFile) + + lActual = self.oFile.get_lines() + + self.assertEqual(lExpected, lActual) + + oRule.analyze(self.oFile) + self.assertEqual(oRule.violations, []) diff --git a/vsg/rules/protected_type/__init__.py b/vsg/rules/protected_type/__init__.py index f3535725..5ce48b96 100644 --- a/vsg/rules/protected_type/__init__.py +++ b/vsg/rules/protected_type/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from .rule_300 import rule_300 from .rule_500 import rule_500 from .rule_501 import rule_501 from .rule_502 import rule_502 diff --git a/vsg/rules/protected_type/rule_300.py b/vsg/rules/protected_type/rule_300.py new file mode 100644 index 00000000..baadde65 --- /dev/null +++ b/vsg/rules/protected_type/rule_300.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_indent + +lTokens = [] +lTokens.append(token.protected_type_declaration.end_keyword) + + +class rule_300(token_indent): + """ + This rule checks the indent of the end protected type declaration. + + **Violation** + + .. code-block:: vhdl + + type flag_pt is protected + end protected; + + **Fix** + + .. code-block:: vhdl + + type flag_pt is protected + end protected; + """ + + def __init__(self): + super().__init__(lTokens) diff --git a/vsg/rules/protected_type_body/__init__.py b/vsg/rules/protected_type_body/__init__.py index 90c0eaba..6bc3a1ca 100644 --- a/vsg/rules/protected_type_body/__init__.py +++ b/vsg/rules/protected_type_body/__init__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +from .rule_300 import rule_300 from .rule_500 import rule_500 from .rule_501 import rule_501 from .rule_502 import rule_502 diff --git a/vsg/rules/protected_type_body/rule_300.py b/vsg/rules/protected_type_body/rule_300.py new file mode 100644 index 00000000..9702f24a --- /dev/null +++ b/vsg/rules/protected_type_body/rule_300.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules import token_indent + +lTokens = [] +lTokens.append(token.protected_type_body.end_keyword) + + +class rule_300(token_indent): + """ + This rule checks the indent of the end protected type body declaration. + + **Violation** + + .. code-block:: vhdl + + type flag_pt is protected body + end protected body; + + **Fix** + + .. code-block:: vhdl + + type flag_pt is protected body + end protected body; + """ + + def __init__(self): + super().__init__(lTokens)