Merge pull request #1507 from JHertz5/issue-1391

Issue#1391: Added blank line rules for case generates
This commit is contained in:
Jukka Hertzog 2025-09-11 23:48:51 +01:00 committed by GitHub
commit cb4eb92ff3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
20 changed files with 494 additions and 0 deletions

View File

@ -53,6 +53,61 @@ This rule checks for a single space before the **=>** operator.
when 3 =>
case_generate_alternative_200
#############################
|phase_3| |error| |blank_line|
This rule checks for a blank line below the **=>** keyword.
|configuring_blank_lines_link|
**Violation**
.. code-block:: vhdl
when 0 =>
a <= b;
**Fix**
.. code-block:: vhdl
when 0 =>
a <= b;
case_generate_alternative_201
#############################
|phase_3| |error| |blank_line|
This rule checks for blank lines or comments above the **when** keyword.
|configuring_previous_line_rules_link|
The default style is :code:`allow_comment`.
**Violation**
.. code-block:: vhdl
case data is
when 3 =>
-- Comment
when 4 =>
**Fix**
.. code-block:: vhdl
case data is
when 3 =>
-- Comment
when 4 =>
case_generate_alternative_300
#############################

View File

@ -46,6 +46,32 @@ This rule checks for a single space before the **generate** keyword.
case data generate
case_generate_statement_200
###########################
|phase_3| |error| |blank_line|
This rule checks for blank lines or comments above the **end** keyword.
|configuring_blank_lines_link|
**Violation**
.. code-block:: vhdl
when others =>
null;
end generate;
**Fix**
.. code-block:: vhdl
when others =>
null;
end generate;
case_generate_statement_400
###########################

View File

@ -146,6 +146,8 @@ Rules Enforcing Blank Lines
* `case_009 <case_rules.html#case-009>`_
* `case_010 <case_rules.html#case-010>`_
* `case_200 <case_rules.html#case-200>`_
* `case_generate_alternative_200 <case_generate_alternative_rules.html#case-generate-alternative-200>`_
* `case_generate_statement_200 <case_generate_statement_rules.html#case-generate-statement-200>`_
* `component_016 <component_rules.html#component-016>`_
* `component_018 <component_rules.html#component-018>`_
* `constant_200 <constant_rules.html#constant-200>`_

View File

@ -241,6 +241,7 @@ Rules Enforcing Previous Lines
* `block_200 <block_rules.html#block-200>`_
* `case_007 <case_rules.html#case-007>`_
* `case_201 <case_rules.html#case-201>`_
* `case_generate_alternative_201 <case_generate_alternative_rules.html#case-generate-alternative-201>`_
* `component_003 <component_rules.html#component-003>`_
* `context_003 <context_rules.html#context-003>`_
* `entity_003 <entity_rules.html#entity-003>`_

View File

@ -22,6 +22,9 @@ Rules Enforcing Blank Line Rule Group
* `case_010 <../case_rules.html#case-010>`_
* `case_200 <../case_rules.html#case-200>`_
* `case_201 <../case_rules.html#case-201>`_
* `case_generate_alternative_200 <../case_generate_alternative_rules.html#case-generate-alternative-200>`_
* `case_generate_alternative_201 <../case_generate_alternative_rules.html#case-generate-alternative-201>`_
* `case_generate_statement_200 <../case_generate_statement_rules.html#case-generate-statement-200>`_
* `component_003 <../component_rules.html#component-003>`_
* `component_016 <../component_rules.html#component-016>`_
* `component_018 <../component_rules.html#component-018>`_

View File

@ -0,0 +1,26 @@
architecture ARCH of ENTITY is
begin
gen_label : case boolean_1 generate
when STATE_1 =>
a <= b;
b <= c;
c <= d;
end generate;
gen_label : case boolean_1 generate
when STATE_1 =>
a <= b;
b <= c;
c <= d;
end generate;
end architecture ARCH;

View File

@ -0,0 +1,25 @@
architecture ARCH of ENTITY is
begin
gen_label : case boolean_1 generate
when STATE_1 =>
a <= b;
b <= c;
c <= d;
end generate;
gen_label : case boolean_1 generate
when STATE_1 =>
a <= b;
b <= c;
c <= d;
end generate;
end architecture ARCH;

View File

@ -0,0 +1,32 @@
architecture ARCH of ENTITY is
begin
gen_label : case boolean_1 generate
when STATE_1 =>
-- Comment
when STATE_2 =>
end generate;
-- Violations below
gen_label : case boolean_1 generate
when STATE_1 =>
-- Comment
when STATE_2 =>
end generate;
gen_label : case boolean_2 generate
-- Comment
when STATE_1 =>
end generate;
end architecture ARCH;

View File

@ -0,0 +1,29 @@
architecture ARCH of ENTITY is
begin
gen_label : case boolean_1 generate
when STATE_1 =>
-- Comment
when STATE_2 =>
end generate;
-- Violations below
gen_label : case boolean_1 generate
when STATE_1 =>
-- Comment
when STATE_2 =>
end generate;
gen_label : case boolean_2 generate
-- Comment
when STATE_1 =>
end generate;
end architecture ARCH;

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
import os
import unittest
from tests import utils
from vsg import vhdlFile
from vsg.rules import case_generate_alternative
sTestDir = os.path.dirname(__file__)
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_200_test_input.vhd"))
lExpected = []
lExpected.append("")
utils.read_file(os.path.join(sTestDir, "rule_200_test_input.fixed.vhd"), lExpected)
class test_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
self.assertIsNone(eError)
def test_rule_200(self):
oRule = case_generate_alternative.rule_200()
self.assertTrue(oRule)
self.assertEqual(oRule.name, "case_generate_alternative")
self.assertEqual(oRule.identifier, "200")
lExpected = [18]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_fix_rule_200(self):
oRule = case_generate_alternative.rule_200()
oRule.fix(self.oFile)
lActual = self.oFile.get_lines()
self.assertEqual(lExpected, lActual)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, [])

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
import os
import unittest
from tests import utils
from vsg import vhdlFile
from vsg.rules import case_generate_alternative
sTestDir = os.path.dirname(__file__)
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_201_test_input.vhd"))
lExpected = []
lExpected.append("")
utils.read_file(os.path.join(sTestDir, "rule_201_test_input.fixed.vhd"), lExpected)
class test_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
self.assertIsNone(eError)
def test_rule_201(self):
oRule = case_generate_alternative.rule_201()
self.assertTrue(oRule)
self.assertEqual(oRule.name, "case_generate_alternative")
self.assertEqual(oRule.identifier, "201")
lExpected = [18, 19, 25]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_fix_rule_201(self):
oRule = case_generate_alternative.rule_201()
oRule.fix(self.oFile)
lActual = self.oFile.get_lines()
self.assertEqual(lExpected, lActual)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, [])

View File

@ -0,0 +1,27 @@
architecture ARCH of ENTITY is
begin
gen_label : case boolean_1 generate
when STATE_1 =>
a <= b;
b <= c;
c <= d;
end generate;
gen_label : case boolean_1 generate
when STATE_1=>
a <= b;
b <= c;
c <= d;
end generate;
end architecture ARCH;

View File

@ -0,0 +1,26 @@
architecture ARCH of ENTITY is
begin
gen_label : case boolean_1 generate
when STATE_1 =>
a <= b;
b <= c;
c <= d;
end generate;
gen_label : case boolean_1 generate
when STATE_1=>
a <= b;
b <= c;
c <= d;
end generate;
end architecture ARCH;

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
import os
import unittest
from tests import utils
from vsg import vhdlFile
from vsg.rules import case_generate_statement
sTestDir = os.path.dirname(__file__)
lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_200_test_input.vhd"))
lExpected = []
lExpected.append("")
utils.read_file(os.path.join(sTestDir, "rule_200_test_input.fixed.vhd"), lExpected)
class test_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
self.assertIsNone(eError)
def test_rule_200(self):
oRule = case_generate_statement.rule_200()
self.assertTrue(oRule)
self.assertEqual(oRule.name, "case_generate_statement")
self.assertEqual(oRule.identifier, "200")
lExpected = [24]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
def test_fix_rule_200(self):
oRule = case_generate_statement.rule_200()
oRule.fix(self.oFile)
lActual = self.oFile.get_lines()
self.assertEqual(lExpected, lActual)
oRule.analyze(self.oFile)
self.assertEqual(oRule.violations, [])

View File

@ -22,6 +22,7 @@ architecture RTL of FIFO is
begin
SOME_LABEL : case D_DEPTH generate
-- When comment
-- When comment
when 0 =>

View File

@ -2,6 +2,8 @@
from .rule_100 import rule_100
from .rule_101 import rule_101
from .rule_200 import rule_200
from .rule_201 import rule_201
from .rule_300 import rule_300
from .rule_500 import rule_500
from .rule_501 import rule_501

View File

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from vsg.rules import blank_line_below_line_ending_with_token
from vsg.token import case_generate_alternative as token
lTokens = []
lTokens.append(token.assignment)
class rule_200(blank_line_below_line_ending_with_token):
"""
This rule checks for a blank line below the **=>** keyword.
|configuring_blank_lines_link|
**Violation**
.. code-block:: vhdl
when 0 =>
a <= b;
**Fix**
.. code-block:: vhdl
when 0 =>
a <= b;
"""
def __init__(self):
super().__init__(lTokens)

View File

@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-
from vsg.rules import previous_line as Rule
from vsg.token import case_generate_alternative as token
class rule_201(Rule):
"""
This rule checks for blank lines or comments above the **when** keyword.
|configuring_previous_line_rules_link|
The default style is :code:`allow_comment`.
**Violation**
.. code-block:: vhdl
case data is
when 3 =>
-- Comment
when 4 =>
**Fix**
.. code-block:: vhdl
case data is
when 3 =>
-- Comment
when 4 =>
"""
def __init__(self):
super().__init__([token.when_keyword])
self.style = "allow_comment"

View File

@ -2,6 +2,7 @@
from .rule_100 import rule_100
from .rule_101 import rule_101
from .rule_200 import rule_200
from .rule_400 import rule_400
from .rule_500 import rule_500
from .rule_501 import rule_501

View File

@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
from vsg.rules import blank_line_above_line_starting_with_token
from vsg.token import case_generate_statement as token
class rule_200(blank_line_above_line_starting_with_token):
"""
This rule checks for blank lines or comments above the **end** keyword.
|configuring_blank_lines_link|
**Violation**
.. code-block:: vhdl
when others =>
null;
end generate;
**Fix**
.. code-block:: vhdl
when others =>
null;
end generate;
"""
def __init__(self):
super().__init__([token.end_keyword])