Skip to content

Commit

Permalink
FileConvention: fix the function
Browse files Browse the repository at this point in the history
A .fs/fsx file might not have a namespace sometimes.
  • Loading branch information
Mersho committed Aug 29, 2023
1 parent 19b442d commit e6fc879
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/FileConventions/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -428,19 +428,28 @@ let DoesNamespaceInclude (fileInfo: FileInfo) (word: string) =

if fileText.Any() then
let rightNamespace =
fileText |> Seq.find(fun x -> x.Contains "namespace")
fileText |> Seq.tryFind(fun x -> x.Contains "namespace")

let words =
rightNamespace.Split(' ', StringSplitOptions.RemoveEmptyEntries)
match rightNamespace with
| Some fileNamespace ->
let words =
fileNamespace.Split(' ', StringSplitOptions.RemoveEmptyEntries)

let namespaceCorrentPos = 1
let namespaceWordsCount = 2
let namespaceCorrentPos = 1
let namespaceWordsCount = 2

if words.Length < namespaceWordsCount then
false
else
let namespaceName = words[namespaceCorrentPos]
namespaceName.Equals(word) || namespaceName.Equals($"{word};")
if words.Length < namespaceWordsCount then
false
else
let namespaceName = words[namespaceCorrentPos]
namespaceName.Equals(word) || namespaceName.Equals($"{word};")
| None ->
// It is possible that there is a fsharp file without namespace
if fileInfo.FullName.EndsWith ".fs"
|| fileInfo.FullName.EndsWith ".fsx" then
true
else
false
else
false

Expand Down

0 comments on commit e6fc879

Please sign in to comment.