@ flow-scanner/ regex-scanner (英语)
一个通用的基于regex的元数据文件扫描引擎. 这个包提供了一个轻量级,可扩展的框架来检测元数据内容中的规律.
安装
npm install @flow-scanner/regex-scanner
使用量
import { scanRegex, MetadataFile } from "@flow-scanner/regex-scanner";
const file: MetadataFile = {
name: "My_Flow",
fileName: "My_Flow.flow-meta.xml",
metadataType: "Flow",
content: "<Flow>...</Flow>",
};
// Works with any Salesforce metadata type
const prompt: MetadataFile = {
name: "My_Prompt",
fileName: "My_Prompt.aiPromptTemplate-meta.xml",
metadataType: "AiPromptTemplate",
content: "<AiPromptTemplate>...</AiPromptTemplate>",
};
const violations = scanRegex([file]);
内部规则
所有内置规则默认适用于任何元数据类型.
| 规则ID | 说明 |
|---|---|
naming-convention | 校验符合可配置模式的文件名 |
hardcoded-id | 检测出硬码的销售力量记录 ID (15/18 char) |
hardcoded-url | 检测出硬码力量.com URL |
hardcoded-secret | 检测 API 密钥、 令牌和证书 |
配置
import { scanRegex, RegexScanConfig } from "@flow-scanner/regex-scanner";
const config: RegexScanConfig = {
rules: {
"naming-convention": {
enabled: true,
expression: "[A-Z][a-z]+_[A-Z][a-z]+", // Custom pattern
severity: "warning",
},
"hardcoded-id": {
enabled: false, // Disable this rule
},
},
};
const violations = scanRegex(files, config);
创建自定义规则
扩展 RegexRule 基准类 :
import { RegexRule, MetadataFile, RegexViolation } from "@flow-scanner/regex-scanner";
export class MyCustomRule extends RegexRule {
constructor() {
super({
ruleId: "my-custom-rule",
name: "MyCustomRule",
label: "My Custom Rule",
description: "Detects something specific",
summary: "Short summary",
severity: "warning",
supportedTypes: ["*"], // or specific types like ["Flow", "ApexClass"]
isConfigurable: false,
});
}
protected check(file: MetadataFile): RegexViolation[] {
const violations: RegexViolation[] = [];
// Your regex logic here
return violations;
}
}
API 密码
职能
scanRegex(files, config?)- 扫描多份文件,返回违规情况scanFile(file, config?)- 扫描一个文件getRegexRuleIds()- 获取所有可用的规则标识hasRegexRule(id)- 检查是否有规则
模型
MetadataFile- 输入文件说明RegexViolation- 输出违反地点信息RegexScanConfig- 扫描行为配置RegexRule- 规则基础课