Skip to content

Commit 7d454a1

Browse files
committed
Merge branch 'topic/rules/fix_one_construct_per_line' into 'master'
Fix the "One_Construct_Per_Line" rule Closes #556 See merge request eng/libadalang/langkit-query-language!545
2 parents bb674d7 + f3e2a07 commit 7d454a1

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

lkql_checker/share/lkql/one_construct_per_line.lkql

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,30 @@ fun one_construct_per_line(node) =
3232
|" I := J; J := Tmp; -- FLAG
3333
|" end Swap;
3434
# Flag any statement, declaration or representation clause
35-
node is (Stmt | BasicDecl | AttributeDefClause |
36-
EnumRepClause | RecordRepClause | AtClause)
37-
# except for enum literal, param spec, discriminant spec
38-
when (not node is (EnumLiteralDecl | ParamSpec | DiscriminantSpec |
39-
# or loop param or entry index.
40-
ForLoopVarDecl | EntryIndexSpec |
41-
# Also ignore anonymous or nested constructs
42-
# generating false positives.
43-
SingleTaskTypeDecl | AnonymousTypeDecl |
44-
LabelDecl | GenericSubpInternal |
45-
ConcreteFormalSubpDecl |
46-
ExtendedReturnStmtObjectDecl |
47-
NamedStmtDecl | AcceptStmtBody))
48-
and (node.token_end().end_line ==
49-
stdlib.next_non_blank_token_line(node.token_end())
50-
or node.token_start().start_line ==
51-
stdlib.previous_non_blank_token_line(node.token_start()))
35+
node is (
36+
Stmt
37+
| BasicDecl
38+
| AttributeDefClause
39+
| EnumRepClause
40+
| RecordRepClause
41+
| AtClause
42+
) when node is not (
43+
# Except for enum literal, param spec, discriminant spec
44+
EnumLiteralDecl | ParamSpec | DiscriminantSpec
45+
# Or loop param or entry index.
46+
| ForLoopVarDecl | EntryIndexSpec
47+
# Also ignore anonymous or nested constructs generating false positives.
48+
| SingleTaskTypeDecl
49+
| AnonymousTypeDecl
50+
| LabelDecl
51+
| GenericSubpInternal
52+
| ConcreteFormalSubpDecl
53+
| ExtendedReturnStmtObjectDecl
54+
| NamedStmtDecl
55+
| AcceptStmtBody
56+
# Ignore generic package instantiations when they are in a generic formal
57+
| GenericPackageInstantiation(parent: GenericFormal)
58+
) and (
59+
node.token_end().end_line == stdlib.next_non_blank_token_line(node.token_end())
60+
or node.token_start().start_line == stdlib.previous_non_blank_token_line(node.token_start())
61+
)

testsuite/tests/checks/one_construct_per_line/line.ads

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ package Line is I : Integer; -- FLAG
44
F2 : Float; C : -- FLAG (2)
55
Character;
66

7+
generic
8+
type Data_Type is private;
9+
package Pkg_A is
10+
end Pkg_A;
11+
12+
generic
13+
with package Data_Pkg is new Pkg_A (<>); -- NOFLAG
14+
with procedure Test (X : Integer) is <>; -- NOFLAG
15+
package Pkg_B is
16+
end Pkg_B;
17+
718
type T (A : Integer; B : Integer) is null record; -- NOFLAG
819

920
procedure Proc (I : in out Integer); end Line; -- FLAG

testsuite/tests/checks/one_construct_per_line/test.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ line.ads:4:16: rule violation: more than one construct on the same line
1010
4 | F2 : Float; C : -- FLAG (2)
1111
| ^
1212

13-
line.ads:9:14: rule violation: more than one construct on the same line
14-
9 | procedure Proc (I : in out Integer); end Line; -- FLAG
15-
| ^^^^
13+
line.ads:20:14: rule violation: more than one construct on the same line
14+
20 | procedure Proc (I : in out Integer); end Line; -- FLAG
15+
| ^^^^
1616

1717
line.adb:20:50: rule violation: more than one construct on the same line
1818
20 | accept Start (I : Integer; B : Boolean) do null; -- FLAG

0 commit comments

Comments
 (0)