Skip to content

Commit 277184a

Browse files
committed
Formatting
1 parent 5554818 commit 277184a

20 files changed

+1308
-430
lines changed

docs/content/Dual Analyzer.fsx

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,49 @@ let private topologicallySortedOpenStatementsAnalyzer
3737
let allOpenStatements = ResizeArray<string list * range>()
3838

3939
let (|LongIdentAsString|) (lid: SynLongIdent) =
40-
lid.LongIdent |> List.map (fun ident -> ident.idText)
40+
lid.LongIdent
41+
|> List.map (fun ident -> ident.idText)
4142

4243
let walker =
4344
{ new SyntaxCollectorBase() with
4445
override _.WalkSynModuleSigDecl(_, decl: SynModuleSigDecl) =
4546
match decl with
4647
| SynModuleSigDecl.Open(
47-
target = SynOpenDeclTarget.ModuleOrNamespace(longId = LongIdentAsString value; range = mOpen)) ->
48+
target = SynOpenDeclTarget.ModuleOrNamespace(
49+
longId = LongIdentAsString value; range = mOpen)) ->
4850
allOpenStatements.Add(value, mOpen)
4951
| _ -> ()
5052

5153
override _.WalkSynModuleDecl(_, decl: SynModuleDecl) =
5254
match decl with
5355
| SynModuleDecl.Open(
54-
target = SynOpenDeclTarget.ModuleOrNamespace(longId = LongIdentAsString value; range = mOpen)) ->
56+
target = SynOpenDeclTarget.ModuleOrNamespace(
57+
longId = LongIdentAsString value; range = mOpen)) ->
5558
allOpenStatements.Add(value, mOpen)
5659
| _ -> ()
5760
}
5861

5962
ASTCollecting.walkAst walker untypedTree
6063

61-
allOpenStatements |> Seq.toList
64+
allOpenStatements
65+
|> Seq.toList
6266

6367
let isSystemOpenStatement (openStatement: string list, mOpen: range) =
6468
let isFromBCL () =
65-
let line = sourceText.GetLineString(mOpen.EndLine - 1)
66-
67-
match checkResults.GetSymbolUseAtLocation(mOpen.EndLine, mOpen.EndColumn, line, openStatement) with
69+
let line =
70+
sourceText.GetLineString(
71+
mOpen.EndLine
72+
- 1
73+
)
74+
75+
match
76+
checkResults.GetSymbolUseAtLocation(
77+
mOpen.EndLine,
78+
mOpen.EndColumn,
79+
line,
80+
openStatement
81+
)
82+
with
6883
| Some symbolUse ->
6984
match symbolUse.Symbol.Assembly.FileName with
7085
| None -> false
@@ -73,19 +88,25 @@ let private topologicallySortedOpenStatementsAnalyzer
7388
assemblyPath.ToLower().Contains "microsoft.netcore.app.ref"
7489
| _ -> false
7590

76-
openStatement.[0].StartsWith("System") && isFromBCL ()
91+
openStatement.[0].StartsWith("System")
92+
&& isFromBCL ()
7793

78-
let nonSystemOpens = allOpenStatements |> List.skipWhile isSystemOpenStatement
94+
let nonSystemOpens =
95+
allOpenStatements
96+
|> List.skipWhile isSystemOpenStatement
7997

8098
return
8199
nonSystemOpens
82100
|> List.filter isSystemOpenStatement
83101
|> List.map (fun (openStatement, mOpen) ->
84-
let openStatementText = openStatement |> String.concat "."
102+
let openStatementText =
103+
openStatement
104+
|> String.concat "."
85105

86106
{
87107
Type = "Unsorted System open statement"
88-
Message = $"%s{openStatementText} was found after non System namespaces where opened!"
108+
Message =
109+
$"%s{openStatementText} was found after non System namespaces where opened!"
89110
Code = "SOT001"
90111
Severity = Severity.Warning
91112
Range = mOpen
@@ -96,15 +117,21 @@ let private topologicallySortedOpenStatementsAnalyzer
96117

97118
[<CliAnalyzer "Topologically sorted open statements">]
98119
let cliAnalyzer (ctx: CliContext) : Async<Message list> =
99-
topologicallySortedOpenStatementsAnalyzer ctx.SourceText ctx.ParseFileResults.ParseTree ctx.CheckFileResults
120+
topologicallySortedOpenStatementsAnalyzer
121+
ctx.SourceText
122+
ctx.ParseFileResults.ParseTree
123+
ctx.CheckFileResults
100124

101125
[<EditorAnalyzer "Topologically sorted open statements">]
102126
let editorAnalyzer (ctx: EditorContext) : Async<Message list> =
103127
match ctx.CheckFileResults with
104128
// The editor might not have any check results for a given file. So we don't return any messages.
105129
| None -> async.Return []
106130
| Some checkResults ->
107-
topologicallySortedOpenStatementsAnalyzer ctx.SourceText ctx.ParseFileResults.ParseTree checkResults
131+
topologicallySortedOpenStatementsAnalyzer
132+
ctx.SourceText
133+
ctx.ParseFileResults.ParseTree
134+
checkResults
108135

109136
(**
110137
Both analyzers will follow the same code path: the console application will always have the required data, while the editor needs to be more careful.

docs/content/Getting Started Writing.fsx

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,46 +146,90 @@ let releaseNotes = ReleaseNotes.load "RELEASE_NOTES.md"
146146
Target.create
147147
"PackAnalyzer"
148148
(fun _ ->
149-
let analyzerProject = "src" </> "BadCodeAnalyzer"
149+
let analyzerProject =
150+
"src"
151+
</> "BadCodeAnalyzer"
150152

151153
let args =
152154
[
153155
"pack"
154156
"--configuration Release"
155157
sprintf "/p:PackageVersion=%s" releaseNotes.NugetVersion
156158
sprintf "/p:PackageReleaseNotes=\"%s\"" (String.concat "\n" releaseNotes.Notes)
157-
sprintf "--output %s" (__SOURCE_DIRECTORY__ </> "dist")
159+
sprintf
160+
"--output %s"
161+
(__SOURCE_DIRECTORY__
162+
</> "dist")
158163
]
159164

160165
// create initial nuget package
161166
let exitCode = Shell.Exec("dotnet", String.concat " " args, analyzerProject)
162167

163-
if exitCode <> 0 then
168+
if
169+
exitCode
170+
<> 0
171+
then
164172
failwith "dotnet pack failed"
165173
else
166-
match Shell.Exec("dotnet", "publish --configuration Release --framework net8.0", analyzerProject) with
174+
match
175+
Shell.Exec(
176+
"dotnet",
177+
"publish --configuration Release --framework net8.0",
178+
analyzerProject
179+
)
180+
with
167181
| 0 ->
168182
let nupkg =
169-
System.IO.Directory.GetFiles(__SOURCE_DIRECTORY__ </> "dist")
183+
System.IO.Directory.GetFiles(
184+
__SOURCE_DIRECTORY__
185+
</> "dist"
186+
)
170187
|> Seq.head
171188
|> Path.GetFullPath
172189

173190
let nugetParent = DirectoryInfo(nupkg).Parent.FullName
174191
let nugetFileName = Path.GetFileNameWithoutExtension(nupkg)
175192

176-
let publishPath = analyzerProject </> "bin" </> "Release" </> "net8.0" </> "publish"
193+
let publishPath =
194+
analyzerProject
195+
</> "bin"
196+
</> "Release"
197+
</> "net8.0"
198+
</> "publish"
177199
// Unzip the nuget
178-
ZipFile.ExtractToDirectory(nupkg, nugetParent </> nugetFileName)
200+
ZipFile.ExtractToDirectory(
201+
nupkg,
202+
nugetParent
203+
</> nugetFileName
204+
)
179205
// delete the initial nuget package
180206
File.Delete nupkg
181207
// remove stuff from ./lib/net8.0
182-
Shell.deleteDir (nugetParent </> nugetFileName </> "lib" </> "net8.0")
208+
Shell.deleteDir (
209+
nugetParent
210+
</> nugetFileName
211+
</> "lib"
212+
</> "net8.0"
213+
)
183214
// move the output of publish folder into the ./lib/net8.0 directory
184-
Shell.copyDir (nugetParent </> nugetFileName </> "lib" </> "net8.0") publishPath (fun _ -> true)
215+
Shell.copyDir
216+
(nugetParent
217+
</> nugetFileName
218+
</> "lib"
219+
</> "net8.0")
220+
publishPath
221+
(fun _ -> true)
185222
// re-create the nuget package
186-
ZipFile.CreateFromDirectory(nugetParent </> nugetFileName, nupkg)
223+
ZipFile.CreateFromDirectory(
224+
nugetParent
225+
</> nugetFileName,
226+
nupkg
227+
)
187228
// delete intermediate directory
188-
Shell.deleteDir (nugetParent </> nugetFileName)
229+
Shell.deleteDir (
230+
nugetParent
231+
</> nugetFileName
232+
)
189233
| _ -> failwith "dotnet publish failed"
190234
)
191235

docs/content/Unit Testing.fsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ let Setup () =
3838
mkOptionsFromProject
3939
"net7.0"
4040
[
41-
// The SDK uses this in a "dotnet add package x --version y" command
42-
// to generate the needed FSharpProjectOptions
43-
{ Name = "Newtonsoft.Json"
44-
Version = "13.0.3" } ]
41+
// The SDK uses this in a "dotnet add package x --version y" command
42+
// to generate the needed FSharpProjectOptions
43+
{
44+
Name = "Newtonsoft.Json"
45+
Version = "13.0.3"
46+
}
47+
]
4548

4649
projectOptions <- opts
4750
}

samples/BadOptionUsage.fsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
let value = Some 42
42

5-
printfn "The value is: %d" value.Value // This will cause a warning from the OptionAnalyzer
3+
printfn "The value is: %d" value.Value // This will cause a warning from the OptionAnalyzer

samples/MsBuildExample/Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
let value = Some 42
44

5-
printfn "The value is: %d" value.Value // This will cause a warning from the OptionAnalyzer
5+
printfn "The value is: %d" value.Value // This will cause a warning from the OptionAnalyzer

0 commit comments

Comments
 (0)