-
Notifications
You must be signed in to change notification settings - Fork 73
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. Co-authored-by: Mehrshad <code.rezaei@gmail.com>
- Loading branch information
1 parent
c7ceca1
commit 4c93a90
Showing
6 changed files
with
54 additions
and
1 deletion.
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
19 changes: 19 additions & 0 deletions
19
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,19 @@ | ||
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 yet 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
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
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
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 self.Content = content | ||
""" | ||
|
||
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 self.Content() = content | ||
""" | ||
|
||
Assert.IsTrue(this.NoErrorsExist) | ||
|