Updates for issue #450.

Replacing indent_step option with indentSize attribute.
This commit is contained in:
Jeremiah Leary 2021-03-01 20:56:43 -06:00
parent 0604fcf219
commit 90efd757c1
3 changed files with 30 additions and 80 deletions

View File

@ -11,9 +11,6 @@ There are several options to these rules:
| align_left | boolean | True | True = New lines will be aligned left. |
| | | | False = Align to left of assignment operator. |
+----------------------+-----------------------------------------------------------------------------+
| indent_step | integer | 1 | Sets how many columns to the right to check for |
| | | | alignment. |
+----------------------+-----------------------------------------------------------------------------+
| align_paren | boolean | True | True = Use open parenthesis for alignment. |
| | | | False = Do not use open parenthesis for alignment. |
+----------------------+-----------------------------------------------------------------------------+
@ -25,71 +22,12 @@ This is an example of how to configure the option.
rule :
constant_012:
align_left : False
indent_step : 2
align_paren : True
.. NOTE:: All examples below are using the rule **constant_012**.
Example: align_left True, align_paren False and indent_step 1
#############################################################
The following code would fail with this option:
.. code-Block:: vhdl
constant c_const : t_type :=
(
(
a => 0,
b => 1
),
(
c => 0,
d => 1
)
);
constant c_const : t_type :=
(
(
a => 0,
b => 1
),
(
c => 0,
d => 1
)
);
The following code would pass with this option:
.. code-block:: vhdl
constant c_const : t_type :=
(
(
a => 0,
b => 1
),
(
c => 0,
d => 1
)
);
constant c_const : t_type :=
(
(
a => 0,
b => 1
),
(
c => 0,
d => 1
)
);
Example: align_left True, align_paren False and indent_step 2
#############################################################
Example: align_left True, align_paren False
###########################################
The following code would fail with this option:
@ -147,8 +85,8 @@ The following code would pass with this option:
)
);
Example: align_left False, align_paren False and indent_step 2
##############################################################
Example: align_left False, align_paren False
############################################
The following code would fail with this option:
@ -182,8 +120,8 @@ The following code would pass with this option:
)
);
Example: align_left True, align_paren True and indent_step 2
############################################################
Example: align_left True, align_paren True
##########################################
The following code would fail with this option:

View File

@ -34,8 +34,6 @@ class rule_012(rule.Rule):
self.lTokenPairs = lTokenPairs
self.align_left = False
self.configuration.append('align_left')
self.indent_step = 1
self.configuration.append('indent_step')
self.align_paren = True
self.configuration.append('align_paren')
@ -53,14 +51,15 @@ class rule_012(rule.Rule):
iLine, lTokens = utils.get_toi_parameters(oToi)
# print('='*5 + str(iLine) + '='*70)
iFirstLine = iLine
iFirstColumn, iNextColumn, iLastColumn = _find_first_column(oFile, oToi, self.align_left, self.indentSize, self.indent_step)
iFirstLine, iFirstLineIndent = _get_first_line_info(iLine, oFile)
iFirstColumn, iNextColumn, iLastColumn = _find_first_column(oFile, oToi, self.align_left, iFirstLineIndent, self.indentSize)
iAssignColumn = oFile.get_column_of_token_index(oToi.get_start_index())
iColumn = iAssignColumn
# iIndent = 0
dActualIndent = {}
dActualIndent[iLine] = oFile.get_indent_of_line_at_index(oToi.get_start_index()) * self.indentSize
dActualIndent[iLine] = iFirstLineIndent
lParens = []
dIndex = {}
@ -103,11 +102,11 @@ class rule_012(rule.Rule):
continue
if not self.align_paren and self.align_left:
dExpectedIndent = _analyze_align_paren_false(iFirstLine, iLastLine, lParens, self.indent_step, dActualIndent, bStartsWithParen)
dExpectedIndent = _analyze_align_paren_false(iFirstLine, iLastLine, lParens, self.indentSize, dActualIndent, bStartsWithParen)
if self.align_paren and not self.align_left:
dExpectedIndent = _analyze_align_paren_true(iFirstLine, iLastLine, lParens, dActualIndent, self.indent_step, bStartsWithParen, iAssignColumn)
dExpectedIndent = _analyze_align_paren_true(iFirstLine, iLastLine, lParens, dActualIndent, self.indentSize, bStartsWithParen, iAssignColumn)
if self.align_paren and self.align_left:
dExpectedIndent = _analyze_align_paren_true_align_left_true(iFirstLine, iLastLine, lParens, dActualIndent, self.indent_step, bStartsWithParen, iAssignColumn)
dExpectedIndent = _analyze_align_paren_true_align_left_true(iFirstLine, iLastLine, lParens, dActualIndent, self.indentSize, bStartsWithParen, iAssignColumn)
# print(f'Actual = {dActualIndent}')
# print(f'Expect = {dExpectedIndent}')
@ -415,3 +414,10 @@ def _starts_with_paren(lTokens):
if isinstance(lTokens[iToken], parser.open_parenthesis):
return True
return False
def _get_first_line_info(iLine, oFile):
lTemp = oFile.get_tokens_from_line(iLine)
iIndent = len(lTemp.get_tokens()[0].get_value())
return iLine, iIndent

View File

@ -45,6 +45,7 @@ class test_constant_rule(unittest.TestCase):
oRule = constant.rule_012()
oRule.align_left = False
oRule.align_paren = True
oRule.indentSize = 1
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'constant')
self.assertEqual(oRule.identifier, '012')
@ -69,6 +70,7 @@ class test_constant_rule(unittest.TestCase):
oRule = constant.rule_012()
oRule.align_left = False
oRule.align_paren = True
oRule.indentSize = 1
oRule.fix(self.oFile)
@ -83,7 +85,7 @@ class test_constant_rule(unittest.TestCase):
oRule = constant.rule_012()
oRule.align_left = False
oRule.align_paren = True
oRule.indent_step = 2
oRule.indentSize = 2
oRule.fix(self.oFile)
@ -99,6 +101,7 @@ class test_constant_rule(unittest.TestCase):
oRule = constant.rule_012()
oRule.align_left = True
oRule.align_paren = False
oRule.indentSize = 1
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'constant')
self.assertEqual(oRule.identifier, '012')
@ -123,6 +126,7 @@ class test_constant_rule(unittest.TestCase):
oRule = constant.rule_012()
oRule.align_left = True
oRule.align_paren = False
oRule.indentSize = 1
oRule.fix(self.oFile)
@ -138,6 +142,7 @@ class test_constant_rule(unittest.TestCase):
oRule = constant.rule_012()
oRule.align_left = True
oRule.align_paren = True
oRule.indentSize = 1
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'constant')
self.assertEqual(oRule.identifier, '012')
@ -162,6 +167,7 @@ class test_constant_rule(unittest.TestCase):
oRule = constant.rule_012()
oRule.align_left = True
oRule.align_paren = True
oRule.indentSize = 1
oRule.fix(self.oFile)
@ -177,7 +183,7 @@ class test_constant_rule(unittest.TestCase):
oRule = constant.rule_012()
oRule.align_left = True
oRule.align_paren = False
oRule.indent_step = 2
oRule.indentSize = 2
oRule.fix(self.oFile)