Skip to content

Commit 9ada5bb

Browse files
committed
Update --language support for new-query
Updates the `qlt query generate new-query` subcommand in order to support the equivalent set of `--language` options as the `qlt test init` subcommand. Adds unit tests to ensure that template vars (i.e. language) are defined (i.e. not empty) for subcommand templates.
1 parent 177984f commit 9ada5bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+700
-2
lines changed

CodeQLToolkit.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features", "s
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Shared.Tests", "test\CodeQLToolkit.Shared.Tests\CodeQLToolkit.Shared.Tests.csproj", "{E57121C2-2A2E-487C-9C32-A7D8914E9123}"
3131
EndProject
32+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeQLToolkit.Features.Tests", "test\CodeQLToolkit.Features.Tests\CodeQLToolkit.Features.Tests.csproj", "{F1234567-89AB-CDEF-0123-456789ABCDEF}"
33+
EndProject
3234
Global
3335
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3436
Debug|Any CPU = Debug|Any CPU
@@ -55,6 +57,10 @@ Global
5557
{E57121C2-2A2E-487C-9C32-A7D8914E9123}.Debug|Any CPU.Build.0 = Debug|Any CPU
5658
{E57121C2-2A2E-487C-9C32-A7D8914E9123}.Release|Any CPU.ActiveCfg = Release|Any CPU
5759
{E57121C2-2A2E-487C-9C32-A7D8914E9123}.Release|Any CPU.Build.0 = Release|Any CPU
60+
{F1234567-89AB-CDEF-0123-456789ABCDEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61+
{F1234567-89AB-CDEF-0123-456789ABCDEF}.Debug|Any CPU.Build.0 = Debug|Any CPU
62+
{F1234567-89AB-CDEF-0123-456789ABCDEF}.Release|Any CPU.ActiveCfg = Release|Any CPU
63+
{F1234567-89AB-CDEF-0123-456789ABCDEF}.Release|Any CPU.Build.0 = Release|Any CPU
5864
EndGlobalSection
5965
GlobalSection(SolutionProperties) = preSolution
6066
HideSolutionNode = FALSE
@@ -65,6 +71,7 @@ Global
6571
{A1F78CBC-9AE9-4360-A06B-395F368B183A} = {05645E0E-835A-4627-BDAE-C27EC39B23EE}
6672
{B85F1529-3321-4AD2-924A-6EA478145DC5} = {667B480C-D805-4A9C-AC1F-D9FCCF3DB57C}
6773
{E57121C2-2A2E-487C-9C32-A7D8914E9123} = {05645E0E-835A-4627-BDAE-C27EC39B23EE}
74+
{F1234567-89AB-CDEF-0123-456789ABCDEF} = {05645E0E-835A-4627-BDAE-C27EC39B23EE}
6875
EndGlobalSection
6976
GlobalSection(ExtensibilityGlobals) = postSolution
7077
SolutionGuid = {BF8F3B81-F4DC-4608-A41C-F00F3E5A05CA}

src/CodeQLToolkit.Features/CodeQLToolkit.Features.csproj

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,69 @@
5151
<None Update="Templates\Query\cpp\testref.liquid">
5252
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
5353
</None>
54+
<None Update="Templates\Query\csharp\expected.liquid">
55+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
56+
</None>
57+
<None Update="Templates\Query\csharp\new-dataflow-query.liquid">
58+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
59+
</None>
60+
<None Update="Templates\Query\csharp\new-query.liquid">
61+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
62+
</None>
63+
<None Update="Templates\Query\csharp\qlpack-query.liquid">
64+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
65+
</None>
66+
<None Update="Templates\Query\csharp\qlpack-test.liquid">
67+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
68+
</None>
69+
<None Update="Templates\Query\csharp\test.liquid">
70+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
71+
</None>
72+
<None Update="Templates\Query\csharp\testref.liquid">
73+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
74+
</None>
75+
<None Update="Templates\Query\go\expected.liquid">
76+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
77+
</None>
78+
<None Update="Templates\Query\go\new-dataflow-query.liquid">
79+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
80+
</None>
81+
<None Update="Templates\Query\go\new-query.liquid">
82+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
83+
</None>
84+
<None Update="Templates\Query\go\qlpack-query.liquid">
85+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
86+
</None>
87+
<None Update="Templates\Query\go\qlpack-test.liquid">
88+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
89+
</None>
90+
<None Update="Templates\Query\go\test.liquid">
91+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
92+
</None>
93+
<None Update="Templates\Query\go\testref.liquid">
94+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
95+
</None>
96+
<None Update="Templates\Query\java\expected.liquid">
97+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
98+
</None>
99+
<None Update="Templates\Query\java\new-dataflow-query.liquid">
100+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
101+
</None>
102+
<None Update="Templates\Query\java\new-query.liquid">
103+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
104+
</None>
105+
<None Update="Templates\Query\java\qlpack-query.liquid">
106+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
107+
</None>
108+
<None Update="Templates\Query\java\qlpack-test.liquid">
109+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
110+
</None>
111+
<None Update="Templates\Query\java\test.liquid">
112+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
113+
</None>
114+
<None Update="Templates\Query\java\testref.liquid">
115+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
116+
</None>
54117
<None Update="Templates\Query\javascript\expected.liquid">
55118
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
56119
</None>
@@ -72,6 +135,48 @@
72135
<None Update="Templates\Query\javascript\testref.liquid">
73136
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
74137
</None>
138+
<None Update="Templates\Query\python\expected.liquid">
139+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
140+
</None>
141+
<None Update="Templates\Query\python\new-dataflow-query.liquid">
142+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
143+
</None>
144+
<None Update="Templates\Query\python\new-query.liquid">
145+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
146+
</None>
147+
<None Update="Templates\Query\python\qlpack-query.liquid">
148+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
149+
</None>
150+
<None Update="Templates\Query\python\qlpack-test.liquid">
151+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
152+
</None>
153+
<None Update="Templates\Query\python\test.liquid">
154+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
155+
</None>
156+
<None Update="Templates\Query\python\testref.liquid">
157+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
158+
</None>
159+
<None Update="Templates\Query\ruby\expected.liquid">
160+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
161+
</None>
162+
<None Update="Templates\Query\ruby\new-dataflow-query.liquid">
163+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
164+
</None>
165+
<None Update="Templates\Query\ruby\new-query.liquid">
166+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
167+
</None>
168+
<None Update="Templates\Query\ruby\qlpack-query.liquid">
169+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
170+
</None>
171+
<None Update="Templates\Query\ruby\qlpack-test.liquid">
172+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
173+
</None>
174+
<None Update="Templates\Query\ruby\test.liquid">
175+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
176+
</None>
177+
<None Update="Templates\Query\ruby\testref.liquid">
178+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
179+
</None>
75180
<None Update="Templates\Test\Actions\install-codeql.liquid">
76181
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
77182
</None>

src/CodeQLToolkit.Features/Query/Scaffolding/QueryScaffoldFeature.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ public QueryScaffoldFeature()
1212
{
1313
FeatureName = "Query";
1414
}
15-
public override LanguageType[] SupportedLangauges => new LanguageType[] { LanguageType.C, LanguageType.CPP, LanguageType.JAVASCRIPT };
15+
public override LanguageType[] SupportedLangauges => new LanguageType[] {
16+
LanguageType.C,
17+
LanguageType.CPP,
18+
LanguageType.CSHARP,
19+
LanguageType.GO,
20+
LanguageType.JAVA,
21+
LanguageType.JAVASCRIPT,
22+
LanguageType.PYTHON,
23+
LanguageType.RUBY
24+
};
1625

1726
public void Register(Command parentCommand)
1827
{

src/CodeQLToolkit.Features/Query/Scaffolding/Targets/NewQueryScaffoldTarget.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public override void Run()
4040
WriteTemplateIfOverwriteOrNotExists("qlpack-query", query.QueryPackPath, "new query pack", new
4141
{
4242
queryPackScope = query.Scope,
43-
queryPackName = query.QueryPackName
43+
queryPackName = query.QueryPackName,
44+
ql_language = query.Language.ToDirectory()
4445
});
4546
}
4647

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// not implemented
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @id {{language}}/{{query_pack_name}}/{{query_name}}
3+
* @name {{query_name}}
4+
* @description {{description}}
5+
* @kind path-problem
6+
* @precision high
7+
* @problem.severity error
8+
* @tags {{query_pack_name}}
9+
*/
10+
11+
import {{ql_language_import}}
12+
import DataFlow::PathGraph
13+
14+
class Config extends TaintTracking::Configuration {
15+
Config() { this = "MyConfig" }
16+
17+
override predicate isSource(DataFlow::Node source) {
18+
// Define your sources here
19+
none()
20+
}
21+
22+
override predicate isSink(DataFlow::Node sink) {
23+
// Define your sinks here
24+
none()
25+
}
26+
}
27+
28+
from Config config, DataFlow::PathNode source, DataFlow::PathNode sink
29+
where config.hasFlowPath(source, sink)
30+
select sink.getNode(), source, sink, "Replace this with your dataflow query."
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @id {{language}}/{{query_pack_name}}/{{query_name}}
3+
* @name {{query_name}}
4+
* @description {{description}}
5+
* @kind problem
6+
* @precision medium
7+
* @problem.severity error
8+
* @tags {{query_pack_name}}
9+
*/
10+
11+
import {{ql_language_import}}
12+
13+
from Expr e
14+
select e, "Replace this with your query."
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: {{query_pack_scope}}/{{query_pack_name}}
2+
version: 0.0.0
3+
description: Default description
4+
suites:
5+
license:
6+
dependencies:
7+
codeql/csharp-all: "^0.6.3"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: {{query_pack_scope}}/{{query_pack_name}}
2+
version: 0.0.0
3+
description: Default description
4+
suites:
5+
license:
6+
extractor: csharp
7+
dependencies:
8+
{{query_pack_dependency}}: '*'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// not implemented

0 commit comments

Comments
 (0)