@@ -7,10 +7,27 @@ import { RuleCommon } from "./RuleCommon";
77import { RuleInfo } from "./RuleInfo" ;
88import { RuleResult } from "./RuleResult" ;
99
10+ /**
11+ * Abstract base class for advanced rules, extending {@link RuleCommon} and implementing
12+ * {@link AdvancedRuleDefinition} and {@link IRuleDefinition}.
13+ *
14+ * @remarks
15+ * This class provides a structure for advanced rule implementations, including
16+ * support for advanced suppression and user-defined suppressions.
17+ *
18+ * @param info - The rule metadata information.
19+ * @param optional - Optional configuration, such as severity.
20+ */
1021export abstract class AdvancedRule
1122 extends RuleCommon
1223 implements AdvancedRuleDefinition , IRuleDefinition
1324{
25+ /**
26+ * Constructs an instance of {@link AdvancedRule}.
27+ *
28+ * @param info - The rule metadata information.
29+ * @param optional - Optional configuration, such as severity.
30+ */
1431 constructor (
1532 info : RuleInfo ,
1633 optional ?: {
@@ -20,7 +37,21 @@ export abstract class AdvancedRule
2037 super ( info , optional ) ;
2138 }
2239
23- abstract execute ( flow : Flow , ruleOptions ?: object ) ;
40+ /**
41+ * Your rule
42+ * @param flow - The flow to analyze.
43+ * @param ruleOptions - Optional rule-specific options.
44+ */
45+ abstract execute ( flow : Flow , ruleOptions ?: object ) : RuleResult ;
46+
47+ /**
48+ * Executes the rule with advanced configuration and applies suppressions.
49+ *
50+ * @param flow - The flow to analyze.
51+ * @param ruleConfiguration - Optional advanced rule configuration.
52+ * @param userFlowSuppressions - Optional list of user-defined suppressions.
53+ * @returns The result of rule execution after applying suppressions.
54+ */
2455 public execute2 (
2556 flow : Flow ,
2657 ruleConfiguration ?: AdvancedConfig ,
@@ -41,7 +72,13 @@ export abstract class AdvancedRule
4172 return ruleResult ;
4273 }
4374}
44-
75+ /**
76+ * Applies user-defined suppressions to the rule result.
77+ *
78+ * @param ruleResult - The result of rule execution.
79+ * @param userFlowRuleSuppressions - Optional list of suppression names to filter out.
80+ * @returns The filtered rule result.
81+ */
4582function generalSuppressions (
4683 ruleResult : RuleResult ,
4784 userFlowRuleSuppressions ?: string [ ]
@@ -57,13 +94,31 @@ function generalSuppressions(
5794 return ruleResult ;
5895}
5996
97+ /**
98+ * Type guard to check if a value is a function.
99+ *
100+ * @param val - The value to check.
101+ * @returns True if the value is a function, false otherwise.
102+ */
60103// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
61104const isFunction = ( val : unknown ) : val is Function => typeof val === "function" ;
62105
106+ /**
107+ * Type guard to check if an instance implements {@link AdvancedSuppression}.
108+ *
109+ * @param instance - The instance to check.
110+ * @returns True if the instance has a suppress method, false otherwise.
111+ */
63112function hasAdvancedSuppression ( instance : unknown ) : instance is AdvancedSuppression {
64113 return isFunction ( ( instance as AdvancedSuppression ) . suppress ) ;
65114}
66115
116+ /**
117+ * Type guard to check if an instance implements {@link IRuleDefinition}.
118+ *
119+ * @param instance - The instance to check.
120+ * @returns True if the instance has an execute method, false otherwise.
121+ */
67122function hasClassicRuleDefinition ( instance : unknown ) : instance is IRuleDefinition {
68123 return isFunction ( ( instance as IRuleDefinition ) . execute ) ;
69124}
0 commit comments