diff --git a/docs/configuring_whitespace_rules.rst b/docs/configuring_whitespace_rules.rst index b6dadfc98..7dc2ed6da 100644 --- a/docs/configuring_whitespace_rules.rst +++ b/docs/configuring_whitespace_rules.rst @@ -188,7 +188,12 @@ Rules Enforcing Whitespace * `external_variable_name_102 `_ * `external_variable_name_103 `_ * `external_variable_name_104 `_ +* `file_open_information_100 `_ +* `file_open_information_101 `_ +* `file_open_information_102 `_ +* `file_open_information_103 `_ * `file_100 `_ +* `file_101 `_ * `function_100 `_ * `function_101 `_ * `generate_002 `_ diff --git a/docs/file_open_information_rules.rst b/docs/file_open_information_rules.rst index 22baeba99..74ee90d62 100644 --- a/docs/file_open_information_rules.rst +++ b/docs/file_open_information_rules.rst @@ -3,6 +3,90 @@ File Open Information Rules --------------------------- +file_open_information_100 +######################### + +|phase_2| |error| |whitespace| + +This rule checks for a single space before the **open** keyword. + +|configuring_whitespace_rules_link| + +**Violation** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +**Fix** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +file_open_information_101 +######################### + +|phase_2| |error| |whitespace| + +This rule checks for a single space after the **open** keyword. + +|configuring_whitespace_rules_link| + +**Violation** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +**Fix** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +file_open_information_102 +######################### + +|phase_2| |error| |whitespace| + +This rule checks for a single space before the **is** keyword. + +|configuring_whitespace_rules_link| + +**Violation** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +**Fix** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +file_open_information_103 +######################### + +|phase_2| |error| |whitespace| + +This rule checks for a single space after the **is** keyword. + +|configuring_whitespace_rules_link| + +**Violation** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +**Fix** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + file_open_information_500 ######################### diff --git a/docs/file_rules.rst b/docs/file_rules.rst index fbb50ace4..3211bf2fa 100644 --- a/docs/file_rules.rst +++ b/docs/file_rules.rst @@ -92,6 +92,27 @@ This rule checks for a single space before the identifier. **Fix** +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +file_101 +######## + +|phase_2| |error| |whitespace| + +This rule checks for a single space after the identifier. + +|configuring_whitespace_rules_link| + +**Violation** + +.. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + +**Fix** + .. code-block:: vhdl file defaultImage : load_file_type open read_mode is load_file_name; diff --git a/docs/rule_groups/whitespace_rule_group.rst b/docs/rule_groups/whitespace_rule_group.rst index f96d54c14..7a0fd7ab5 100644 --- a/docs/rule_groups/whitespace_rule_group.rst +++ b/docs/rule_groups/whitespace_rule_group.rst @@ -82,7 +82,12 @@ Rules Enforcing Whitespace Rule Group * `external_variable_name_102 <../external_variable_name_rules.html#external-variable-name-102>`_ * `external_variable_name_103 <../external_variable_name_rules.html#external-variable-name-103>`_ * `external_variable_name_104 <../external_variable_name_rules.html#external-variable-name-104>`_ +* `file_open_information_100 <../file_open_information_rules.html#file-open-information-100>`_ +* `file_open_information_101 <../file_open_information_rules.html#file-open-information-101>`_ +* `file_open_information_102 <../file_open_information_rules.html#file-open-information-102>`_ +* `file_open_information_103 <../file_open_information_rules.html#file-open-information-103>`_ * `file_100 <../file_rules.html#file-100>`_ +* `file_101 <../file_rules.html#file-101>`_ * `function_100 <../function_rules.html#function-100>`_ * `function_101 <../function_rules.html#function-101>`_ * `generate_002 <../generate_rules.html#generate-002>`_ diff --git a/tests/file_open_information/rule_100_test_input.fixed.vhd b/tests/file_open_information/rule_100_test_input.fixed.vhd new file mode 100644 index 000000000..6d6757e80 --- /dev/null +++ b/tests/file_open_information/rule_100_test_input.fixed.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_open_information/rule_100_test_input.vhd b/tests/file_open_information/rule_100_test_input.vhd new file mode 100644 index 000000000..709d90572 --- /dev/null +++ b/tests/file_open_information/rule_100_test_input.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_open_information/rule_101_test_input.fixed.vhd b/tests/file_open_information/rule_101_test_input.fixed.vhd new file mode 100644 index 000000000..6d6757e80 --- /dev/null +++ b/tests/file_open_information/rule_101_test_input.fixed.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_open_information/rule_101_test_input.vhd b/tests/file_open_information/rule_101_test_input.vhd new file mode 100644 index 000000000..a9b546da1 --- /dev/null +++ b/tests/file_open_information/rule_101_test_input.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_open_information/rule_102_test_input.fixed.vhd b/tests/file_open_information/rule_102_test_input.fixed.vhd new file mode 100644 index 000000000..6d6757e80 --- /dev/null +++ b/tests/file_open_information/rule_102_test_input.fixed.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_open_information/rule_102_test_input.vhd b/tests/file_open_information/rule_102_test_input.vhd new file mode 100644 index 000000000..4495731bd --- /dev/null +++ b/tests/file_open_information/rule_102_test_input.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_open_information/rule_103_test_input.fixed.vhd b/tests/file_open_information/rule_103_test_input.fixed.vhd new file mode 100644 index 000000000..6d6757e80 --- /dev/null +++ b/tests/file_open_information/rule_103_test_input.fixed.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_open_information/rule_103_test_input.vhd b/tests/file_open_information/rule_103_test_input.vhd new file mode 100644 index 000000000..9b529a41c --- /dev/null +++ b/tests/file_open_information/rule_103_test_input.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_open_information/test_rule_100.py b/tests/file_open_information/test_rule_100.py new file mode 100644 index 000000000..2b8b13180 --- /dev/null +++ b/tests/file_open_information/test_rule_100.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_open_information + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_100_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_100_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_100(self): + oRule = file_open_information.rule_100() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "100") + + lExpected = [6] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_100(self): + oRule = file_open_information.rule_100() + + 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/file_open_information/test_rule_101.py b/tests/file_open_information/test_rule_101.py new file mode 100644 index 000000000..ec8346322 --- /dev/null +++ b/tests/file_open_information/test_rule_101.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_open_information + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_101_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_101_test_input.fixed.vhd"), lExpected) + + +class test_file_declaration_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_101(self): + oRule = file_open_information.rule_101() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "101") + + lExpected = [6] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_101(self): + oRule = file_open_information.rule_101() + + 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/file_open_information/test_rule_102.py b/tests/file_open_information/test_rule_102.py new file mode 100644 index 000000000..645226ab7 --- /dev/null +++ b/tests/file_open_information/test_rule_102.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_open_information + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_102_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_102_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_102(self): + oRule = file_open_information.rule_102() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "102") + + lExpected = [6] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_102(self): + oRule = file_open_information.rule_102() + + 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/file_open_information/test_rule_103.py b/tests/file_open_information/test_rule_103.py new file mode 100644 index 000000000..72d5a15b1 --- /dev/null +++ b/tests/file_open_information/test_rule_103.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_open_information + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_103_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_103_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_103(self): + oRule = file_open_information.rule_103() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file_open_information") + self.assertEqual(oRule.identifier, "103") + + lExpected = [6] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_103(self): + oRule = file_open_information.rule_103() + + 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/file_statement/rule_101_test_input.fixed.vhd b/tests/file_statement/rule_101_test_input.fixed.vhd new file mode 100644 index 000000000..6d6757e80 --- /dev/null +++ b/tests/file_statement/rule_101_test_input.fixed.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_statement/rule_101_test_input.vhd b/tests/file_statement/rule_101_test_input.vhd new file mode 100644 index 000000000..24d4288c1 --- /dev/null +++ b/tests/file_statement/rule_101_test_input.vhd @@ -0,0 +1,10 @@ + +architecture rtl of fifo is + + file defaultImage : load_file_type open read_mode is load_file_name; + + file defaultImage : load_file_type open read_mode is load_file_name; + +begin + +end architecture rtl; diff --git a/tests/file_statement/test_rule_101.py b/tests/file_statement/test_rule_101.py new file mode 100644 index 000000000..9e0c8c3c8 --- /dev/null +++ b/tests/file_statement/test_rule_101.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import os +import unittest + +from tests import utils +from vsg import vhdlFile +from vsg.rules import file_statement + +sTestDir = os.path.dirname(__file__) + +lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_101_test_input.vhd")) + +dIndentMap = utils.read_indent_file() + +lExpected = [] +lExpected.append("") +utils.read_file(os.path.join(sTestDir, "rule_101_test_input.fixed.vhd"), lExpected) + + +class test_rule(unittest.TestCase): + def setUp(self): + self.oFile = vhdlFile.vhdlFile(lFile) + self.assertIsNone(eError) + self.oFile.set_indent_map(dIndentMap) + + def test_rule_101(self): + oRule = file_statement.rule_101() + self.assertTrue(oRule) + self.assertEqual(oRule.name, "file") + self.assertEqual(oRule.identifier, "101") + + lExpected = [6] + + oRule.analyze(self.oFile) + self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations)) + + def test_fix_rule_101(self): + oRule = file_statement.rule_101() + + 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/file_open_information/__init__.py b/vsg/rules/file_open_information/__init__.py index f35357259..0b85b82e3 100644 --- a/vsg/rules/file_open_information/__init__.py +++ b/vsg/rules/file_open_information/__init__.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +from .rule_100 import rule_100 +from .rule_101 import rule_101 +from .rule_102 import rule_102 +from .rule_103 import rule_103 from .rule_500 import rule_500 from .rule_501 import rule_501 from .rule_502 import rule_502 diff --git a/vsg/rules/file_open_information/rule_100.py b/vsg/rules/file_open_information/rule_100.py new file mode 100644 index 000000000..87600dcd2 --- /dev/null +++ b/vsg/rules/file_open_information/rule_100.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules.whitespace_between_tokens import Rule + + +class rule_100(Rule): + """ + This rule checks for a single space before the **open** keyword. + + |configuring_whitespace_rules_link| + + **Violation** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + + **Fix** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + """ + + def __init__(self): + Rule.__init__(self) + self.left_token = token.type_mark.name + self.right_token = token.file_open_information.open_keyword diff --git a/vsg/rules/file_open_information/rule_101.py b/vsg/rules/file_open_information/rule_101.py new file mode 100644 index 000000000..bcb63b46d --- /dev/null +++ b/vsg/rules/file_open_information/rule_101.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +from vsg.rules.whitespace_between_tokens import Rule +from vsg.token import file_open_information as token + + +class rule_101(Rule): + """ + This rule checks for a single space after the **open** keyword. + + |configuring_whitespace_rules_link| + + **Violation** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + + **Fix** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + """ + + def __init__(self): + Rule.__init__(self) + self.left_token = token.open_keyword + self.right_token = token.file_open_kind_expression diff --git a/vsg/rules/file_open_information/rule_102.py b/vsg/rules/file_open_information/rule_102.py new file mode 100644 index 000000000..c6fc7fb42 --- /dev/null +++ b/vsg/rules/file_open_information/rule_102.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +from vsg.rules.whitespace_between_tokens import Rule +from vsg.token import file_open_information as token + + +class rule_102(Rule): + """ + This rule checks for a single space before the **is** keyword. + + |configuring_whitespace_rules_link| + + **Violation** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + + **Fix** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + """ + + def __init__(self): + Rule.__init__(self) + self.left_token = token.file_open_kind_expression + self.right_token = token.is_keyword diff --git a/vsg/rules/file_open_information/rule_103.py b/vsg/rules/file_open_information/rule_103.py new file mode 100644 index 000000000..1b47098af --- /dev/null +++ b/vsg/rules/file_open_information/rule_103.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules.whitespace_after_token import Rule + +lTokens = [] +lTokens.append(token.file_open_information.is_keyword) + + +class rule_103(Rule): + """ + This rule checks for a single space after the **is** keyword. + + |configuring_whitespace_rules_link| + + **Violation** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + + **Fix** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + """ + + def __init__(self): + super().__init__(lTokens) diff --git a/vsg/rules/file_statement/__init__.py b/vsg/rules/file_statement/__init__.py index 4790a7f76..394f6a60f 100644 --- a/vsg/rules/file_statement/__init__.py +++ b/vsg/rules/file_statement/__init__.py @@ -4,4 +4,5 @@ from .rule_002 import rule_002 from .rule_003 import rule_003 from .rule_100 import rule_100 +from .rule_101 import rule_101 from .rule_500 import rule_500 diff --git a/vsg/rules/file_statement/rule_101.py b/vsg/rules/file_statement/rule_101.py new file mode 100644 index 000000000..34daf63e3 --- /dev/null +++ b/vsg/rules/file_statement/rule_101.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +from vsg import token +from vsg.rules.whitespace_between_tokens import Rule + + +class rule_101(Rule): + """ + This rule checks for a single space after the identifier. + + |configuring_whitespace_rules_link| + + **Violation** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + + **Fix** + + .. code-block:: vhdl + + file defaultImage : load_file_type open read_mode is load_file_name; + """ + + def __init__(self): + Rule.__init__(self) + self.left_token = token.file_declaration.colon + self.right_token = token.type_mark.name