Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/configuring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Configuring
configuring_indent_rules.rst
configuring_keyword_alignment_rules.rst
configuring_length_rules.rst
configuring_library_and_package_name_restriction_rules.rst
configuring_move_token_rules.rst
configuring_multiline_assert_rule.rst
configuring_multiline_constraint_rules.rst
Expand Down
4 changes: 2 additions & 2 deletions docs/configuring_disabled_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ Rules Disabled by Default
* `generic_map_601 <generic_map_rules.html#generic-map-601>`_
* `instantiation_600 <instantiation_rules.html#instantiation-600>`_
* `instantiation_601 <instantiation_rules.html#instantiation-601>`_

* `interface_incomplete_type_declaration_600 <../interface_incomplete_type_declaration_rules.html#interface-incomplete-type-declaration-600>`_
* `interface_incomplete_type_declaration_601 <../interface_incomplete_type_declaration_rules.html#interface-incomplete-type-declaration-601>`_

* `library_012 <library_rules.html#library-012>`_
* `loop_statement_006 <loop_statement_rules.html#loop-statement-006>`_
* `loop_statement_007 <loop_statement_rules.html#loop-statement-007>`_
* `loop_statement_600 <loop_statement_rules.html#loop-statement-600>`_
Expand Down Expand Up @@ -102,6 +101,7 @@ Rules Disabled by Default
* `type_100 <type_rules.html#type-100>`_
* `type_200 <type_rules.html#type-200>`_
* `type_600 <type_rules.html#type-600>`_
* `use_clause_001 <use_clause_rules.html#use-clause-001>`_
* `variable_012 <variable_rules.html#variable-012>`_
* `variable_100 <variable_rules.html#variable-100>`_
* `variable_600 <variable_rules.html#variable-600>`_
70 changes: 70 additions & 0 deletions docs/configuring_library_and_package_name_restriction_rules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

.. _configuring-library-and-package-name-restriction-rules:

Configuring Library and Package Name Restriction Rules
------------------------------------------------------

There are rules which will check for invalid package names in library and use clauses.
These rules are disabled by default and must be enabled before they will perform any checks.

There is one option for these rules:

.. |names| replace::
:code:`names`

.. |default| replace::
:code:`std_logic_arith` for **use_clause_001**. None for **library_012**

.. |values__names| replace::
List of strings

.. |action__names| replace::
Search for libraries and packages with the user defined names

+--------------------------------------+-----------------+-----------+------------------------------------------------+
| Option | Values | Default | Description |
+======================================+=================+===========+================================================+
| |names| | |values__names| | |default| | * |action__names| |
+--------------------------------------+-----------------+-----------+------------------------------------------------+

This is an example of how to configure the option.

.. code-block:: yaml

rule :
library_012:
names:
- "work"
- "std_logic_arith"

.. NOTE:: All examples below are using the rule **use_clause_001**.

Example: |names| set to list ["std_logic_arith"]
################################################

The following code would fail with this option:

.. code-Block:: vhdl

library ieee;
use ieee.std_logic_arith.all;

Example: |names| set to ["std_logic_arith", "my_package"]
##############################################

The following code would fail three times with this option:

.. code-block:: vhdl

library ieee;
use ieee.std_logic_arith.all;

library work;
use work.my_package.all;


Rules Enforcing Valid Names
###########################

* `library_012 <library_rules.html#library-012>`_
* `use_clause_001 <use_clause_rules.html#use-clause-001>`_
17 changes: 17 additions & 0 deletions docs/library_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,23 @@ This rule checks the **use** keyword is on its own line.
context c1 is library ieee;
use ieee.std_logic_1164.all; end context c1;
library_012
###########

|phase_7| |disabled| |error| |unfixable| |naming|

This rule checks for libraries that have been restricted by the user.

|configuring_library_and_package_name_restriction_rules_link|

.. NOTE:: This rule is disabled by default.

**Violation**

.. code-block:: vhdl
library bad_lib;
library_500
###########

Expand Down
3 changes: 3 additions & 0 deletions docs/links.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@

.. |configuring_comment_indenting_link| replace::
Refer to :ref:`configuring-comment-indenting` for configuration options.

.. |configuring_library_and_package_name_restriction_rules_link| replace::
Refer to :ref:`configuring-library-and-package-name-restriction-rules` for configuration options.
4 changes: 2 additions & 2 deletions docs/rule_groups/naming_rule_group.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ Rules Enforcing Naming Rule Group
* `generic_map_601 <../generic_map_rules.html#generic-map-601>`_
* `instantiation_600 <../instantiation_rules.html#instantiation-600>`_
* `instantiation_601 <../instantiation_rules.html#instantiation-601>`_

* `interface_incomplete_type_declaration_600 <../interface_incomplete_type_declaration_rules.html#interface-incomplete-type-declaration-600>`_
* `interface_incomplete_type_declaration_601 <../interface_incomplete_type_declaration_rules.html#interface-incomplete-type-declaration-601>`_

* `library_012 <../library_rules.html#library-012>`_
* `loop_statement_600 <../loop_statement_rules.html#loop-statement-600>`_
* `loop_statement_601 <../loop_statement_rules.html#loop-statement-601>`_
* `loop_statement_602 <../loop_statement_rules.html#loop-statement-602>`_
Expand Down Expand Up @@ -58,5 +57,6 @@ Rules Enforcing Naming Rule Group
* `subtype_600 <../subtype_rules.html#subtype-600>`_
* `type_015 <../type_rules.html#type-015>`_
* `type_600 <../type_rules.html#type-600>`_
* `use_clause_001 <../use_clause_rules.html#use-clause-001>`_
* `variable_012 <../variable_rules.html#variable-012>`_
* `variable_600 <../variable_rules.html#variable-600>`_
4 changes: 2 additions & 2 deletions docs/unfixable_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ With multiple options available, the user is required to make the decision.

* `architecture_025 <architecture_rules.html#architecture-025>`_
* `instantiation_036 <instantiation_rules.html#instantiation-036>`_
* `library_012 <../library_rules.html#library-012>`_
* `use_clause_001 <../use_clause_rules.html#use-clause-001>`_

Lengths
-------
Expand Down Expand Up @@ -104,10 +106,8 @@ With multiple options available, the user is required to make the decision.
* `generic_map_601 <generic_map_rules.html#generic-map-601>`_
* `instantiation_600 <instantiation_rules.html#instantiation-600>`_
* `instantiation_601 <instantiation_rules.html#instantiation-601>`_

* `interface_incomplete_type_declaration_600 <../interface_incomplete_type_declaration_rules.html#interface-incomplete-type-declaration-600>`_
* `interface_incomplete_type_declaration_601 <../interface_incomplete_type_declaration_rules.html#interface-incomplete-type-declaration-601>`_

* `loop_statement_600 <loop_statement_rules.html#loop-statement-600>`_
* `loop_statement_601 <loop_statement_rules.html#loop-statement-601>`_
* `loop_statement_602 <loop_statement_rules.html#loop-statement-602>`_
Expand Down
19 changes: 19 additions & 0 deletions docs/use_clause_rules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
Use Clause Rules
----------------

use_clause_001
##############

|phase_7| |disabled| |error| |unfixable| |naming|

This rule checks for packages that have been restricted by the user.

|configuring_library_and_package_name_restriction_rules_link|

.. NOTE:: This rule is disabled by default.

.. NOTE:: This rule is configured to restrict the std_logic_arith package by default.

**Violation**

.. code-block:: vhdl
use ieee.std_logic_arith.all;
use_clause_500
##############

Expand Down
5 changes: 5 additions & 0 deletions tests/library/rule_012_test_input.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

library ieee;
library work;
library std;
library bad_lib;
82 changes: 82 additions & 0 deletions tests/library/test_rule_012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-

import os
import unittest

from tests import utils
from vsg import vhdlFile
from vsg.rules import library

sTestDir = os.path.dirname(__file__)

lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_012_test_input.vhd"))


class test_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
self.assertIsNone(eError)

def test_rule_012(self):
oRule = library.rule_012()
self.assertTrue(oRule)
self.assertEqual(oRule.name, "library")
self.assertEqual(oRule.identifier, "012")
self.assertFalse(oRule.fixable)
self.assertTrue(oRule.disable)
self.assertEqual(oRule.groups, ["naming"])

lExpected = []
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Library name is on list of restricted names: ", oRule._get_solution(None))

oRule.violations = []
oRule.names = []
oRule.names.append("ieee")
lExpected = [2]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Library name is on list of restricted names: ieee", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["work"]
lExpected = [3]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Library name is on list of restricted names: work", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["std"]
lExpected = [4]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Library name is on list of restricted names: std", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["bad_lib"]
lExpected = [5]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Library name is on list of restricted names: bad_lib", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["ieee", "bad_lib"]
lExpected = [2, 5]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Library name is on list of restricted names: ieee, bad_lib", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["ieee", "work", "std"]
lExpected = [2, 3, 4]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Library name is on list of restricted names: ieee, work, std", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["ieee", "work", "std", "bad_lib"]
lExpected = [2, 3, 4, 5]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Library name is on list of restricted names: ieee, work, std, bad_lib", oRule._get_solution(None))
10 changes: 10 additions & 0 deletions tests/use_clause/rule_001_test_input.vhd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

library ieee;
use ieee.std_logic_arith.all;
use ieee.std_logic_1164.std_logic;

library std;
use std.env.all;

library bad_lib;
use bad_lib.bad_pkg.bad_obj;
84 changes: 84 additions & 0 deletions tests/use_clause/test_rule_001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-

import os
import unittest

from tests import utils
from vsg import vhdlFile
from vsg.rules import use_clause

sTestDir = os.path.dirname(__file__)

lFile, eError = vhdlFile.utils.read_vhdlfile(os.path.join(sTestDir, "rule_001_test_input.vhd"))


class test_rule(unittest.TestCase):
def setUp(self):
self.oFile = vhdlFile.vhdlFile(lFile)
self.assertIsNone(eError)

def test_rule_001(self):
oRule = use_clause.rule_001()
self.assertTrue(oRule)
self.assertEqual(oRule.names, ["std_logic_arith"])
self.assertEqual(oRule.name, "use_clause")
self.assertEqual(oRule.identifier, "001")
self.assertFalse(oRule.fixable)
self.assertTrue(oRule.disable)
self.assertEqual(oRule.groups, ["naming"])

lExpected = []
oRule.names = []
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Package name is on list of restricted names: ", oRule._get_solution(None))

oRule.violations = []
oRule.names = []
oRule.names.append("std_logic_arith")
lExpected = [3]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Package name is on list of restricted names: std_logic_arith", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["std_logic_1164"]
lExpected = [4]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Package name is on list of restricted names: std_logic_1164", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["env"]
lExpected = [7]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Package name is on list of restricted names: env", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["bad_pkg"]
lExpected = [10]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Package name is on list of restricted names: bad_pkg", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["std_logic_arith", "bad_pkg"]
lExpected = [3, 10]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Package name is on list of restricted names: std_logic_arith, bad_pkg", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["std_logic_arith", "std_logic_1164", "env"]
lExpected = [3, 4, 7]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Package name is on list of restricted names: std_logic_arith, std_logic_1164, env", oRule._get_solution(None))

oRule.violations = []
oRule.names = ["std_logic_arith", "std_logic_1164", "env", "bad_pkg"]
lExpected = [3, 4, 7, 10]
oRule.analyze(self.oFile)
self.assertEqual(lExpected, utils.extract_violation_lines_from_violation_object(oRule.violations))
self.assertEqual("Package name is on list of restricted names: std_logic_arith, std_logic_1164, env, bad_pkg", oRule._get_solution(None))
1 change: 1 addition & 0 deletions vsg/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from .insert_token_next_to_token_if_it_does_not_exist_between_tokens_using_value_from_token import (
insert_token_next_to_token_if_it_does_not_exist_between_tokens_using_value_from_token,
)
from .does_token_value_match_none_of import does_token_value_match_none_of
from .does_token_value_match_one_of import does_token_value_match_one_of
from .align_tokens_in_region_between_tokens import align_tokens_in_region_between_tokens
from .align_tokens_in_region_between_tokens_unless_between_tokens import align_tokens_in_region_between_tokens_unless_between_tokens
Expand Down
Loading
Loading