Skip to content
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
50fe215
FileConventions: add failing test
tehraninasab Aug 1, 2023
186213e
FileConventions: implement the function
tehraninasab Aug 1, 2023
2ebd2b5
FileConventions: add failing test
tehraninasab Aug 1, 2023
cc82850
FileConventions: implement the function
tehraninasab Aug 3, 2023
a0272d6
FileConventions: add failing test
tehraninasab Aug 7, 2023
482d4d6
FileConventions: implement the function
tehraninasab Aug 7, 2023
5f06394
FileConventions.Test: add failing test
tehraninasab Aug 7, 2023
12f4d0b
FileConventions: fix the function
tehraninasab Aug 7, 2023
b0acb0c
FileConventions: add failing test
Mersho Aug 17, 2023
7823ab2
FileConventions: fix csharp namespace
Mersho Aug 17, 2023
9b8afb3
FileConventions: add failing test
Mersho Aug 17, 2023
21f3749
FileConventions: `Contains()` is not suitable here
Mersho Aug 17, 2023
81bfb57
FileConventions: use BetterAssert() & update Fsdk
Mersho Aug 21, 2023
e124a91
FileConventions(.Test): applying f# standard style
Mersho Aug 21, 2023
eb5f76c
FileConventions: add failing test
Mersho Aug 21, 2023
885a60a
FileConventions: fix the function
Mersho Aug 21, 2023
4e0c6e1
FileConventions: add failing test
Mersho Aug 22, 2023
6e80056
FileConvention: fix the function
Mersho Aug 22, 2023
46f3dae
FileConventions: add failing test
Mersho Aug 22, 2023
45e298b
FileConvention: fix the function
Mersho Aug 22, 2023
c190f9c
FileConventions(.Test): fix proj file indent
Mersho Aug 28, 2023
d49a99c
FileConvention: properly naming variables
Mersho Aug 28, 2023
19b442d
FileConventions: add failing test
Mersho Aug 29, 2023
e6fc879
FileConvention: fix the function
Mersho Aug 29, 2023
5358b96
FileConventions.Test: add failing test
Mersho Aug 23, 2023
ce4c0c6
FileConventions: fix empty string false-positives
Mersho Aug 23, 2023
18b828e
FileConventions: load Helpers.fs first
Mersho Aug 24, 2023
1fd7576
FileConventions: improvements to Library.fs
Mersho Aug 24, 2023
a326d09
FileConventions: dotnetFileConvention
Mersho Aug 24, 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
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,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
162 changes: 162 additions & 0 deletions src/FileConventions.Test/FileConventions.Test.fs
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,165 @@ let IsExecutableTest2() =
))

Assert.That(IsExecutable fileInfo, Is.EqualTo false)


[<Test>]
let DefiningEmptyStringsWithDoubleQuotes1() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra parens

Path.Combine(
dummyFilesDirectory.FullName,
"DummyScriptWithConventionalEmptyString.fsx"
)
))

Assert.That(DefiningEmptyStringsWithDoubleQuotes fileInfo, Is.EqualTo false)


[<Test>]
let DefiningEmptyStringsWithDoubleQuotes2() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra parens

Path.Combine(
dummyFilesDirectory.FullName,
"DummyScriptWithNonConventionalEmptyString.fsx"
)
))

Assert.That(DefiningEmptyStringsWithDoubleQuotes fileInfo, Is.EqualTo true)


[<Test>]
let ProjFilesNamingConvention1() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra paren

Path.Combine(
dummyFilesDirectory.FullName,
"DummyProjFileWithTheSameNameAsItsParentFolder",
"DummyProjFileWithTheSameNameAsItsParentFolder.fsproj"
)
))

Assert.That(ProjFilesNamingConvention fileInfo, Is.EqualTo false)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.False?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope



[<Test>]
let ProjFilesNamingConvention2() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra paren.

Path.Combine(
dummyFilesDirectory.FullName,
"DummyProject",
"DummyProjFileWithoutTheSameNameAsItsParentFolder.fsproj"
)
))

Assert.That(ProjFilesNamingConvention fileInfo, Is.EqualTo true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it easier to use Assert.True?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, Assert.That is fine



[<Test>]
let NamespaceConvention1() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Path.Combine(
dummyFilesDirectory.FullName,
"src",
"Foo",
"DummyFileUnderFooWithRightNamespace.fs"
)
))

Assert.That(NotFollowingNamespaceConvention fileInfo, Is.EqualTo false)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.False?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope



[<Test>]
let NamespaceConvention2() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Path.Combine(
dummyFilesDirectory.FullName,
"src",
"Foo",
"DummyFileUnderFooWithWrongNamespace.fs"
)
))

Assert.That(NotFollowingNamespaceConvention fileInfo, Is.EqualTo true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert.True?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope



[<Test>]
let NamespaceConvention3() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Path.Combine(
dummyFilesDirectory.FullName,
"src",
"Foo",
"Bar",
"DummyFileUnderBarWithRightNamespace.fs"
)
))

Assert.That(NotFollowingNamespaceConvention fileInfo, Is.EqualTo false)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these asserts, keep happening and I'm not sure which one is desired here, I'm not gonna mention them in the upcoming reviews for this PR. But, if one of them is changed to Assert.False or Assert.True all of them have to change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mersho please don't change



[<Test>]
let NamespaceConvention4() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Path.Combine(
dummyFilesDirectory.FullName,
"src",
"Foo",
"Bar",
"DummyFileUnderBarWithWrongNamespace.fs"
)
))

Assert.That(NotFollowingNamespaceConvention fileInfo, Is.EqualTo true)


[<Test>]
let NamespaceConvention5() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Path.Combine(
dummyFilesDirectory.FullName,
"src",
"Foo",
"Bar",
"DummyFileUnderBarWithWrongNamespace2.fs"
)
))

Assert.That(NotFollowingNamespaceConvention fileInfo, Is.EqualTo true)


[<Test>]
let NamespaceConvention6() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Path.Combine(
dummyFilesDirectory.FullName,
"src",
"Foo",
"DummyFileUnderFooWithRightNamespace.cs"
)
))

Assert.That(NotFollowingNamespaceConvention fileInfo, Is.EqualTo false)


[<Test>]
let NamespaceConvention7() =
let fileInfo =
(FileInfo(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mersho if this has been addressed, please click on the button "Resolve conversation"

Path.Combine(
dummyFilesDirectory.FullName,
"src",
"Foo",
"DummyFileUnderFooWithWrongNamespace2.fs"
)
))

Assert.That(NotFollowingNamespaceConvention fileInfo, Is.EqualTo true)
52 changes: 52 additions & 0 deletions src/FileConventions/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,55 @@ let NonVerboseFlags(fileInfo: FileInfo) =
let IsExecutable(fileInfo: FileInfo) =
let hasExecuteAccess = Syscall.access(fileInfo.FullName, AccessModes.X_OK)
hasExecuteAccess = 0

let DefiningEmptyStringsWithDoubleQuotes(fileInfo: FileInfo) =
let fileText = File.ReadAllText fileInfo.FullName
fileText.Contains "\"\""

let ProjFilesNamingConvention(fileInfo: FileInfo) =
let regex = new Regex("(.*)\..*proj$")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for new keyword

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also extra paren.

assert (regex.IsMatch fileInfo.FullName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about this but I think paren is not needed

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is needed; because assert doesn't receive 2 currified arguments

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert is for debug mode only, are we sure it should be used here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is needed; because assert doesn't receive 2 currified arguments

Not sure because it compiles without them 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aarani you're right, they should use Fsdk's Misc.BetterAssert

let fileName = Path.GetFileNameWithoutExtension fileInfo.FullName

let parentDirectoryName =
Path.GetDirectoryName fileInfo.FullName |> Path.GetFileName

printfn
"File name: %s, Parent directory name: %s"
fileName
parentDirectoryName

fileName <> parentDirectoryName

let DoesNamespaceInclude (fileInfo: FileInfo) (word: string) =
let fileText = File.ReadLines fileInfo.FullName

if fileText.Any() then
let rightNamespace =
fileText |> Seq.find(fun x -> x.Contains "namespace")

rightNamespace.Split().[1].Equals(word)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if using 1 here is good practice. gonna ask @aarani's opinion on this one (we had a similar conversation on another PR)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please give us an example?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • What does no argument to Split function do?
  • Just put 1 inside a well-named variable we can't do much except that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mersho ping? why there's no answer to this Afshin's question?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a result of our discussion with @parhamsaremi @aarani , this is the most effective solution

|| rightNamespace.Split().[1].Equals(word + ";")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra paren

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe also use $"{word};" instead of using +.

else
false

let NotFollowingNamespaceConvention(fileInfo: FileInfo) =
assert
(fileInfo.FullName.EndsWith(".fs") || fileInfo.FullName.EndsWith(".cs"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for paren at all in this line 🤔


let fileName = Path.GetFileNameWithoutExtension fileInfo.FullName
let parentDir = Path.GetDirectoryName fileInfo.FullName |> DirectoryInfo

printfn "File name: %s, Parent directory name: %s" fileName parentDir.Name

if parentDir.Parent.Name = "src" then
DoesNamespaceInclude fileInfo parentDir.Name |> not

elif parentDir.Parent.Parent.Name = "src" then
DoesNamespaceInclude
fileInfo
$"{parentDir.Parent.Name}.{parentDir.Name}"
|> not

else
false