Skip to content

Commit

Permalink
FileConventions: fix the function
Browse files Browse the repository at this point in the history
Fix NotFollowingNamespaceConvention function.
  • Loading branch information
tehraninasab authored and Mersho committed Aug 17, 2023
1 parent 5f06394 commit 12f4d0b
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/FileConventions/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -410,32 +410,35 @@ let ProjFilesNamingConvention(fileInfo: FileInfo) =

fileName <> parentDirectoryName

let DoesNamespaceInclude (fileInfo: FileInfo) (word: string) =
let fileText = File.ReadLines fileInfo.FullName

if fileText.Any() then
let firstLine = fileText.First()

if firstLine.Contains "namespace" then
firstLine.Contains word
else
false
else
false

let NotFollowingNamespaceConvention(fileInfo: FileInfo) =
assert (fileInfo.FullName.EndsWith(".fs"))

let fileName = Path.GetFileNameWithoutExtension fileInfo.FullName
let parentDir = Path.GetDirectoryName fileInfo.FullName |> DirectoryInfo

let parentDirectoryName =
Path.GetDirectoryName fileInfo.FullName |> Path.GetFileName

printfn
"File name: %s, Parent directory name: %s"
fileName
parentDirectoryName
printfn "File name: %s, Parent directory name: %s" fileName parentDir.Name

if parentDirectoryName <> "src"
&& fileInfo.FullName.Contains
$"{Path.DirectorySeparatorChar}src{Path.DirectorySeparatorChar}" then
let fileText = File.ReadLines fileInfo.FullName
if parentDir.Parent.Name = "src" then
DoesNamespaceInclude fileInfo parentDir.Name |> not

if fileText.Any() then
let firstLine = fileText.First()
elif parentDir.Parent.Parent.Name = "src" then
DoesNamespaceInclude
fileInfo
$"{parentDir.Parent.Name}.{parentDir.Name}"
|> not

if firstLine.Contains "namespace" then
firstLine.Contains parentDirectoryName |> not
else
false
else
false
else
false

0 comments on commit 12f4d0b

Please sign in to comment.