forked from nblockchain/conventions
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split styleChecker into styleCheck and styleApply.
- Loading branch information
1 parent
2ecf57b
commit c185305
Showing
19 changed files
with
515 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env -S dotnet fsi | ||
|
||
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62" | ||
#load "../src/FileConventions/Config.fs" | ||
#load "../src/FileConventions/Helpers.fs" | ||
#load "../src/FileConventions/Library.fs" | ||
|
||
open System.IO | ||
|
||
open FileConventions | ||
|
||
let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo | ||
|
||
StyleFSharpFiles rootDir | ||
StyleTypeScriptFiles() | ||
This comment has been minimized.
Sorry, something went wrong. |
||
StyleYmlFiles() | ||
StyleCSharpFiles rootDir | ||
StyleXamlFiles() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
#!/usr/bin/env -S dotnet fsi | ||
|
||
#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62" | ||
#load "../src/FileConventions/Config.fs" | ||
#load "../src/FileConventions/Helpers.fs" | ||
#load "../src/FileConventions/Library.fs" | ||
|
||
open System | ||
open System.IO | ||
|
||
open Fsdk | ||
open Fsdk.Process | ||
|
||
open Helpers | ||
open FileConventions | ||
|
||
let ContainsFiles (rootDir: DirectoryInfo) (searchPattern: string) = | ||
Helpers.GetFiles rootDir searchPattern |> Seq.length > 0 | ||
|
||
let GitDiff() : ProcessResult = | ||
|
||
// Since we changed file modes in the prettier step we need the following command to | ||
// make git ignore mode changes in files and doesn't include them in the git diff command. | ||
Process | ||
.Execute( | ||
{ | ||
Command = "git" | ||
Arguments = "config core.fileMode false" | ||
}, | ||
Echo.Off | ||
) | ||
.UnwrapDefault() | ||
|> ignore | ||
|
||
let processResult = | ||
Process.Execute( | ||
{ | ||
Command = "git" | ||
Arguments = "diff --exit-code" | ||
}, | ||
Echo.Off | ||
) | ||
|
||
processResult | ||
|
||
let GitRestore() = | ||
Process | ||
.Execute( | ||
{ | ||
Command = "git" | ||
Arguments = "restore ." | ||
}, | ||
Echo.Off | ||
) | ||
.UnwrapDefault() | ||
|> ignore | ||
|
||
let CheckStyleOfFSharpFiles(rootDir: DirectoryInfo) : bool = | ||
let suggestion = | ||
Some "Please style your F# code using: `dotnet fantomless --recurse .`" | ||
|
||
GitRestore() | ||
|
||
let success = | ||
if ContainsFiles rootDir "*.fs" || ContainsFiles rootDir ".fsx" then | ||
StyleFSharpFiles rootDir | ||
let processResult = GitDiff() | ||
UnwrapProcessResult suggestion true processResult |> ignore | ||
IsProcessSuccessful processResult | ||
|
||
else | ||
true | ||
|
||
success | ||
|
||
let CheckStyleOfTypeScriptFiles(rootDir: DirectoryInfo) : bool = | ||
let pattern = | ||
$".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.ts" | ||
|
||
let suggestion = | ||
Some | ||
$"Please style your TypeScript code using: `npx prettier --quote-props=consistent --write {pattern}`" | ||
|
||
GitRestore() | ||
|
||
let success = | ||
if ContainsFiles rootDir "*.ts" then | ||
StyleTypeScriptFiles() | ||
let processResult = GitDiff() | ||
UnwrapProcessResult suggestion true processResult |> ignore | ||
IsProcessSuccessful processResult | ||
|
||
else | ||
true | ||
|
||
success | ||
|
||
let CheckStyleOfYmlFiles(rootDir: DirectoryInfo) : bool = | ||
let pattern = | ||
$".{Path.DirectorySeparatorChar}**{Path.DirectorySeparatorChar}*.yml" | ||
|
||
let suggestion = | ||
Some | ||
$"Please style your YML code using: `npx prettier --quote-props=consistent --write {pattern}`" | ||
|
||
GitRestore() | ||
|
||
let success = | ||
if ContainsFiles rootDir "*.yml" then | ||
StyleYmlFiles() | ||
let processResult = GitDiff() | ||
UnwrapProcessResult suggestion true processResult |> ignore | ||
IsProcessSuccessful processResult | ||
else | ||
true | ||
|
||
success | ||
|
||
let CheckStyleOfCSharpFiles(rootDir: DirectoryInfo) : bool = | ||
let suggestion = | ||
Some | ||
"Please style your C# code using: `dotnet format whitespace . --folder" | ||
|
||
GitRestore() | ||
|
||
let success = | ||
if ContainsFiles rootDir "*.cs" then | ||
StyleCSharpFiles rootDir | ||
let processResult = GitDiff() | ||
UnwrapProcessResult suggestion true processResult |> ignore | ||
IsProcessSuccessful processResult | ||
else | ||
true | ||
|
||
success | ||
|
||
let CheckStyleOfXamlFiles(rootDir: DirectoryInfo) : bool = | ||
let prettierPath = | ||
Path.Combine( | ||
Directory.GetCurrentDirectory(), | ||
"node_modules", | ||
".bin", | ||
"prettier" | ||
) | ||
|
||
let pattern = $"**{Path.DirectorySeparatorChar}*.xaml" | ||
|
||
let suggestion = | ||
"Please style your XAML code using:" | ||
+ Environment.NewLine | ||
+ $"`{prettierPath} --xml-whitespace-sensitivity ignore --tab-width 4 --prose-wrap preserve --write {pattern}`" | ||
|> Some | ||
|
||
GitRestore() | ||
|
||
let success = | ||
if ContainsFiles rootDir "*.xaml" then | ||
StyleXamlFiles() | ||
let processResult = GitDiff() | ||
UnwrapProcessResult suggestion true processResult |> ignore | ||
IsProcessSuccessful processResult | ||
else | ||
true | ||
|
||
success | ||
|
||
let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo | ||
|
||
let processSuccessStates = | ||
[| | ||
CheckStyleOfFSharpFiles rootDir | ||
CheckStyleOfCSharpFiles rootDir | ||
CheckStyleOfTypeScriptFiles rootDir | ||
CheckStyleOfYmlFiles rootDir | ||
CheckStyleOfXamlFiles rootDir | ||
|] | ||
|
||
if processSuccessStates |> Seq.contains false then | ||
Environment.Exit 1 |
Oops, something went wrong.
@realmarv this script is calling this func which is calling another func which is calling chmod; chmod should only be invoked by CI (so styleCheck.fsx script, not styleApply.fsx), we don't want to modify the permissions of the files of the developer