Skip to content

Commit

Permalink
Update customruleguide.md
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenHalman authored Mar 20, 2024
1 parent e001e76 commit 52a01ea
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions docs/customruleguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,45 @@
A custom rule class typically follows this structure:

```typescript
const core = await import('https://Lightning-Flow-Scanner.github.io/lightning-flow-scanner-core/types.d.ts');
// Import necessary types and classes from the local core repository
import { Flow, FlowAttribute, FlowType, IRuleDefinition, ResultDetails, RuleResult } from './lightning-flow-scanner-core/src/index';

export class CustomRule extends core.IRuleDefinition {
execute(flow: core.Flow, ruleOptions?: {}): core.RuleResult {
// Implement rule logic here
}
export class CustomNamingConvention implements IRuleDefinition{

name: string;
label: string;
description: string;
type:string;
supportedTypes:string[];
isConfigurable: boolean;
docRefs: any;

constructor(){
this.name = 'CustomNamingConvention';
this.label = 'Custom Naming Convention';
this.description='custom execute function ';
this.type = 'flow';
this.supportedTypes = FlowType.allTypes();
isConfigurable: true;
}

// Create custom execute logic
public execute(flow: Flow, options?: { expression: string }): RuleResult {

const conventionApplied = (flow.name)?.startsWith('AcmeCorp_]');
return (!conventionApplied ?
new RuleResult(this, [new ResultDetails(new FlowAttribute(flow.name, 'name', 'The Name needs to start with AcmeCorp_'))]) :
new RuleResult(this, []));
}
}

```

In this example, a dynamic import is utilized to import types from our GitHub Pages, but you can also import the types from a local version of the core repo. The execute method within the CustomRule class can implement any logic while having access to the flow being analyzed and the user-provided configurations.
In this code:
- We're importing necessary types and classes from the local core repository using a relative path (./lightning-flow-scanner-core/src/index). Make sure to adjust the path according to your local Core Module.
- We're defining the CustomNamingConvention class, implementing the IRuleDefinition interface.
- We're setting up the class properties such as name, label, description, etc., as per your provided example.
- We're implementing the execute method, which performs the custom logic for your rule. This method takes a Flow object as input and returns a RuleResult.

## Custom Rule Interface

Expand Down Expand Up @@ -42,4 +71,4 @@ The Flow Compiler is a powerful tool provided by the Lightning Flow Scanner Core
The Compiler class consists of methods designed to traverse flow elements effectively:
- Constructor: The constructor initializes the visitedElements set, which keeps track of visited elements during traversal.
- traverseFlow Method: This method implements the Iterative Deepening Depth-First Search (IDDFS) algorithm for traversing flow elements. It iteratively explores each element, starting from a specified starting point, and visits each element by calling the provided callback function. The traversal continues until all elements are visited or until a specified end point is reached.
- findNextElements Method: This private method is used internally by the traverseFlow method to find the next elements to visit based on the connectors of the current element. It examines the connectors of the current element and identifies the next elements to traverse.
- findNextElements Method: This private method is used internally by the traverseFlow method to find the next elements to visit based on the connectors of the current element. It examines the connectors of the current element and identifies the next elements to traverse.

0 comments on commit 52a01ea

Please sign in to comment.