From 73777c5e0c15ed5bd3c3c3cfdc18f66a2166561f Mon Sep 17 00:00:00 2001 From: thindil Date: Wed, 5 Jun 2024 05:02:25 +0000 Subject: [PATCH] refactor: added constructor for RuleOptions FossilOrigin-Name: 927f93bbe96d7a62cdc50b5e045355e3e158a4919dd8a85495723690d4e95235 --- src/rules.nim | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/rules.nim b/src/rules.nim index e466578..45db40a 100644 --- a/src/rules.nim +++ b/src/rules.nim @@ -122,6 +122,39 @@ type fixProc: proc (astNode, parentNode: PNode; rule: RuleOptions; data: string): bool +proc initRuleOptions*(options: seq[RuleOption] = @[]; parent: bool = false; + fileName: FilePath = ""; negation: bool = false; ruleType: RuleTypes = none; + amount: ResultAmount = 0; enabled: bool = true; fixCommand: FixCommand = ""; + identsCache: IdentCache = nil; forceFixCommand: bool = false; + maxResults: Natural = Natural.high; + explanation: Message = ""): RuleOptions {.sideEffect, raises: [], tags: [], + contractual.} = + ## Initialize a new instance of RuleOptions object + ## + ## * options - The list of the program's rule's options + ## * parent - If true, check is currently make in the parent (usualy + ## module) entity + ## * fileName - The path to the file which is checked + ## * negation - If true, the rule show return oposite result + ## * ruleType - The type of rule + ## * amount - The amount of results found by the rule + ## * enabled - If false, the rule is temporary disabled by pragmas + ## * fixCommand - The command executed by the rule if no custom code is set + ## for fix type of rule + ## * identsCache - The Nim identifiers cache + ## * forceFixCommand - If true, force the rule to use fixCommand instead of its + ## fix code + ## * explanation - The explanation which will be show to the user if check + ## or fix type of rule setting is violated by the checked + ## code + ## + ## Returns the new instance of RuleOptions object + return RuleOptions(options: options, parent: parent, fileName: fileName, + negation: negation, ruleType: ruleType, amount: amount, enabled: enabled, + fixCommand: fixCommand, identsCache: identsCache, + forceFixCommand: forceFixCommand, maxResults: maxResults, + explanation: explanation) + template optionsGetterSetter(name: untyped; typ: typedesc) = ## Set the getter for a field of RuleOptions type ##