File tree Expand file tree Collapse file tree 9 files changed +91
-0
lines changed Expand file tree Collapse file tree 9 files changed +91
-0
lines changed Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ GNATcheck rules.
107107* :ref: `Nested_Paths `
108108* :ref: `Nested_Subprograms `
109109* :ref: `No_Closing_Names `
110+ * :ref: `No_Dependence `
110111* :ref: `No_Explicit_Real_Range `
111112* :ref: `No_Inherited_Classwide_Pre `
112113* :ref: `No_Others_In_Exception_Handlers `
Original file line number Diff line number Diff line change @@ -6123,6 +6123,39 @@ A line containing one or more identifiers may end with a comment.
61236123
61246124
61256125
6126+ .. _No_Dependence :
6127+
6128+ ``No_Dependence ``
6129+ ^^^^^^^^^^^^^^^^^
6130+
6131+ .. index :: No_Dependence
6132+
6133+ Flag every explicit dependency (with clause) to any of the library units
6134+ designated by names passed as parameters.
6135+
6136+ This rule has the following optional parameter for the ``+R `` option and for
6137+ LKQL rule options files:
6138+
6139+ *Unit_Names: list[string] *
6140+ List of fully qualified names designating the library units that
6141+ should not be explicitly depended upon.
6142+
6143+ The list of unit names is case insensitive. Any case can be used both in
6144+ the parameter or in the code's with clauses.
6145+
6146+ .. rubric :: Example
6147+
6148+ .. code-block :: ada
6149+ :emphasize-lines: 2
6150+
6151+ -- if the rule is activated as +RNo_Dependence:Unchecked_Conversion
6152+ with Unchecked_Conversion; -- FLAG
6153+
6154+ package Foo is
6155+ end Foo;
6156+
6157+
6158+
61266159 .. _Numeric_Format :
61276160
61286161``Numeric_Format ``
Original file line number Diff line number Diff line change 1+ import stdlib
2+
3+ @check(category="Style", subcategory="Readability", message="Forbidden dependency")
4+ fun no_dependence(node, unit_names=[]) =
5+ |" Flag every explicit dependency (with clause) to any of the library units
6+ |" designated by names passed as parameters.
7+ |"
8+ |" This rule has the following optional parameter for the ``+R`` option and for
9+ |" LKQL rule options files:
10+ |"
11+ |" *Unit_Names: list[string]*
12+ |" List of fully qualified names designating the library units that
13+ |" should not be explicitly depended upon.
14+ |"
15+ |" The list of unit names is case insensitive. Any case can be used both in
16+ |" the parameter or in the code's with clauses.
17+ |"
18+ |" .. rubric:: Example
19+ |"
20+ |" .. code-block:: ada
21+ |" :emphasize-lines: 2
22+ |"
23+ |" -- if the rule is activated as +RNo_Dependence:Unchecked_Conversion
24+ |" with Unchecked_Conversion; -- FLAG
25+ |"
26+ |" package Foo is
27+ |" end Foo;
28+ node is n@Name(
29+ any parent(depth=2): WithClause
30+ ) when stdlib.any([name.to_lower_case == n.text.to_lower_case for name in unit_names])
Original file line number Diff line number Diff line change 1+ package Custom.Unchecked_Conversion is
2+ end Custom.Unchecked_Conversion ;
Original file line number Diff line number Diff line change 1+ package Custom is
2+ end Custom ;
Original file line number Diff line number Diff line change 1+ with Ada.Unchecked_Conversion ; -- FLAG
2+ with Unchecked_Conversion ; -- FLAG
3+ with Custom.Unchecked_Conversion ; -- NOFLAG
4+
5+ procedure Test is
6+ begin
7+ null ;
8+ end Test ;
Original file line number Diff line number Diff line change 1+ test.adb:1:6: rule violation: Forbidden dependency
2+ 1 | with Ada.Unchecked_Conversion; -- FLAG
3+ | ^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+ test.adb:2:6: rule violation: Forbidden dependency
6+ 2 | with Unchecked_Conversion; -- FLAG
7+ | ^^^^^^^^^^^^^^^^^^^^
8+
Original file line number Diff line number Diff line change 1+ driver : ' checker'
2+ rule_name : no_dependence
3+ rule_arguments :
4+ no_dependence.unit_names : ' ["ada.unchecked_conversion", "unchecked_conversion"]'
5+ input_sources : ['test.adb']
Original file line number Diff line number Diff line change @@ -391,6 +391,7 @@ testsuite_driver: No output file generated by gnatcheck
391391 <spin switch="+Rmin_identifier_length" label="identifier too short" min="0" max="99999" default="-1" separator=":"/>
392392 <check switch="+Rmisnamed_controlling_parameters" label="first parameter should have name 'This' and proper type"/>
393393 <field switch="+Rname_clashes" separator=":" label="use of forbidden identifier"/>
394+ <field switch="+Rno_dependence" separator=":" label="Forbidden dependency"/>
394395 <check switch="+Rnumeric_format" label="incorrect format for numeric literal"/>
395396 <check switch="+Robject_declarations_out_of_order" label="object declarations should precede program unit declarations"/>
396397 <check switch="+Rone_construct_per_line" label="more than one construct on the same line"/>
@@ -906,6 +907,7 @@ testsuite_driver: No output file generated by gnatcheck
906907 <spin switch="+Rmin_identifier_length" label="identifier too short" min="0" max="99999" default="-1" separator=":"/>
907908 <check switch="+Rmisnamed_controlling_parameters" label="first parameter should have name 'This' and proper type"/>
908909 <field switch="+Rname_clashes" separator=":" label="use of forbidden identifier"/>
910+ <field switch="+Rno_dependence" separator=":" label="Forbidden dependency"/>
909911 <check switch="+Rnumeric_format" label="incorrect format for numeric literal"/>
910912 <check switch="+Robject_declarations_out_of_order" label="object declarations should precede program unit declarations"/>
911913 <check switch="+Rone_construct_per_line" label="more than one construct on the same line"/>
You can’t perform that action at this time.
0 commit comments