Skip to content

Commit

Permalink
FileConventions: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tehraninasab committed Jul 6, 2023
1 parent 61d4b00 commit be256d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let invalidFiles =
Helpers.GetInvalidFiles
rootDir
("*" + ext)
FileConventions.NonVerboseFlagsInGitHubCI
FileConventions.NonVerboseFlags
)
|> Seq.concat

Expand Down
12 changes: 6 additions & 6 deletions src/FileConventions.Test/FileConventions.Test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ let NonVerboseFlagsInGitHubCI1() =
)
))

Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo true)
Assert.That(NonVerboseFlags fileInfo, Is.EqualTo true)


[<Test>]
Expand All @@ -572,7 +572,7 @@ let NonVerboseFlagsInGitHubCI2() =
)
))

Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo false)
Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false)


[<Test>]
Expand All @@ -585,7 +585,7 @@ let NonVerboseFlagsInGitHubCI3() =
)
))

Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo false)
Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false)


[<Test>]
Expand All @@ -598,7 +598,7 @@ let NonVerboseFlagsInGitHubCI4() =
)
))

Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo true)
Assert.That(NonVerboseFlags fileInfo, Is.EqualTo true)


[<Test>]
Expand All @@ -611,7 +611,7 @@ let NonVerboseFlagsInGitHubCI5() =
)
))

Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo false)
Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false)


[<Test>]
Expand All @@ -624,4 +624,4 @@ let NonVerboseFlagsInGitHubCI6() =
)
))

Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo false)
Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false)
16 changes: 11 additions & 5 deletions src/FileConventions/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ let allowedNonVerboseFlags =
"env -S"
}

let NonVerboseFlagsInGitHubCI(fileInfo: FileInfo) =
let NonVerboseFlags(fileInfo: FileInfo) =
let validExtensions =
seq {
".yml"
Expand All @@ -348,12 +348,18 @@ let NonVerboseFlagsInGitHubCI(fileInfo: FileInfo) =
".sh"
}

assert
let isFileExtentionValid =
validExtensions
|> Seq.map(fun ext -> fileInfo.FullName.EndsWith(ext))
|> Seq.map(fun ext -> fileInfo.FullName.EndsWith ext)
|> Seq.contains true

let fileLines = File.ReadLines(fileInfo.FullName)
if not isFileExtentionValid then
let sep = ","

failwith
$"NonVerboseFlags function only supports {String.concat sep validExtensions} files."

let fileLines = File.ReadLines fileInfo.FullName

let nonVerboseFlagsRegex = Regex("\\s-[a-zA-Z]\\b", RegexOptions.Compiled)

Expand All @@ -367,7 +373,7 @@ let NonVerboseFlagsInGitHubCI(fileInfo: FileInfo) =
|> Seq.map(fun allowedFlag -> line.Contains allowedFlag)
|> Seq.contains true

nonVerboseFlag && not(allowedNonVerboseFlag)
nonVerboseFlag && not allowedNonVerboseFlag
)
|> Seq.length

Expand Down

0 comments on commit be256d4

Please sign in to comment.