Skip to content

Commit

Permalink
wip: transfer style functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tehraninasab committed Aug 2, 2023
1 parent ea35639 commit e4b86fa
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 78 deletions.
80 changes: 3 additions & 77 deletions scripts/styleChecker.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

open System
open System.IO
Expand All @@ -15,81 +16,6 @@ let fantomlessToolVersion = "4.7.997-prerelease"
let prettierVersion = "2.8.3"
let pluginXmlVersion = "v2.2.0"

let StyleFSharpFiles(rootDir: DirectoryInfo) =
InstallFantomlessTool fantomlessToolVersion

Process
.Execute(
{
Command = "dotnet"
Arguments = $"fantomless --recurse {rootDir.FullName}"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let StyleCSharpFiles(rootDir: DirectoryInfo) =
Process
.Execute(
{
Command = "dotnet"
Arguments = $"format whitespace {rootDir.FullName} --folder"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let StyleXamlFiles() =
InstallPrettier prettierVersion
InstallPrettierPluginXml pluginXmlVersion

Process
.Execute(
{
Command = "npm"
Arguments =
$"install --save-dev prettier@{prettierVersion} @prettier/plugin-xml@{pluginXmlVersion}"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let pattern = $"**{Path.DirectorySeparatorChar}*.xaml"

Process
.Execute(
{
Command =
Path.Combine(
Directory.GetCurrentDirectory(),
"node_modules",
".bin",
"prettier"
)

Arguments =
$"--xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write {pattern}"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let StyleTypeScriptFiles() =
let pattern =
$"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts"

RunPrettier $"--quote-props=consistent --write {pattern}"

let StyleYmlFiles() =
let pattern =
$"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml"

RunPrettier $"--quote-props=consistent --write {pattern}"

let ContainsFiles (rootDir: DirectoryInfo) (searchPattern: string) =
Helpers.GetFiles rootDir searchPattern |> Seq.length > 0

Expand Down Expand Up @@ -139,7 +65,7 @@ let CheckStyleOfFSharpFiles(rootDir: DirectoryInfo) : bool =

let success =
if ContainsFiles rootDir "*.fs" || ContainsFiles rootDir ".fsx" then
StyleFSharpFiles rootDir
StyleFSharpFiles rootDir fantomlessToolVersion
let processResult = GitDiff()
UnwrapProcessResult suggestion true processResult |> ignore
IsProcessSuccessful processResult
Expand Down Expand Up @@ -227,7 +153,7 @@ let CheckStyleOfXamlFiles(rootDir: DirectoryInfo) : bool =

let success =
if ContainsFiles rootDir "*.xaml" then
StyleXamlFiles()
StyleXamlFiles prettierVersion pluginXmlVersion
let processResult = GitDiff()
UnwrapProcessResult suggestion true processResult |> ignore
IsProcessSuccessful processResult
Expand Down
2 changes: 1 addition & 1 deletion src/FileConventions/FileConventions.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</ItemGroup>

<ItemGroup>
<Compile Include="Library.fs" />
<Compile Include="Helpers.fs" />
<Compile Include="Library.fs" />
</ItemGroup>

</Project>
78 changes: 78 additions & 0 deletions src/FileConventions/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ open System.IO
open System.Linq
open System.Text.RegularExpressions

open Helpers

let HasCorrectShebang(fileInfo: FileInfo) =
let fileText = File.ReadLines fileInfo.FullName

Expand Down Expand Up @@ -378,3 +380,79 @@ let NonVerboseFlags(fileInfo: FileInfo) =
|> Seq.length

numInvalidFlags > 0


let StyleFSharpFiles(rootDir: DirectoryInfo, fantomlessToolVersion: string) =
InstallFantomlessTool fantomlessToolVersion

Process
.Execute(
{
Command = "dotnet"
Arguments = $"fantomless --recurse {rootDir.FullName}"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let StyleCSharpFiles(rootDir: DirectoryInfo) =
Process
.Execute(
{
Command = "dotnet"
Arguments = $"format whitespace {rootDir.FullName} --folder"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let StyleXamlFiles (prettierVersion: string) (pluginXmlVersion: string) =
InstallPrettier prettierVersion
InstallPrettierPluginXml pluginXmlVersion

Process
.Execute(
{
Command = "npm"
Arguments =
$"install --save-dev prettier@{prettierVersion} @prettier/plugin-xml@{pluginXmlVersion}"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let pattern = $"**{Path.DirectorySeparatorChar}*.xaml"

Process
.Execute(
{
Command =
Path.Combine(
Directory.GetCurrentDirectory(),
"node_modules",
".bin",
"prettier"
)

Arguments =
$"--xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write {pattern}"
},
Echo.Off
)
.UnwrapDefault()
|> ignore

let StyleTypeScriptFiles() =
let pattern =
$"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts"

RunPrettier $"--quote-props=consistent --write {pattern}"

let StyleYmlFiles() =
let pattern =
$"{Directory.GetCurrentDirectory()}{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml"

RunPrettier $"--quote-props=consistent --write {pattern}"

0 comments on commit e4b86fa

Please sign in to comment.