Skip to content

Commit 367c770

Browse files
committed
docs(#237): add docs to advanced rule
1 parent 1c0e91e commit 367c770

File tree

5 files changed

+157
-15
lines changed

5 files changed

+157
-15
lines changed
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1-
import { RuleResult } from "../internals/internals";
1+
import { RuleResult } from "../models/RuleResult";
22
import { AdvancedConfig } from "./AdvancedRuleConfig";
3+
4+
/**
5+
* Interface for implementing advanced suppression logic on rule scan results.
6+
*
7+
* @remarks
8+
* This interface defines a contract for classes or objects that provide suppression capabilities
9+
* for rule results, potentially modifying or filtering the results based on custom logic and optional configuration.
10+
*
11+
* @interface
12+
*/
313
export interface AdvancedSuppression {
14+
/**
15+
* Suppresses or modifies a given rule scan result based on advanced configuration.
16+
*
17+
* @param scanResult - The result of a rule scan to be potentially suppressed or altered.
18+
* @param ruleConfiguration - Optional advanced configuration that may influence suppression logic.
19+
* @returns The (potentially) suppressed or modified rule result.
20+
*/
421
suppress(scanResult: RuleResult, ruleConfiguration?: AdvancedConfig): RuleResult;
522
}

src/main/interfaces/AutoFixable.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { Flow } from "../internals/internals";
22

3+
/**
4+
* Interface representing an entity capable of automatically fixing a Flow.
5+
*
6+
* Implementations of this interface provide a `fix` method that takes a {@link Flow}
7+
* object as input and returns a new or modified {@link Flow} with applied fixes.
8+
*/
39
export interface AutoFixable {
410
fix(flow: Flow): Flow;
511
}

src/main/models/AdvancedRule.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,27 @@ import { RuleCommon } from "./RuleCommon";
77
import { RuleInfo } from "./RuleInfo";
88
import { 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+
*/
1021
export 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+
*/
4582
function 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
61104
const 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+
*/
63112
function 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+
*/
67122
function hasClassicRuleDefinition(instance: unknown): instance is IRuleDefinition {
68123
return isFunction((instance as IRuleDefinition).execute);
69124
}

src/main/models/FlowType.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,37 @@
1+
/**
2+
* Represents the different types of Salesforce Flows and provides utility methods
3+
* to categorize and retrieve them.
4+
*
5+
* @remarks
6+
* This class defines static properties for various flow types, including backend,
7+
* process builder, survey, visual, and unsupported types. It also provides a method
8+
* to retrieve all supported flow types.
9+
*
10+
* @example
11+
* ```typescript
12+
* const allFlowTypes = FlowType.allTypes();
13+
* ```
14+
*/
115
export class FlowType {
2-
public static autolaunchedType = "AutoLaunchedFlow";
16+
public static readonly autolaunchedType = "AutoLaunchedFlow";
317

4-
public static backEndTypes = [
18+
public static readonly backEndTypes = [
519
this.autolaunchedType,
620
"CustomEvent",
721
"InvocableProcess",
822
"Orchestrator",
923
"EvaluationFlow",
1024
"ActionCadenceAutolaunchedFlow",
1125
];
12-
public static processBuilder = ["Workflow"];
13-
public static surveyTypes = ["Survey"];
14-
public static visualTypes = [
26+
public static readonly processBuilder = ["Workflow"];
27+
public static readonly surveyTypes = ["Survey"];
28+
public static readonly unsupportedTypes = [
29+
"CheckoutFlow",
30+
"FSCLending",
31+
"FSCLending",
32+
"LoyaltyManagementFlow",
33+
];
34+
public static readonly visualTypes = [
1535
"Flow",
1636
"IndividualObjectLinkingFlow",
1737
"LoginFlow",
@@ -25,14 +45,8 @@ export class FlowType {
2545
"FieldServiceWeb",
2646
"SurveyEnrich",
2747
];
28-
public static unsupportedTypes = [
29-
"CheckoutFlow",
30-
"FSCLending",
31-
"FSCLending",
32-
"LoyaltyManagementFlow",
33-
];
3448

35-
public static allTypes = function () {
49+
public static readonly allTypes = function () {
3650
return [...this.backEndTypes, ...this.visualTypes, ...this.surveyTypes];
3751
};
3852
}

src/main/models/RuleInfo.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,60 @@
1+
export type RuleDefinitionExpression = {
2+
options?: {
3+
expression?: unknown;
4+
};
5+
};
6+
7+
/**
8+
* Represents a rule metadata; this contains properties to describe the rule
9+
*/
110
export class RuleInfo {
11+
/**
12+
* Indicates whether the rule can be automatically fixed.
13+
* When the rule is autofixable, implement @see {AutoFixable}
14+
*/
215
public autoFixable: boolean;
16+
17+
/**
18+
* A human-readable description of the rule.
19+
*/
320
public description: string;
21+
22+
/**
23+
* An array of documentation references related to the rule.
24+
*/
425
public docRefs: Array<{ label: string; path: string }>;
26+
27+
/**
28+
* Specifies if the rule's behavior can be configured.
29+
* When configurable, execute should take in a second parameter @see RuleDefinitionExpression
30+
* @example
31+
* ```typescript
32+
* public execute(flow: core.Flow, options?: { expression: string }): core.RuleResult {
33+
* // your rule
34+
* }
35+
*/
536
public isConfigurable: boolean;
37+
38+
/**
39+
* The display label for the rule.
40+
* This property is being displayed on sf cli and on vsce
41+
*/
642
public label: string;
43+
44+
/**
45+
* The unique name identifier for the rule.
46+
*/
747
public name: string;
48+
49+
/**
50+
* The types supported by this rule (e.g., Flow, Process).
51+
* Use defined types in @see FlowType
52+
*/
853
public supportedTypes: string[];
54+
55+
/**
56+
* (Optional) The element that can be used to suppress this rule.
57+
* @see AdvancedSuppression
58+
*/
959
public suppressionElement?: string;
1060
}

0 commit comments

Comments
 (0)