-
Notifications
You must be signed in to change notification settings - Fork 12
Add scripts to apply and check the style of F#, C#, TS, YMl and XAML files #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
tehraninasab
wants to merge
4
commits into
nblockchain:master
from
tehraninasab:addStyleCheckerScript-squashed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,19 @@ | ||
| #!/usr/bin/env -S dotnet fsi | ||
|
|
||
| #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" | ||
| #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() | ||
| StyleYmlFiles() | ||
| StyleCSharpFiles rootDir | ||
| StyleXamlFiles() |
This file contains hidden or 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,187 @@ | ||
| #!/usr/bin/env -S dotnet fsi | ||
|
|
||
| #r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1" | ||
| #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(".", "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 | ||
|
|
||
| // We need this step so we can change the files using `npx prettier --write` in the prettier calls. | ||
| // Otherwise we get permission denied error in the CI. | ||
| Process | ||
| .Execute( | ||
| { | ||
| Command = "chmod" | ||
| Arguments = "777 --recursive ." | ||
| }, | ||
| Echo.Off | ||
| ) | ||
| .UnwrapDefault() | ||
| |> ignore | ||
|
|
||
| let processSuccessStates = | ||
| [| | ||
| CheckStyleOfFSharpFiles rootDir | ||
| CheckStyleOfCSharpFiles rootDir | ||
| CheckStyleOfTypeScriptFiles rootDir | ||
| CheckStyleOfYmlFiles rootDir | ||
| CheckStyleOfXamlFiles rootDir | ||
| |] | ||
|
|
||
| if processSuccessStates |> Seq.contains false then | ||
| Environment.Exit 1 | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
| module Config | ||
|
|
||
| let FantomlessToolVersion = "4.7.997-prerelease" | ||
| let PrettierVersion = "2.8.3" | ||
| let PluginXmlVersion = "v2.2.0" |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.