Lightning-Flow-Scanner / lightning-flow-scanner-core

A rule engine capable of conducting static analysis on the metadata associated with Salesforce Lightning Flows, Process Builders, and Workflows.
https://www.npmjs.com/package/lightning-flow-scanner-core
MIT License
27 stars 9 forks source link

Feature: Custom Rules #37

Closed SFDX-Sam closed 7 months ago

SFDX-Sam commented 1 year ago

Problem:

We have internal rules around flow naming conventions - e.g: all record triggered flows must contain context and object:

"Account - Before Save - Update Account Name"

While we can currently pass a custom regex expression into the "FlowName" rule in the config file, there is no way to control the output of a failure, currently we get a generic message.

Solution:

Add a "description" option for rules like the following, to allow us to override the default description defined in the RuleInfo file.

    {
      "rules": {
        "FlowName" : {
          "severity":"error",
          "expression": "custom regex here",
          "description": "You flow must match the format Object - Context - Action, see help article at https://example.com"
        }
      }
    }
RubenHalman commented 1 year ago

@SFDX-Sam Thank you very much for the feedback and suggestion. I will add this to the project and backlog, but I am wondering how many rules you would really implement custom descriptions with? In some sense this seems perhaps rule specific rather than a generic requirement. If that were the case it might make more sense to implement a quick fix for this rule and focus on enabling a user to implement their own rules altogether and just deactivate the default ones.

SFDX-Sam commented 1 year ago

@RubenHalman I think we'd want to do it for all rules, it'd be helpful if we could link every violation to the relevant piece of our internal documentation / flow standards documentation and training materials so that users could get notified, fix, and then retry without having to reach out to a senior team member.

We have 30+ consultants of varying skill all working on flows, so the ultimate vision would be them to be able to build independently, commit to the pipeline and have the flow scanner catch their common / easy mistakes and link them to our documents to help them fix without having to trawl through pages of docs.

RubenHalman commented 1 year ago

Thank you for elaborating @SFDX-Sam . I think what I have in mind will work. What I am saying is, that if you are able pass a fully custom rule like so:

''' {
  "rules": {
    "FlowName" : {
      "ruledefinition":, "src/customrules/FlowName.js"
    }
  }
} '''

This makes it possible for you to essentially create custom versions of the default rule that would also include your own documentation(you just copy paste the file and would give it a new name and description attribute value). You can then provide your team the custom rules paired with instructions on setting up the .flow-scanner configuration file. The VS Code Extension also aims to make configuring easier. Does this also sound like a solution to you?

RubenHalman commented 7 months ago

@SFDX-Sam With 2.30 we now have an initial version to load custom rules. Let us know your thoughts if you ever get to using it!