Skip to content

Commit 13f1dec

Browse files
committed
scripts: add dotNetFileConventions.fsx
The newly developed script can detect wrong empty strings, wrong project directories, incorrect namespace usage, and incorrect methods in non-console applications.
1 parent 1fd7576 commit 13f1dec

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

scripts/dotnetFileConvention.fsx

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env -S dotnet fsi
2+
3+
open System
4+
open System.IO
5+
open System.Text.RegularExpressions
6+
7+
#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
8+
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"
9+
10+
open Fsdk
11+
open Fsdk.Process
12+
13+
#load "../src/FileConventions/Helpers.fs"
14+
#load "../src/FileConventions/Library.fs"
15+
16+
open FileConventions
17+
open Helpers
18+
19+
let args = Misc.FsxOnlyArguments()
20+
21+
if args.Length > 1 then
22+
Console.Error.WriteLine
23+
"Usage: dotnetFileConvention.fsx [projectFolder(optional)]"
24+
25+
Environment.Exit 1
26+
27+
let rootDir = DirectoryInfo args.[0]
28+
29+
// DefiningEmptyStringsWithDoubleQuotes
30+
let allSourceFiles = ReturnAllProjectSourceFile rootDir [ "*.cs"; "*.fs" ] true
31+
printfn "%A" (String.Join("\n", allSourceFiles))
32+
33+
let allProjFiles =
34+
ReturnAllProjectSourceFile rootDir [ "*.csproj"; "*.fsproj" ] true
35+
36+
for sourceFile in allSourceFiles do
37+
let isStringEmpty = DefiningEmptyStringsWithDoubleQuotes sourceFile
38+
39+
if isStringEmpty then
40+
failwith(
41+
sprintf
42+
"%s file: Contains empty strings specifed with \"\" , you should use String.Empty()"
43+
sourceFile.FullName
44+
)
45+
46+
47+
// ProjFilesNamingConvention
48+
49+
for projfile in allProjFiles do
50+
let isWrongProjFile = ProjFilesNamingConvention projfile
51+
52+
if isWrongProjFile then
53+
failwith(
54+
sprintf
55+
"%s file: Project file or Project directory is incorrect!\n
56+
Fix: use same name on .csproj/.fsproj on parrent project directory"
57+
projfile.FullName
58+
)
59+
60+
// notfollowingnamespaceconvention
61+
for sourcefile in allSourceFiles do
62+
let iswrongnamespace = NotFollowingNamespaceConvention sourcefile
63+
64+
if iswrongnamespace then
65+
failwith(sprintf "%s file: has wrong namespace!" sourcefile.FullName)
66+
67+
// NotFollowingConsoleAppConvention
68+
for projfile in allProjFiles do
69+
let isWrongConsoleApplication =
70+
NotFollowingConsoleAppConvention projfile true
71+
72+
printfn "%A" projfile
73+
74+
if isWrongConsoleApplication then
75+
failwith(
76+
sprintf
77+
"%s project: Should not contain console methods or printf"
78+
projfile.FullName
79+
)

0 commit comments

Comments
 (0)