diff --git a/docs/comment_rules.rst b/docs/comment_rules.rst index 87d7d009..e741f2d7 100644 --- a/docs/comment_rules.rst +++ b/docs/comment_rules.rst @@ -69,6 +69,7 @@ comment_011 |phase_1| |disabled| |error| This rule checks for in-line comments and moves them to the line above. +The indent of the comment will be set to the indent of the current line. .. NOTE:: This rule is disabled by default. diff --git a/vsg/rules/comment/rule_011.py b/vsg/rules/comment/rule_011.py index a9cf2234..975fb53b 100644 --- a/vsg/rules/comment/rule_011.py +++ b/vsg/rules/comment/rule_011.py @@ -34,6 +34,7 @@ class rule_011(rule.Rule): lTemp = lTokens[dAction['iToken']:] lTemp.append(parser.carriage_return()) lTemp.extend(lTokens[:dAction['iToken']]) + lTemp[dAction['index']].set_indent(dAction['indent']) oViolation.set_tokens(lTemp) @@ -62,8 +63,11 @@ def create_action(lTokens, iToken): dAction = {} if isinstance(lTokens[iToken - 1], parser.whitespace): dAction['iToken'] = iToken - 1 + dAction['index'] = 1 else: dAction['iToken'] = iToken + dAction['index'] = 0 + dAction['indent'] = utils.get_indent_of_line(lTokens) return dAction diff --git a/vsg/rules/utils.py b/vsg/rules/utils.py index 28535cb0..b71d1974 100644 --- a/vsg/rules/utils.py +++ b/vsg/rules/utils.py @@ -98,3 +98,10 @@ def get_index_of_token_in_list(oToken, lTokens): if isinstance(token, oToken): return iToken return None + + +def get_indent_of_line(lTokens): + if isinstance(lTokens[0], parser.whitespace): + return lTokens[1].get_indent() + else: + return lTokens[0].get_indent() diff --git a/vsg/tests/comment/rule_011_test_input.fixed.vhd b/vsg/tests/comment/rule_011_test_input.fixed.vhd index ba89b851..0376f00a 100644 --- a/vsg/tests/comment/rule_011_test_input.fixed.vhd +++ b/vsg/tests/comment/rule_011_test_input.fixed.vhd @@ -17,4 +17,21 @@ begin -- Comment 3 e <= f; + -- BQ1/M3S1 + rx_tdata_remapped <= rx_tdata(119 downto 112) & rx_tdata(127 downto 120) & + -- BI1/M2S1 + rx_tdata(87 downto 80) & rx_tdata(95 downto 88) & + -- BQ0/M3S0 + rx_tdata(103 downto 96) & rx_tdata(111 downto 104) & + -- BQ0/M2S0 + rx_tdata(71 downto 64) & rx_tdata(79 downto 72) & + -- AQ1/M1S1 + rx_tdata(55 downto 48) & rx_tdata(63 downto 56) & + -- AI1/M0S1 + rx_tdata(23 downto 16) & rx_tdata(31 downto 24) & + -- AQ0/M1S0 + rx_tdata(39 downto 32) & rx_tdata(47 downto 40) & + -- AI0/M0S0 + rx_tdata(7 downto 0) & rx_tdata(15 downto 8); + end architecture rtl; diff --git a/vsg/tests/comment/rule_011_test_input.vhd b/vsg/tests/comment/rule_011_test_input.vhd index defa3b0c..af7086ae 100644 --- a/vsg/tests/comment/rule_011_test_input.vhd +++ b/vsg/tests/comment/rule_011_test_input.vhd @@ -13,4 +13,13 @@ begin c <= d; -- Comment 2 e <= f; -- Comment 3 + rx_tdata_remapped <= rx_tdata(119 downto 112) & rx_tdata(127 downto 120) & -- BQ1/M3S1 + rx_tdata(87 downto 80) & rx_tdata(95 downto 88) & -- BI1/M2S1 + rx_tdata(103 downto 96) & rx_tdata(111 downto 104) & -- BQ0/M3S0 + rx_tdata(71 downto 64) & rx_tdata(79 downto 72) & -- BQ0/M2S0 + rx_tdata(55 downto 48) & rx_tdata(63 downto 56) & -- AQ1/M1S1 + rx_tdata(23 downto 16) & rx_tdata(31 downto 24) & -- AI1/M0S1 + rx_tdata(39 downto 32) & rx_tdata(47 downto 40) & -- AQ0/M1S0 + rx_tdata(7 downto 0) & rx_tdata(15 downto 8); -- AI0/M0S0 + end architecture rtl; diff --git a/vsg/tests/comment/test_rule_011.py b/vsg/tests/comment/test_rule_011.py index 0d1d5ba3..a41a12a7 100644 --- a/vsg/tests/comment/test_rule_011.py +++ b/vsg/tests/comment/test_rule_011.py @@ -30,7 +30,7 @@ class test_comment_rule(unittest.TestCase): self.assertEqual(oRule.name, 'comment') self.assertEqual(oRule.identifier, '011') - lExpected = [5, 12, 13, 14] + lExpected = [5, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23] oRule.analyze(self.oFile) self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) diff --git a/vsg/vhdlFile/indent/set_token_indent.py b/vsg/vhdlFile/indent/set_token_indent.py index 7063f7f2..b816658c 100644 --- a/vsg/vhdlFile/indent/set_token_indent.py +++ b/vsg/vhdlFile/indent/set_token_indent.py @@ -27,6 +27,8 @@ def set_token_indent(dIndentMap, lTokens): sUniqueId = oToken.get_unique_id(sJoin=':') + iTokenIndent = None + if sUniqueId in lTokenKeys: token_key = dIndents[sUniqueId]['token'] after_key = dIndents[sUniqueId]['after'] @@ -105,6 +107,8 @@ def set_token_indent(dIndentMap, lTokens): dVars['insideConcurrentSignalAssignment'] = False continue + oToken.set_indent(iTokenIndent) + def update_indent_var(iIndent, update): if str(update).startswith('+'):