Skip to content

Commit

Permalink
build: refactoring for rule activation
Browse files Browse the repository at this point in the history
This refactoring activates all rules by default and only
deactivates the specified ones.
  • Loading branch information
Mersho committed Feb 12, 2024
1 parent e263e32 commit 2726f8b
Showing 1 changed file with 26 additions and 36 deletions.
62 changes: 26 additions & 36 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,47 +226,37 @@ Target.create "SelfCheck" (fun _ ->
let fsharplintJsonDir = Path.Combine("src", "FSharpLint.Core", "fsharplint.json")
let fsharplintJsonText = File.ReadAllText fsharplintJsonDir

let recommendedRules =
[
"recursiveAsyncFunction"
"nestedStatements"
(*
"cyclomaticComplexity" rule is too complex and we can enable it later
*)
"avoidSinglePipeOperator"
"maxLinesInLambdaFunction"
"maxLinesInMatchLambdaFunction"
"maxLinesInValue"
"maxLinesInFunction"
"maxLinesInMember"
"maxLinesInConstructor"
"maxLinesInProperty"
"maxLinesInModule"
"maxLinesInRecord"
"maxLinesInEnum"
"maxLinesInUnion"
"maxLinesInClass"
"favourTypedIgnore"
"favourStaticEmptyFields"
"favourConsistentThis"
"avoidTooShortNames"
"asyncExceptionWithoutReturn"
"maxNumberOfItemsInTuple"
"maxNumberOfFunctionParameters"
"maxNumberOfMembers"
"maxNumberOfBooleanOperatorsInCondition"
"noPartialFunctions"
"suggestUseAutoProperty"
"maxLinesInFile"
let excludedRules =
[
"typedItemSpacing"
"typePrefixing"
"unionDefinitionIndentation"
"moduleDeclSpacing"
"classMemberSpacing"
"tupleCommaSpacing"
"tupleIndentation"
"tupleParentheses"
"patternMatchClausesOnNewLine"
"patternMatchOrClausesOnNewLine"
"patternMatchClauseIndentation"
"patternMatchExpressionIndentation"
// rule is too complex and we can enable it later
"cyclomaticComplexity"
"unnestedFunctionNames"
"nestedFunctionNames"
"indentation"
"maxCharactersOnLine"
"trailingWhitespaceOnLine"
"trailingNewLineInFile"
]

let jsonObj = JObject.Parse fsharplintJsonText

for key in recommendedRules do
let token = jsonObj.SelectToken key
for pair in jsonObj do
let isRule = (jsonObj.SelectToken pair.Key).SelectToken("enabled")

if not (isNull token) then
token.SelectToken("enabled").Replace(JValue true) |> ignore<unit>
if not (isNull isRule) && not (List.contains pair.Key excludedRules) then
isRule.Replace(JValue true) |> ignore<unit>

File.WriteAllText(fsharplintJsonDir, jsonObj.ToString())

Expand Down

0 comments on commit 2726f8b

Please sign in to comment.