Skip to content

Commit d105d7d

Browse files
committed
Npgsql.FSharp.Analyzer v3.18 detect queries within lambda expressions
1 parent 8d5412f commit d105d7d

File tree

17 files changed

+312
-49
lines changed

17 files changed

+312
-49
lines changed

NpgsqlFSharpAnalyzer.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FParsec", "src\FParsec\FPar
4141
EndProject
4242
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ParserTestsWithNet48", "src\ParserTestsWithNet48\ParserTestsWithNet48.csproj", "{40067E09-6281-4DC2-905D-60F7C6E3B812}"
4343
EndProject
44+
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Ubik", "src\Ubik\Ubik.fsproj", "{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}"
45+
EndProject
4446
Global
4547
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4648
Debug|Any CPU = Debug|Any CPU
@@ -159,6 +161,18 @@ Global
159161
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|x64.Build.0 = Release|Any CPU
160162
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|x86.ActiveCfg = Release|Any CPU
161163
{40067E09-6281-4DC2-905D-60F7C6E3B812}.Release|x86.Build.0 = Release|Any CPU
164+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
165+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Debug|Any CPU.Build.0 = Debug|Any CPU
166+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Debug|x64.ActiveCfg = Debug|Any CPU
167+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Debug|x64.Build.0 = Debug|Any CPU
168+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Debug|x86.ActiveCfg = Debug|Any CPU
169+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Debug|x86.Build.0 = Debug|Any CPU
170+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
171+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Release|Any CPU.Build.0 = Release|Any CPU
172+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Release|x64.ActiveCfg = Release|Any CPU
173+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Release|x64.Build.0 = Release|Any CPU
174+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Release|x86.ActiveCfg = Release|Any CPU
175+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E}.Release|x86.Build.0 = Release|Any CPU
162176
EndGlobalSection
163177
GlobalSection(SolutionProperties) = preSolution
164178
HideSolutionNode = FALSE
@@ -174,6 +188,7 @@ Global
174188
{C5EB813F-4278-4EE7-925B-6757BAD0FE9B} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
175189
{9C8E7641-9DC8-470C-8009-71A747C01DC5} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
176190
{40067E09-6281-4DC2-905D-60F7C6E3B812} = {ACBEE43C-7A88-4FB1-9B06-DB064D22B29F}
191+
{0CCC7E3F-78F0-4A4F-8AC1-27A1F6386B1E} = {C397A34C-84F1-49E7-AEBC-2F9F2B196216}
177192
EndGlobalSection
178193
GlobalSection(ExtensibilityGlobals) = postSolution
179194
SolutionGuid = {BC821061-2FB3-4ABD-9FA1-044D4C59C475}

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 3.18.0 - 2020-09-15
2+
* Analyze SQL blocks from within lambda expressions
3+
14
### 3.17.0 - 2020-09-15
25
* Support for datetimeOffset and datetimeOffsetOrNone when reading columns of type timestamptz
36

src/FParsec/AssemblyInfo.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ open System.Reflection
44

55
[<assembly: AssemblyTitleAttribute("FParsec")>]
66
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
7-
[<assembly: AssemblyVersionAttribute("3.17.0")>]
7+
[<assembly: AssemblyVersionAttribute("3.18.0")>]
88
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-09-15T00:00:00.0000000")>]
9-
[<assembly: AssemblyFileVersionAttribute("3.17.0")>]
10-
[<assembly: AssemblyInformationalVersionAttribute("3.17.0")>]
9+
[<assembly: AssemblyFileVersionAttribute("3.18.0")>]
10+
[<assembly: AssemblyInformationalVersionAttribute("3.18.0")>]
1111
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
12-
[<assembly: AssemblyMetadataAttribute("GitHash","985f38c696391f5c8f38f4498e3a59db66ffe3c6")>]
12+
[<assembly: AssemblyMetadataAttribute("GitHash","8d5412fe3dd28abc45fb45a7d97134d09ec1ce82")>]
1313
do ()
1414

1515
module internal AssemblyVersionInformation =
1616
let [<Literal>] AssemblyTitle = "FParsec"
1717
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
18-
let [<Literal>] AssemblyVersion = "3.17.0"
18+
let [<Literal>] AssemblyVersion = "3.18.0"
1919
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-09-15T00:00:00.0000000"
20-
let [<Literal>] AssemblyFileVersion = "3.17.0"
21-
let [<Literal>] AssemblyInformationalVersion = "3.17.0"
20+
let [<Literal>] AssemblyFileVersion = "3.18.0"
21+
let [<Literal>] AssemblyInformationalVersion = "3.18.0"
2222
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
23-
let [<Literal>] AssemblyMetadata_GitHash = "985f38c696391f5c8f38f4498e3a59db66ffe3c6"
23+
let [<Literal>] AssemblyMetadata_GitHash = "8d5412fe3dd28abc45fb45a7d97134d09ec1ce82"

src/NpgsqlFSharpAnalyzer.Core/AssemblyInfo.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ open System.Reflection
44

55
[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer.Core")>]
66
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
7-
[<assembly: AssemblyVersionAttribute("3.17.0")>]
7+
[<assembly: AssemblyVersionAttribute("3.18.0")>]
88
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-09-15T00:00:00.0000000")>]
9-
[<assembly: AssemblyFileVersionAttribute("3.17.0")>]
10-
[<assembly: AssemblyInformationalVersionAttribute("3.17.0")>]
9+
[<assembly: AssemblyFileVersionAttribute("3.18.0")>]
10+
[<assembly: AssemblyInformationalVersionAttribute("3.18.0")>]
1111
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
12-
[<assembly: AssemblyMetadataAttribute("GitHash","985f38c696391f5c8f38f4498e3a59db66ffe3c6")>]
12+
[<assembly: AssemblyMetadataAttribute("GitHash","8d5412fe3dd28abc45fb45a7d97134d09ec1ce82")>]
1313
do ()
1414

1515
module internal AssemblyVersionInformation =
1616
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer.Core"
1717
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
18-
let [<Literal>] AssemblyVersion = "3.17.0"
18+
let [<Literal>] AssemblyVersion = "3.18.0"
1919
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-09-15T00:00:00.0000000"
20-
let [<Literal>] AssemblyFileVersion = "3.17.0"
21-
let [<Literal>] AssemblyInformationalVersion = "3.17.0"
20+
let [<Literal>] AssemblyFileVersion = "3.18.0"
21+
let [<Literal>] AssemblyInformationalVersion = "3.18.0"
2222
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
23-
let [<Literal>] AssemblyMetadata_GitHash = "985f38c696391f5c8f38f4498e3a59db66ffe3c6"
23+
let [<Literal>] AssemblyMetadata_GitHash = "8d5412fe3dd28abc45fb45a7d97134d09ec1ce82"

src/NpgsqlFSharpAnalyzer.Core/SyntacticAnalysis.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@ module SyntacticAnalysis =
641641
| Some expr -> yield! visitSyntacticExpression expr range
642642
]
643643

644+
| SynExpr.Lambda (fromMethod, inSeq, args, body, range) ->
645+
visitSyntacticExpression body range
646+
644647
| otherwise ->
645648
[ ]
646649

src/NpgsqlFSharpAnalyzer/AssemblyInfo.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ open System.Reflection
44

55
[<assembly: AssemblyTitleAttribute("NpgsqlFSharpAnalyzer")>]
66
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
7-
[<assembly: AssemblyVersionAttribute("3.17.0")>]
7+
[<assembly: AssemblyVersionAttribute("3.18.0")>]
88
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-09-15T00:00:00.0000000")>]
9-
[<assembly: AssemblyFileVersionAttribute("3.17.0")>]
10-
[<assembly: AssemblyInformationalVersionAttribute("3.17.0")>]
9+
[<assembly: AssemblyFileVersionAttribute("3.18.0")>]
10+
[<assembly: AssemblyInformationalVersionAttribute("3.18.0")>]
1111
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
12-
[<assembly: AssemblyMetadataAttribute("GitHash","985f38c696391f5c8f38f4498e3a59db66ffe3c6")>]
12+
[<assembly: AssemblyMetadataAttribute("GitHash","8d5412fe3dd28abc45fb45a7d97134d09ec1ce82")>]
1313
do ()
1414

1515
module internal AssemblyVersionInformation =
1616
let [<Literal>] AssemblyTitle = "NpgsqlFSharpAnalyzer"
1717
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
18-
let [<Literal>] AssemblyVersion = "3.17.0"
18+
let [<Literal>] AssemblyVersion = "3.18.0"
1919
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-09-15T00:00:00.0000000"
20-
let [<Literal>] AssemblyFileVersion = "3.17.0"
21-
let [<Literal>] AssemblyInformationalVersion = "3.17.0"
20+
let [<Literal>] AssemblyFileVersion = "3.18.0"
21+
let [<Literal>] AssemblyInformationalVersion = "3.18.0"
2222
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
23-
let [<Literal>] AssemblyMetadata_GitHash = "985f38c696391f5c8f38f4498e3a59db66ffe3c6"
23+
let [<Literal>] AssemblyMetadata_GitHash = "8d5412fe3dd28abc45fb45a7d97134d09ec1ce82"

src/NpgsqlFSharpParser/AssemblyInfo.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ open System.Reflection
44

55
[<assembly: AssemblyTitleAttribute("NpgsqlFSharpParser")>]
66
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
7-
[<assembly: AssemblyVersionAttribute("3.17.0")>]
7+
[<assembly: AssemblyVersionAttribute("3.18.0")>]
88
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-09-15T00:00:00.0000000")>]
9-
[<assembly: AssemblyFileVersionAttribute("3.17.0")>]
10-
[<assembly: AssemblyInformationalVersionAttribute("3.17.0")>]
9+
[<assembly: AssemblyFileVersionAttribute("3.18.0")>]
10+
[<assembly: AssemblyInformationalVersionAttribute("3.18.0")>]
1111
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
12-
[<assembly: AssemblyMetadataAttribute("GitHash","985f38c696391f5c8f38f4498e3a59db66ffe3c6")>]
12+
[<assembly: AssemblyMetadataAttribute("GitHash","8d5412fe3dd28abc45fb45a7d97134d09ec1ce82")>]
1313
do ()
1414

1515
module internal AssemblyVersionInformation =
1616
let [<Literal>] AssemblyTitle = "NpgsqlFSharpParser"
1717
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
18-
let [<Literal>] AssemblyVersion = "3.17.0"
18+
let [<Literal>] AssemblyVersion = "3.18.0"
1919
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-09-15T00:00:00.0000000"
20-
let [<Literal>] AssemblyFileVersion = "3.17.0"
21-
let [<Literal>] AssemblyInformationalVersion = "3.17.0"
20+
let [<Literal>] AssemblyFileVersion = "3.18.0"
21+
let [<Literal>] AssemblyInformationalVersion = "3.18.0"
2222
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
23-
let [<Literal>] AssemblyMetadata_GitHash = "985f38c696391f5c8f38f4498e3a59db66ffe3c6"
23+
let [<Literal>] AssemblyMetadata_GitHash = "8d5412fe3dd28abc45fb45a7d97134d09ec1ce82"

src/NpgsqlFSharpVs/source.extension.vsixmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011"
44
xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
55
<Metadata>
6-
<Identity Id="FSharpLintVs.ef00bfc3-a899-45fc-aae8-afecf8673aaf" Version="3.17.0" Language="en-US" Publisher="Zaid Ajaj" />
6+
<Identity Id="FSharpLintVs.ef00bfc3-a899-45fc-aae8-afecf8673aaf" Version="3.18.0" Language="en-US" Publisher="Zaid Ajaj" />
77
<DisplayName>NpgsqlFSharpVs</DisplayName>
88
<Description xml:space="preserve">F# Analyzer for embedded SQL syntax analysis, type-checking for parameters and result sets and nullable column detection when writing queries using Npgsql.FSharp.</Description>
99
<MoreInfo>https://github.com/Zaid-Ajaj/Npgsql.FSharp.Analyzer</MoreInfo>

src/Ubik/AssemblyInfo.fs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Auto-Generated by FAKE; do not edit
2+
namespace System
3+
open System.Reflection
4+
5+
[<assembly: AssemblyTitleAttribute("Ubik")>]
6+
[<assembly: AssemblyProductAttribute("NpgsqlFSharpAnalyzer")>]
7+
[<assembly: AssemblyVersionAttribute("3.18.0")>]
8+
[<assembly: AssemblyMetadataAttribute("ReleaseDate","2020-09-15T00:00:00.0000000")>]
9+
[<assembly: AssemblyFileVersionAttribute("3.18.0")>]
10+
[<assembly: AssemblyInformationalVersionAttribute("3.18.0")>]
11+
[<assembly: AssemblyMetadataAttribute("ReleaseChannel","release")>]
12+
[<assembly: AssemblyMetadataAttribute("GitHash","8d5412fe3dd28abc45fb45a7d97134d09ec1ce82")>]
13+
do ()
14+
15+
module internal AssemblyVersionInformation =
16+
let [<Literal>] AssemblyTitle = "Ubik"
17+
let [<Literal>] AssemblyProduct = "NpgsqlFSharpAnalyzer"
18+
let [<Literal>] AssemblyVersion = "3.18.0"
19+
let [<Literal>] AssemblyMetadata_ReleaseDate = "2020-09-15T00:00:00.0000000"
20+
let [<Literal>] AssemblyFileVersion = "3.18.0"
21+
let [<Literal>] AssemblyInformationalVersion = "3.18.0"
22+
let [<Literal>] AssemblyMetadata_ReleaseChannel = "release"
23+
let [<Literal>] AssemblyMetadata_GitHash = "8d5412fe3dd28abc45fb45a7d97134d09ec1ce82"

src/Ubik/Program.fs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
open System
2+
open System.IO
3+
open Npgsql.FSharp.Analyzers.Core
4+
open Spectre.Console
5+
open System.Xml
6+
7+
let resolveFile (path: string) =
8+
if Path.IsPathRooted path
9+
then path
10+
else Path.GetFullPath (Path.Combine(Environment.CurrentDirectory, path))
11+
12+
let getProject (args: string []) =
13+
try
14+
match args with
15+
| [| |] ->
16+
Directory.GetFiles(Environment.CurrentDirectory, "*.fsproj")
17+
|> Array.tryHead
18+
|> Option.map (fun projectPath -> resolveFile projectPath)
19+
20+
| multipleArgs ->
21+
let firstArg = multipleArgs.[0]
22+
if firstArg.EndsWith(".fsproj") then
23+
Some (resolveFile firstArg)
24+
else
25+
Directory.GetFiles(resolveFile firstArg, "*.fsproj")
26+
|> Array.tryHead
27+
|> Option.map (fun projectPath -> resolveFile projectPath)
28+
with
29+
| error -> None
30+
31+
[<EntryPoint>]
32+
let main argv =
33+
match getProject argv with
34+
| None ->
35+
printfn "No project file found in the current directory"
36+
1
37+
38+
| Some project ->
39+
AnsiConsole.MarkupLine("Analyzing [blue]{0}[/]", project)
40+
41+
let document = XmlDocument()
42+
document.LoadXml(File.ReadAllText project)
43+
44+
let fsharpFileNodes = document.GetElementsByTagName("Compile")
45+
let fsharpFiles = [
46+
for item in 0 .. fsharpFileNodes.Count - 1 ->
47+
let relativePath = fsharpFileNodes.[item].Attributes.["Include"].InnerText
48+
let projectParent = Directory.GetParent project
49+
Path.Combine(projectParent.FullName, relativePath)
50+
]
51+
52+
for file in fsharpFiles do
53+
AnsiConsole.MarkupLine("Analyzing file [green]{0}[/]", file)
54+
match Project.context file with
55+
| None -> ()
56+
| Some context ->
57+
let syntacticBlocks = SyntacticAnalysis.findSqlOperations context
58+
if not syntacticBlocks.IsEmpty then
59+
let messages =
60+
let connectionString = SqlAnalyzer.tryFindConnectionString context.FileName
61+
if isNull connectionString || String.IsNullOrWhiteSpace connectionString then
62+
[ ]
63+
else
64+
match SqlAnalysis.databaseSchema connectionString with
65+
| Result.Error connectionError ->
66+
[
67+
for block in syntacticBlocks ->
68+
SqlAnalysis.createWarning (sprintf "Error while connecting to the development database using the connection string from environment variable 'NPGSQL_FSHARP' or put the connection string in a file called 'NPGSQL_FSHARP' relative next your project or in your project root. Connection error: %s" connectionError) block.range
69+
]
70+
71+
| Result.Ok schema ->
72+
syntacticBlocks
73+
|> List.collect (fun block -> SqlAnalysis.analyzeOperation block connectionString schema)
74+
|> List.distinctBy (fun message -> message.Range)
75+
76+
for message in messages do
77+
AnsiConsole.MarkupLine("Error [red]{0}[/]", message.Message)
78+
79+
0

0 commit comments

Comments
 (0)