From e6fc8796402ffaac72096e96cc5a714c1b33231e Mon Sep 17 00:00:00 2001 From: Mehrshad Date: Tue, 29 Aug 2023 13:18:02 +0330 Subject: [PATCH] FileConvention: fix the function A .fs/fsx file might not have a namespace sometimes. --- src/FileConventions/Library.fs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 86de06e1..8b43afa1 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -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