From deb3af6e38c05dcbed87b36eb3cdc589f156ea1b Mon Sep 17 00:00:00 2001 From: Mehrshad Date: Wed, 27 Dec 2023 14:30:58 +0330 Subject: [PATCH] MaxLinesIn*: remove skip properties To respect YAGNI. Also comments on TestMaxLinesInModule replaced with a variable because the rule now skips comments. --- docs/content/how-tos/rules/FL0022.md | 10 +--- docs/content/how-tos/rules/FL0023.md | 10 +--- docs/content/how-tos/rules/FL0024.md | 10 +--- docs/content/how-tos/rules/FL0025.md | 10 +--- docs/content/how-tos/rules/FL0026.md | 10 +--- docs/content/how-tos/rules/FL0027.md | 10 +--- docs/content/how-tos/rules/FL0028.md | 10 +--- docs/content/how-tos/rules/FL0029.md | 10 +--- docs/content/how-tos/rules/FL0030.md | 10 +--- docs/content/how-tos/rules/FL0031.md | 10 +--- docs/content/how-tos/rules/FL0032.md | 10 +--- docs/content/how-tos/rules/FL0033.md | 10 +--- docs/content/how-tos/rules/FL0062.md | 10 +--- .../SourceLength/SourceLengthHelper.fs | 21 ++------ src/FSharpLint.Core/fsharplint.json | 52 +++++-------------- .../Rules/Conventions/SourceLength.fs | 28 +++++----- 16 files changed, 45 insertions(+), 186 deletions(-) diff --git a/docs/content/how-tos/rules/FL0022.md b/docs/content/how-tos/rules/FL0022.md index 81e17f2e3..ef210b62e 100644 --- a/docs/content/how-tos/rules/FL0022.md +++ b/docs/content/how-tos/rules/FL0022.md @@ -24,15 +24,7 @@ Consider using a named function rather than a lambda function. "maxLinesInLambdaFunction": { "enabled": false, "config": { - "maxLines": 7, - "skipBlankLines": false, - "skipComments": false + "maxLines": 7 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0023.md b/docs/content/how-tos/rules/FL0023.md index 2e8fd1971..5f56d8d98 100644 --- a/docs/content/how-tos/rules/FL0023.md +++ b/docs/content/how-tos/rules/FL0023.md @@ -24,15 +24,7 @@ Use active patterns to help reduce the number of matches/extract code out into c "maxLinesInMatchLambdaFunction": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0024.md b/docs/content/how-tos/rules/FL0024.md index 555706b3d..f692b3c95 100644 --- a/docs/content/how-tos/rules/FL0024.md +++ b/docs/content/how-tos/rules/FL0024.md @@ -32,15 +32,7 @@ Refactor to extract out code into smaller composable functions. "maxLinesInValue": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0025.md b/docs/content/how-tos/rules/FL0025.md index 67475e558..c8636d128 100644 --- a/docs/content/how-tos/rules/FL0025.md +++ b/docs/content/how-tos/rules/FL0025.md @@ -24,15 +24,7 @@ Refactor to extract out code into smaller composable functions. "maxLinesInFunction": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0026.md b/docs/content/how-tos/rules/FL0026.md index d63555591..4e2c281f7 100644 --- a/docs/content/how-tos/rules/FL0026.md +++ b/docs/content/how-tos/rules/FL0026.md @@ -24,15 +24,7 @@ Extract code out into private methods or functions. "maxLinesInMember": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0027.md b/docs/content/how-tos/rules/FL0027.md index ddc84b258..8b4fcf698 100644 --- a/docs/content/how-tos/rules/FL0027.md +++ b/docs/content/how-tos/rules/FL0027.md @@ -24,15 +24,7 @@ Extract code out into private methods or functions. "maxLinesInConstructor": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0028.md b/docs/content/how-tos/rules/FL0028.md index d8678d899..4f6b377a3 100644 --- a/docs/content/how-tos/rules/FL0028.md +++ b/docs/content/how-tos/rules/FL0028.md @@ -24,15 +24,7 @@ Extract code out into private methods or functions. "MaxLinesInProperty": { "enabled": false, "config": { - "maxLines": 70, - "skipBlankLines": false, - "skipComments": false + "maxLines": 70 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0029.md b/docs/content/how-tos/rules/FL0029.md index c160275a1..98ae2fe2c 100644 --- a/docs/content/how-tos/rules/FL0029.md +++ b/docs/content/how-tos/rules/FL0029.md @@ -24,15 +24,7 @@ Extract code out into smaller modules. "maxLinesInModule": { "enabled": false, "config": { - "maxLines": 1000, - "skipBlankLines": false, - "skipComments": false + "maxLines": 1000 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0030.md b/docs/content/how-tos/rules/FL0030.md index c7ae1e002..40cffb7e4 100644 --- a/docs/content/how-tos/rules/FL0030.md +++ b/docs/content/how-tos/rules/FL0030.md @@ -24,15 +24,7 @@ Extract code out into smaller composed records. "maxLinesInRecord": { "enabled": false, "config": { - "maxLines": 500, - "skipBlankLines": false, - "skipComments": false + "maxLines": 500 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0031.md b/docs/content/how-tos/rules/FL0031.md index 3d81ba439..e065282b9 100644 --- a/docs/content/how-tos/rules/FL0031.md +++ b/docs/content/how-tos/rules/FL0031.md @@ -24,15 +24,7 @@ Extract code out into smaller enums. "maxLinesInEnum": { "enabled": false, "config": { - "maxLines": 500, - "skipBlankLines": false, - "skipComments": false + "maxLines": 500 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0032.md b/docs/content/how-tos/rules/FL0032.md index 017d12cc7..5a980838a 100644 --- a/docs/content/how-tos/rules/FL0032.md +++ b/docs/content/how-tos/rules/FL0032.md @@ -24,15 +24,7 @@ Extract code out into smaller composed discriminated unions. "maxLinesInUnion": { "enabled": false, "config": { - "maxLines": 500, - "skipBlankLines": false, - "skipComments": false + "maxLines": 500 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0033.md b/docs/content/how-tos/rules/FL0033.md index ce43f00b3..841c84860 100644 --- a/docs/content/how-tos/rules/FL0033.md +++ b/docs/content/how-tos/rules/FL0033.md @@ -24,15 +24,7 @@ Extract code out into smaller composable classes. "maxLinesInClass": { "enabled": false, "config": { - "maxLines": 500, - "skipBlankLines": false, - "skipComments": false + "maxLines": 500 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/docs/content/how-tos/rules/FL0062.md b/docs/content/how-tos/rules/FL0062.md index 83b183d08..dcd0622e7 100644 --- a/docs/content/how-tos/rules/FL0062.md +++ b/docs/content/how-tos/rules/FL0062.md @@ -24,15 +24,7 @@ Refactor to extract code out into another file. "maxLinesInFile": { "enabled": false, "config": { - "maxLinesInFile": 1000, - "skipBlankLines": false, - "skipComments": false + "maxLinesInFile": 1000 } } } - -*Introduced in `0.23.0`:* - -The default setting will be false if the option is not provided in the Rule Settings: -* *skipBlankLines* - A boolean property that determines whether blank lines will be skipped. (Default false) -* *skipComments* - A boolean property that determines whether commented lines will be skipped. (Default false) diff --git a/src/FSharpLint.Core/Rules/Conventions/SourceLength/SourceLengthHelper.fs b/src/FSharpLint.Core/Rules/Conventions/SourceLength/SourceLengthHelper.fs index b3bd888a0..e70ddd69b 100644 --- a/src/FSharpLint.Core/Rules/Conventions/SourceLength/SourceLengthHelper.fs +++ b/src/FSharpLint.Core/Rules/Conventions/SourceLength/SourceLengthHelper.fs @@ -11,8 +11,6 @@ open FSharpLint.Framework.ExpressionUtilities type Config = { MaxLines:int - SkipBlankLines: bool - SkipComments: bool } type private MultilineCommentMarker = @@ -62,25 +60,16 @@ let checkSourceLengthRule (config:Config) range fileContents errorName = match tryFindTextOfRange range fileContents with | Some(sourceCode) -> let sourceCode = - if config.SkipComments then - stripMultilineComments sourceCode - else - sourceCode + stripMultilineComments sourceCode let commentLinesCount = - if config.SkipComments then - singleLineCommentRegex.Matches(sourceCode).Count - else - 0 + singleLineCommentRegex.Matches(sourceCode).Count let sourceCodeLines = sourceCode.Split([| '\n'; '\r' |]) let blankLinesCount = - if config.SkipBlankLines then - sourceCodeLines - |> Seq.filter (fun line -> line.Trim().Length > 0) - |> Seq.length - else - 0 + sourceCodeLines + |> Seq.filter (fun line -> line.Trim().Length > 0) + |> Seq.length let skipResult = sourceCodeLines.Length - commentLinesCount - blankLinesCount if skipResult > config.MaxLines then diff --git a/src/FSharpLint.Core/fsharplint.json b/src/FSharpLint.Core/fsharplint.json index 74ec859b6..2759ac977 100644 --- a/src/FSharpLint.Core/fsharplint.json +++ b/src/FSharpLint.Core/fsharplint.json @@ -49,97 +49,73 @@ "maxLinesInLambdaFunction": { "enabled": false, "config": { - "maxLines": 7, - "skipBlankLines": false, - "skipComments": false + "maxLines": 7 } }, "maxLinesInMatchLambdaFunction": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } }, "maxLinesInValue": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } }, "maxLinesInFunction": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } }, "maxLinesInMember": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } }, "maxLinesInConstructor": { "enabled": false, "config": { - "maxLines": 100, - "skipBlankLines": false, - "skipComments": false + "maxLines": 100 } }, "maxLinesInProperty": { "enabled": false, "config": { - "maxLines": 70, - "skipBlankLines": false, - "skipComments": false + "maxLines": 70 } }, "maxLinesInModule": { "enabled": false, "config": { - "maxLines": 1000, - "skipBlankLines": false, - "skipComments": false + "maxLines": 1000 } }, "maxLinesInRecord": { "enabled": false, "config": { - "maxLines": 500, - "skipBlankLines": false, - "skipComments": false + "maxLines": 500 } }, "maxLinesInEnum": { "enabled": false, "config": { - "maxLines": 500, - "skipBlankLines": false, - "skipComments": false + "maxLines": 500 } }, "maxLinesInUnion": { "enabled": false, "config": { - "maxLines": 500, - "skipBlankLines": false, - "skipComments": false + "maxLines": 500 } }, "maxLinesInClass": { "enabled": false, "config": { - "maxLines": 500, - "skipBlankLines": false, - "skipComments": false + "maxLines": 500 } }, "interfaceNames": { @@ -320,9 +296,7 @@ "maxLinesInFile": { "enabled": false, "config": { - "maxLinesInFile": 1000, - "skipBlankLines": false, - "skipComments": false + "maxLinesInFile": 1000 } }, "trailingNewLineInFile": { "enabled": false }, diff --git a/tests/FSharpLint.Core.Tests/Rules/Conventions/SourceLength.fs b/tests/FSharpLint.Core.Tests/Rules/Conventions/SourceLength.fs index db4e65151..55104a9f5 100644 --- a/tests/FSharpLint.Core.Tests/Rules/Conventions/SourceLength.fs +++ b/tests/FSharpLint.Core.Tests/Rules/Conventions/SourceLength.fs @@ -9,7 +9,7 @@ let generateNewLines numNewLines = Array.create numNewLines "\n" |> String.conca let FunctionLength = 70 [] type TestMaxLinesInFunction() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInFunction.rule { Config.MaxLines = FunctionLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInFunction.rule { Config.MaxLines = FunctionLength }) [] member this.FunctionTooManyLines() = @@ -77,7 +77,7 @@ let dog x = let LambdaFunctionLength = 5 [] type TestMaxLinesInLambdaFunction() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInLambdaFunction.rule { Config.MaxLines = LambdaFunctionLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInLambdaFunction.rule { Config.MaxLines = LambdaFunctionLength }) [] member this.LambdaFunctionTooManyLines() = @@ -124,7 +124,7 @@ let dog = fun x -> let MatchLambdaFunctionLength = 70 [] type TestMaxLinesInMatchLambdaFunction() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInMatchLambdaFunction.rule { Config.MaxLines = MatchLambdaFunctionLength; SkipBlankLines = false; SkipComments = false }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInMatchLambdaFunction.rule { Config.MaxLines = MatchLambdaFunctionLength }) [] member this.MatchFunctionTooManyLines() = @@ -153,7 +153,7 @@ let dog = function let ValueLength = 70 [] type TestMaxLinesInValue() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInValue.rule { Config.MaxLines = ValueLength; SkipBlankLines = false; SkipComments = false }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInValue.rule { Config.MaxLines = ValueLength }) [] member this.ValueTooManyLines() = @@ -178,7 +178,7 @@ let dog = let ConstructorLength = 70 [] type TestMaxLinesInConstructor() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInConstructor.rule { Config.MaxLines = ConstructorLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInConstructor.rule { Config.MaxLines = ConstructorLength }) [] member this.ConstructorTooManyLines() = @@ -202,13 +202,13 @@ type MyClass(x) = let MemberLength = 70 [] type TestMaxLinesInMember() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInMember.rule { Config.MaxLines = MemberLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInMember.rule { Config.MaxLines = MemberLength }) // TODO: Add tests. let PropertyLength = 70 [] type TestMaxLinesInProperty() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInProperty.rule { Config.MaxLines = PropertyLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInProperty.rule { Config.MaxLines = PropertyLength }) [] member this.PropertyNotTooManyLines() = @@ -223,7 +223,7 @@ module Program let ClassLength = 500 [] type TestMaxLinesInClass() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInClass.rule { Config.MaxLines = ClassLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInClass.rule { Config.MaxLines = ClassLength }) [] member this.ClassTooManyLines() = @@ -262,13 +262,13 @@ module Program let UnionLength = 500 [] type TestMaxLinesInUnion() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInUnion.rule { Config.MaxLines = UnionLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInUnion.rule { Config.MaxLines = UnionLength }) // TODO: Add tests. let RecordLength = 500 [] type TestMaxLinesInRecord() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInRecord.rule { Config.MaxLines = RecordLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInRecord.rule { Config.MaxLines = RecordLength }) [] member this.RecordTooManyLines() = @@ -291,20 +291,20 @@ module Program let EnumLength = 1000 [] type TestMaxLinesInEnum() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInEnum.rule { Config.MaxLines = EnumLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInEnum.rule { Config.MaxLines = EnumLength }) // TODO: Add tests. let ModuleLength = 1000 [] type TestMaxLinesInModule() = - inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInModule.rule { Config.MaxLines = ModuleLength; SkipBlankLines = false; SkipComments = true }) + inherit TestAstNodeRuleBase.TestAstNodeRuleBase(MaxLinesInModule.rule { Config.MaxLines = ModuleLength }) [] member this.ModuleTooManyLines() = this.Parse(sprintf """ module Program %s -// Some exception. +let foo = "" exception SomeException of string""" (generateNewLines ModuleLength)) Assert.IsTrue(this.ErrorExistsAt(2, 0)) @@ -313,6 +313,6 @@ exception SomeException of string""" (generateNewLines ModuleLength)) this.Parse(sprintf """ module Program %s -// Some exception. +let foo = "" exception SomeException of string""" (generateNewLines (ModuleLength - 4))) Assert.IsFalse(this.ErrorExistsAt(2, 0))