forked from fsprojects/FSharpLint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core(Tests): new rule and tests for it
Add a rule that suggest usage of auto-property for property with getter that only returns some (immutable) value. Add tests for it.
- Loading branch information
1 parent
af75a00
commit 543ba5b
Showing
5 changed files
with
76 additions
and
0 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
18 changes: 18 additions & 0 deletions
18
src/FSharpLint.Core/Rules/Conventions/SuggestUseAutoProperty.fs
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 @@ | ||
module FSharpLint.Rules.SuggestUseAutoProperty | ||
|
||
open System | ||
open FSharpLint.Framework | ||
open FSharpLint.Framework.Suggestion | ||
open FSharp.Compiler.Syntax | ||
open FSharpLint.Framework.Ast | ||
open FSharpLint.Framework.Rules | ||
|
||
let private runner (args: AstNodeRuleParams) = | ||
|
||
failwith "Not implemented" | ||
|
||
let rule = | ||
{ Name = "SuggestUseAutoProperty" | ||
Identifier = Identifiers.FavourConsistentThis | ||
RuleConfig = { AstNodeRuleConfig.Runner = runner; Cleanup = ignore } } | ||
|> AstNodeRule |
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
55 changes: 55 additions & 0 deletions
55
tests/FSharpLint.Core.Tests/Rules/Conventions/SuggestUseAutoProperty.fs
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,55 @@ | ||
module FSharpLint.Core.Tests.Rules.Conventions.SuggestUseAutoProperty | ||
|
||
open NUnit.Framework | ||
open FSharpLint.Framework.Rules | ||
open FSharpLint.Rules | ||
|
||
[<TestFixture>] | ||
type TestSuggestUseAutoProperty() = | ||
inherit TestAstNodeRuleBase.TestAstNodeRuleBase(SuggestUseAutoProperty.rule) | ||
|
||
[<Test>] | ||
member this.``Should suggest usage of auto-property for property that only returns immutable value`` () = | ||
this.Parse """ | ||
type Foo(content: int) = | ||
member x.Content = content | ||
""" | ||
|
||
Assert.IsTrue(this.ErrorsExist) | ||
|
||
[<Test>] | ||
member this.``Should suggest usage of auto-property for property that only returns literal`` () = | ||
this.Parse """ | ||
type Foo() = | ||
member x.Content = 42 | ||
""" | ||
|
||
Assert.IsTrue(this.ErrorsExist) | ||
|
||
[<Test>] | ||
member this.``Shouldn't suggest usage of auto-property for non-property member``() = | ||
this.Parse """ | ||
type Foo(content: int) = | ||
member x.Content() = content | ||
""" | ||
|
||
Assert.IsTrue(this.NoErrorsExist) | ||
|
||
[<Test>] | ||
member this.``Shouldn't suggest usage of auto-property for property that does more than just return value``() = | ||
this.Parse """ | ||
type Foo(content: int) = | ||
member x.Content = content.ToString() | ||
""" | ||
|
||
Assert.IsTrue(this.NoErrorsExist) | ||
|
||
[<Test>] | ||
member this.``Shouldn't suggest usage of auto-property for property that returns mutable value``() = | ||
this.Parse """ | ||
type Foo(content: int) = | ||
let mutable mutableContent = content | ||
member x.Content = mutableContent | ||
""" | ||
|
||
Assert.IsTrue(this.NoErrorsExist) |