Skip to content

Commit

Permalink
FileConventions: fix the function
Browse files Browse the repository at this point in the history
Ensure that projects that aren't console applications don't
have source files with console methods.

Co-authored-by: Parham <[email protected]>
  • Loading branch information
Mersho and parhamsaremi committed Aug 21, 2023
1 parent b6e39f2 commit dffea45
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/FileConventions/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,44 @@ let NotFollowingNamespaceConvention(fileInfo: FileInfo) =
false


let ContainsConsoleMethods(fileInfo: FileInfo) =
let fileText = File.ReadAllText fileInfo.FullName
let consoleMethods = [ "printf"; "Console." ]
consoleMethods |> List.exists fileText.Contains


let NotFollowingConsoleAppConvention(fileInfo: FileInfo) =
printf "%A" fileInfo
false
let fileText = File.ReadAllText fileInfo.FullName
let parentDir = Path.GetDirectoryName fileInfo.FullName |> Seq.singleton

if not(fileText.Contains "<OutputType>Exe</OutputType>") then
let rec allFiles dirs =
if Seq.isEmpty dirs then
Seq.empty
else
let csFiles =
dirs
|> Seq.collect(fun dir ->
Directory.EnumerateFiles(dir, "*.cs")
)

let fsFiles =
dirs
|> Seq.collect(fun dir ->
Directory.EnumerateFiles(dir, "*.fs")
)

let projectDirectories =
dirs
|> Seq.collect Directory.EnumerateDirectories
|> allFiles

Seq.append csFiles <| Seq.append fsFiles projectDirectories

let sourceFiles = allFiles parentDir

sourceFiles
|> Seq.exists(fun value -> ContainsConsoleMethods(FileInfo value))

else
false

0 comments on commit dffea45

Please sign in to comment.