Skip to content
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

Easy dotnet conventions to verify #141

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5071790
FileConventions: add failing test
tehraninasab Aug 1, 2023
854bb84
FileConventions: implement the function
tehraninasab Aug 1, 2023
64aa0ef
FileConventions: add failing test
tehraninasab Aug 1, 2023
ac8e438
FileConventions: implement the function
tehraninasab Aug 3, 2023
be96888
FileConventions: add failing test
tehraninasab Aug 7, 2023
2ad886c
FileConventions: implement the function
tehraninasab Aug 7, 2023
4cb987e
FileConventions.Test: add failing test
tehraninasab Aug 7, 2023
bf64190
FileConventions: fix the function
tehraninasab Aug 7, 2023
f95737a
FileConventions: add failing test
Mersho Aug 17, 2023
fe91fed
FileConventions: fix csharp namespace
Mersho Aug 17, 2023
2e5b0cc
FileConventions: add failing test
Mersho Aug 17, 2023
842e3c1
FileConventions: `Contains()` is not suitable here
Mersho Aug 17, 2023
040d85d
FileConventions: use BetterAssert() & update Fsdk
Mersho Aug 21, 2023
b85986b
FileConventions(.Test): applying f# standard style
Mersho Aug 21, 2023
4cbf1bc
FileConventions: add failing test
Mersho Aug 21, 2023
c15b542
FileConventions: fix the function
Mersho Aug 21, 2023
e532e35
FileConventions: add failing test
Mersho Aug 22, 2023
cc7b70e
FileConvention: fix the function
Mersho Aug 22, 2023
86db3b3
FileConventions: add failing test
Mersho Aug 22, 2023
4ee7a19
FileConvention: fix the function
Mersho Aug 22, 2023
18e91ea
FileConventions(.Test): fix proj file indent
Mersho Aug 28, 2023
2f8f770
FileConvention: properly naming variables
Mersho Aug 28, 2023
f937c57
FileConventions: add failing test
Mersho Aug 29, 2023
edd540f
FileConvention: fix the function
Mersho Aug 29, 2023
e71117f
FileConventions.Test: add failing test
Mersho Aug 23, 2023
071e30a
FileConventions: fix empty string false-positives
Mersho Aug 23, 2023
1731514
FileConventions: load Helpers.fs first
Mersho Aug 24, 2023
f1bfbb0
FileConventions: improvements to Library.fs
Mersho Aug 24, 2023
e6dd18d
scripts: add dotNetFileConventions.fsx
Mersho Aug 24, 2023
280d634
FileConventions: improvements to Library.fs
Mersho Sep 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/checkCommits1by1.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open System.Net.Http.Headers
#r "nuget: FSharp.Data, Version=5.0.2"
open FSharp.Data

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

open Fsdk
open Fsdk.Process
Expand Down
2 changes: 1 addition & 1 deletion scripts/compileFSharpScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
open System
open System.IO

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

Fsdk
Expand Down
79 changes: 79 additions & 0 deletions scripts/dotnetFileConventions.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env -S dotnet fsi

open System
open System.IO
open System.Text.RegularExpressions

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

open Fsdk
open Fsdk.Process

#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

open FileConventions
open Helpers

let args = Misc.FsxOnlyArguments()

if args.Length > 1 then
Console.Error.WriteLine
"Usage: dotnetFileConventions.fsx [projectFolder(optional)]"

Environment.Exit 1

let rootDir = DirectoryInfo args.[0]

// DefiningEmptyStringsWithDoubleQuotes
let allSourceFiles = ReturnAllProjectSourceFiles rootDir [ "*.cs"; "*.fs" ] true
printfn "%A" (String.Join("\n", allSourceFiles))

let allProjFiles =
ReturnAllProjectSourceFiles rootDir [ "*.csproj"; "*.fsproj" ] true

for sourceFile in allSourceFiles do
let isStringEmpty = DefiningEmptyStringsWithDoubleQuotes sourceFile

if isStringEmpty then
failwith(
sprintf
"%s file: Contains empty strings specifed with \"\" , you should use String.Empty()"
sourceFile.FullName
)


// ProjFilesNamingConvention

for projfile in allProjFiles do
let isWrongProjFile = ProjFilesNamingConvention projfile

if isWrongProjFile then
failwith(
sprintf
"%s file: Project file or Project directory is incorrect!\n
Fix: use same name on .csproj/.fsproj on parrent project directory"
projfile.FullName
)

// notfollowingnamespaceconvention
for sourcefile in allSourceFiles do
let iswrongnamespace = NotFollowingNamespaceConvention sourcefile

if iswrongnamespace then
failwith(sprintf "%s file: has wrong namespace!" sourcefile.FullName)

// NotFollowingConsoleAppConvention
for projfile in allProjFiles do
let isWrongConsoleApplication =
NotFollowingConsoleAppConvention projfile true

printfn "%A" projfile

if isWrongConsoleApplication then
failwith(
sprintf
"%s project: Should not contain console methods or printf"
projfile.FullName
)
1 change: 1 addition & 0 deletions scripts/eofConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System.IO
open System

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"
Expand Down
3 changes: 2 additions & 1 deletion scripts/executableConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#load "../src/FileConventions/Library.fs"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
2 changes: 1 addition & 1 deletion scripts/gitPush1by1.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open System.Threading
#r "System.Configuration"
open System.Configuration

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

open Fsdk
open Fsdk.Process
Expand Down
3 changes: 2 additions & 1 deletion scripts/inconsistentVersionsInFSharpScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ open System.IO
open System.Linq

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo
let currentDir = Directory.GetCurrentDirectory() |> DirectoryInfo
Expand Down
3 changes: 2 additions & 1 deletion scripts/inconsistentVersionsInGitHubCI.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
3 changes: 2 additions & 1 deletion scripts/mixedLineEndings.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
3 changes: 2 additions & 1 deletion scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
3 changes: 2 additions & 1 deletion scripts/shebangConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
3 changes: 2 additions & 1 deletion scripts/unpinnedDotnetPackageVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
3 changes: 2 additions & 1 deletion scripts/unpinnedDotnetToolInstallVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
3 changes: 2 additions & 1 deletion scripts/unpinnedGitHubActionsImageVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
3 changes: 2 additions & 1 deletion scripts/unpinnedNugetPackageReferenceVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

let rootDir = Path.Combine(__SOURCE_DIRECTORY__, "..") |> DirectoryInfo

Expand Down
4 changes: 2 additions & 2 deletions scripts/wrapLatestCommitMsg.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ open System
open System.Text.RegularExpressions

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"

open Fsdk
open Fsdk.Process

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
printf "Hello World"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
printf "Hello World"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
async { do! Async.Sleep(5000) } |> Async.RunSynchronously
printf "Hello World"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace DummyProjectAsync

module Say =

let delayedHello name =
async { do! Async.Sleep(5000) } |> Async.RunSynchronously
"Delayed Hello"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
printf "Hello World"
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

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

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// printf not accepted here
namespace DummyProjectWithWrongConsole

module Say =
let hello name =
printfn "Hello %s" name
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S dotnet fsi

open System
open System.IO

let emptyString = String.Empty
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let myString = "\"Hello World\""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let temp = "Hello World"

match temp with
| "" -> failwith "Empty String"
| _ -> failwith "Non-Empty String"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S dotnet fsi

open System
open System.IO

let emptyString = ""
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace Foo.Bar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace Foo.Baz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace Bar
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System;

namespace Foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace Baz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace FooBuzz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
printf "Hello"
Loading
Loading