-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env -S dotnet fsi | ||
|
||
open System | ||
open System.IO | ||
open System.Text.RegularExpressions | ||
|
||
#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" | ||
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853" | ||
|
||
open Fsdk | ||
open Fsdk.Process | ||
|
||
#load "../src/FileConventions/Helpers.fs" | ||
#load "../src/FileConventions/Library.fs" | ||
|
||
open FileConventions | ||
open Helpers | ||
|
||
let args = Misc.FsxOnlyArguments() | ||
|
||
if args.Length > 1 then | ||
Console.Error.WriteLine | ||
"Usage: dotnetFileConventions.fsx [projectFolder(optional)]" | ||
|
||
Environment.Exit 1 | ||
|
||
let rootDir = DirectoryInfo args.[0] | ||
|
||
// DefiningEmptyStringsWithDoubleQuotes | ||
let allSourceFiles = ReturnAllProjectSourceFile rootDir [ "*.cs"; "*.fs" ] true | ||
printfn "%A" (String.Join("\n", allSourceFiles)) | ||
|
||
let allProjFiles = | ||
ReturnAllProjectSourceFile rootDir [ "*.csproj"; "*.fsproj" ] true | ||
|
||
for sourceFile in allSourceFiles do | ||
let isStringEmpty = DefiningEmptyStringsWithDoubleQuotes sourceFile | ||
|
||
if isStringEmpty then | ||
failwith( | ||
sprintf | ||
"%s file: Contains empty strings specifed with \"\" , you should use String.Empty()" | ||
sourceFile.FullName | ||
) | ||
|
||
|
||
// ProjFilesNamingConvention | ||
|
||
for projfile in allProjFiles do | ||
let isWrongProjFile = ProjFilesNamingConvention projfile | ||
|
||
if isWrongProjFile then | ||
failwith( | ||
sprintf | ||
"%s file: Project file or Project directory is incorrect!\n | ||
Fix: use same name on .csproj/.fsproj on parrent project directory" | ||
projfile.FullName | ||
) | ||
|
||
// notfollowingnamespaceconvention | ||
for sourcefile in allSourceFiles do | ||
let iswrongnamespace = NotFollowingNamespaceConvention sourcefile | ||
|
||
if iswrongnamespace then | ||
failwith(sprintf "%s file: has wrong namespace!" sourcefile.FullName) | ||
|
||
// NotFollowingConsoleAppConvention | ||
for projfile in allProjFiles do | ||
let isWrongConsoleApplication = | ||
NotFollowingConsoleAppConvention projfile true | ||
|
||
printfn "%A" projfile | ||
|
||
if isWrongConsoleApplication then | ||
failwith( | ||
sprintf | ||
"%s project: Should not contain console methods or printf" | ||
projfile.FullName | ||
) |