@flow-scanner/lightning-flow-scanner-core 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONTRIBUTING.md +30 -0
- package/LICENSE.md +21 -0
- package/README.md +314 -0
- package/SECURITY.md +26 -0
- package/assets/media/bannerslim.png +0 -0
- package/index.d.ts +21 -0
- package/index.js +83 -0
- package/main/interfaces/AdvancedRuleConfig.d.ts +11 -0
- package/main/interfaces/AdvancedRuleConfig.js +4 -0
- package/main/interfaces/AdvancedRuleDefintion.d.ts +5 -0
- package/main/interfaces/AdvancedRuleDefintion.js +4 -0
- package/main/interfaces/AdvancedSuppression.d.ts +21 -0
- package/main/interfaces/AdvancedSuppression.js +4 -0
- package/main/interfaces/AutoFixable.d.ts +10 -0
- package/main/interfaces/AutoFixable.js +4 -0
- package/main/interfaces/IExceptions.d.ts +5 -0
- package/main/interfaces/IExceptions.js +4 -0
- package/main/interfaces/IRuleConfig.d.ts +3 -0
- package/main/interfaces/IRuleConfig.js +4 -0
- package/main/interfaces/IRuleDefinition.d.ts +17 -0
- package/main/interfaces/IRuleDefinition.js +4 -0
- package/main/interfaces/IRuleOptions.d.ts +4 -0
- package/main/interfaces/IRuleOptions.js +4 -0
- package/main/interfaces/IRulesConfig.d.ts +8 -0
- package/main/interfaces/IRulesConfig.js +4 -0
- package/main/internals/internals.d.ts +17 -0
- package/main/internals/internals.js +64 -0
- package/main/libs/BuildFlow.d.ts +1 -0
- package/main/libs/BuildFlow.js +20 -0
- package/main/libs/Compiler.d.ts +8 -0
- package/main/libs/Compiler.js +70 -0
- package/main/libs/ConvertFlowNodes.d.ts +1 -0
- package/main/libs/ConvertFlowNodes.js +14 -0
- package/main/libs/DynamicRule.d.ts +5 -0
- package/main/libs/DynamicRule.js +19 -0
- package/main/libs/FixFlows.d.ts +3 -0
- package/main/libs/FixFlows.js +110 -0
- package/main/libs/GetRuleDefinitions.d.ts +5 -0
- package/main/libs/GetRuleDefinitions.js +81 -0
- package/main/libs/ParseFlows.d.ts +2 -0
- package/main/libs/ParseFlows.js +111 -0
- package/main/libs/Scan2.d.ts +3 -0
- package/main/libs/Scan2.js +124 -0
- package/main/libs/ScanFlows.d.ts +4 -0
- package/main/libs/ScanFlows.js +103 -0
- package/main/models/AdvancedRule.d.ts +44 -0
- package/main/models/AdvancedRule.js +84 -0
- package/main/models/Flow.d.ts +33 -0
- package/main/models/Flow.js +277 -0
- package/main/models/FlowAttribute.d.ts +7 -0
- package/main/models/FlowAttribute.js +34 -0
- package/main/models/FlowElement.d.ts +10 -0
- package/main/models/FlowElement.js +37 -0
- package/main/models/FlowElementConnector.d.ts +15 -0
- package/main/models/FlowElementConnector.js +50 -0
- package/main/models/FlowMetadata.d.ts +4 -0
- package/main/models/FlowMetadata.js +16 -0
- package/main/models/FlowNode.d.ts +10 -0
- package/main/models/FlowNode.js +169 -0
- package/main/models/FlowResource.d.ts +5 -0
- package/main/models/FlowResource.js +30 -0
- package/main/models/FlowType.d.ts +23 -0
- package/main/models/FlowType.js +80 -0
- package/main/models/FlowVariable.d.ts +6 -0
- package/main/models/FlowVariable.js +31 -0
- package/main/models/LoopRuleCommon.d.ts +9 -0
- package/main/models/LoopRuleCommon.js +48 -0
- package/main/models/ParsedFlow.d.ts +7 -0
- package/main/models/ParsedFlow.js +35 -0
- package/main/models/ResultDetails.d.ts +10 -0
- package/main/models/ResultDetails.js +57 -0
- package/main/models/RuleCommon.d.ts +19 -0
- package/main/models/RuleCommon.js +48 -0
- package/main/models/RuleInfo.d.ts +55 -0
- package/main/models/RuleInfo.js +61 -0
- package/main/models/RuleResult.d.ts +11 -0
- package/main/models/RuleResult.js +44 -0
- package/main/models/ScanResult.d.ts +7 -0
- package/main/models/ScanResult.js +31 -0
- package/main/rules/APIVersion.d.ts +8 -0
- package/main/rules/APIVersion.js +86 -0
- package/main/rules/ActionCallsInLoop.d.ts +6 -0
- package/main/rules/ActionCallsInLoop.js +38 -0
- package/main/rules/AutoLayout.d.ts +8 -0
- package/main/rules/AutoLayout.js +78 -0
- package/main/rules/CopyAPIName.d.ts +6 -0
- package/main/rules/CopyAPIName.js +82 -0
- package/main/rules/CyclomaticComplexity.d.ts +10 -0
- package/main/rules/CyclomaticComplexity.js +111 -0
- package/main/rules/DMLStatementInLoop.d.ts +6 -0
- package/main/rules/DMLStatementInLoop.js +37 -0
- package/main/rules/DuplicateDMLOperation.d.ts +8 -0
- package/main/rules/DuplicateDMLOperation.js +153 -0
- package/main/rules/FlowDescription.d.ts +6 -0
- package/main/rules/FlowDescription.js +76 -0
- package/main/rules/FlowName.d.ts +7 -0
- package/main/rules/FlowName.js +80 -0
- package/main/rules/GetRecordAllFields.d.ts +6 -0
- package/main/rules/GetRecordAllFields.js +101 -0
- package/main/rules/HardcodedId.d.ts +6 -0
- package/main/rules/HardcodedId.js +87 -0
- package/main/rules/HardcodedUrl.d.ts +6 -0
- package/main/rules/HardcodedUrl.js +50 -0
- package/main/rules/InactiveFlow.d.ts +6 -0
- package/main/rules/InactiveFlow.js +73 -0
- package/main/rules/MissingFaultPath.d.ts +12 -0
- package/main/rules/MissingFaultPath.js +161 -0
- package/main/rules/MissingNullHandler.d.ts +6 -0
- package/main/rules/MissingNullHandler.js +152 -0
- package/main/rules/ProcessBuilder.d.ts +8 -0
- package/main/rules/ProcessBuilder.js +77 -0
- package/main/rules/RecursiveAfterUpdate.d.ts +7 -0
- package/main/rules/RecursiveAfterUpdate.js +124 -0
- package/main/rules/SOQLQueryInLoop.d.ts +6 -0
- package/main/rules/SOQLQueryInLoop.js +35 -0
- package/main/rules/SameRecordFieldUpdates.d.ts +7 -0
- package/main/rules/SameRecordFieldUpdates.js +111 -0
- package/main/rules/TriggerOrder.d.ts +7 -0
- package/main/rules/TriggerOrder.js +101 -0
- package/main/rules/UnconnectedElement.d.ts +7 -0
- package/main/rules/UnconnectedElement.js +93 -0
- package/main/rules/UnsafeRunningContext.d.ts +6 -0
- package/main/rules/UnsafeRunningContext.js +86 -0
- package/main/rules/UnusedVariable.d.ts +6 -0
- package/main/rules/UnusedVariable.js +100 -0
- package/main/store/DefaultRuleStore.d.ts +2 -0
- package/main/store/DefaultRuleStore.js +68 -0
- package/package.json +88 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IRuleDefinition } from "../interfaces/IRuleDefinition";
|
|
2
|
+
import type { IRulesConfig } from "../interfaces/IRulesConfig";
|
|
3
|
+
import { Compiler } from "../libs/Compiler";
|
|
4
|
+
import { Flow } from "../models/Flow";
|
|
5
|
+
import { FlowAttribute } from "../models/FlowAttribute";
|
|
6
|
+
import { FlowElement } from "../models/FlowElement";
|
|
7
|
+
import { FlowType } from "../models/FlowType";
|
|
8
|
+
import { FlowNode } from "../models/FlowNode";
|
|
9
|
+
import { FlowResource } from "../models/FlowResource";
|
|
10
|
+
import { FlowVariable } from "../models/FlowVariable";
|
|
11
|
+
import { ResultDetails } from "../models/ResultDetails";
|
|
12
|
+
import { RuleResult } from "../models/RuleResult";
|
|
13
|
+
import { ScanResult } from "../models/ScanResult";
|
|
14
|
+
import { RuleCommon } from "../models/RuleCommon";
|
|
15
|
+
import { ParsedFlow } from "../models/ParsedFlow";
|
|
16
|
+
export { FlowAttribute, FlowElement, FlowNode, FlowType, FlowVariable, FlowResource, Flow, Compiler, ScanResult, RuleResult, ResultDetails, RuleCommon, ParsedFlow, };
|
|
17
|
+
export type { IRuleDefinition, IRulesConfig };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get Compiler () {
|
|
13
|
+
return _Compiler.Compiler;
|
|
14
|
+
},
|
|
15
|
+
get Flow () {
|
|
16
|
+
return _Flow.Flow;
|
|
17
|
+
},
|
|
18
|
+
get FlowAttribute () {
|
|
19
|
+
return _FlowAttribute.FlowAttribute;
|
|
20
|
+
},
|
|
21
|
+
get FlowElement () {
|
|
22
|
+
return _FlowElement.FlowElement;
|
|
23
|
+
},
|
|
24
|
+
get FlowNode () {
|
|
25
|
+
return _FlowNode.FlowNode;
|
|
26
|
+
},
|
|
27
|
+
get FlowResource () {
|
|
28
|
+
return _FlowResource.FlowResource;
|
|
29
|
+
},
|
|
30
|
+
get FlowType () {
|
|
31
|
+
return _FlowType.FlowType;
|
|
32
|
+
},
|
|
33
|
+
get FlowVariable () {
|
|
34
|
+
return _FlowVariable.FlowVariable;
|
|
35
|
+
},
|
|
36
|
+
get ParsedFlow () {
|
|
37
|
+
return _ParsedFlow.ParsedFlow;
|
|
38
|
+
},
|
|
39
|
+
get ResultDetails () {
|
|
40
|
+
return _ResultDetails.ResultDetails;
|
|
41
|
+
},
|
|
42
|
+
get RuleCommon () {
|
|
43
|
+
return _RuleCommon.RuleCommon;
|
|
44
|
+
},
|
|
45
|
+
get RuleResult () {
|
|
46
|
+
return _RuleResult.RuleResult;
|
|
47
|
+
},
|
|
48
|
+
get ScanResult () {
|
|
49
|
+
return _ScanResult.ScanResult;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const _Compiler = require("../libs/Compiler");
|
|
53
|
+
const _Flow = require("../models/Flow");
|
|
54
|
+
const _FlowAttribute = require("../models/FlowAttribute");
|
|
55
|
+
const _FlowElement = require("../models/FlowElement");
|
|
56
|
+
const _FlowType = require("../models/FlowType");
|
|
57
|
+
const _FlowNode = require("../models/FlowNode");
|
|
58
|
+
const _FlowResource = require("../models/FlowResource");
|
|
59
|
+
const _FlowVariable = require("../models/FlowVariable");
|
|
60
|
+
const _ResultDetails = require("../models/ResultDetails");
|
|
61
|
+
const _RuleResult = require("../models/RuleResult");
|
|
62
|
+
const _ScanResult = require("../models/ScanResult");
|
|
63
|
+
const _RuleCommon = require("../models/RuleCommon");
|
|
64
|
+
const _ParsedFlow = require("../models/ParsedFlow");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function BuildFlow(nodesToMerge: any): {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "BuildFlow", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return BuildFlow;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _ConvertFlowNodes = require("./ConvertFlowNodes");
|
|
12
|
+
function BuildFlow(nodesToMerge) {
|
|
13
|
+
let res = {};
|
|
14
|
+
for (const nodeToMerge of nodesToMerge){
|
|
15
|
+
const subtype = nodeToMerge.subtype;
|
|
16
|
+
const nodesOfType = nodesToMerge.filter((node)=>subtype === node.subtype);
|
|
17
|
+
res = (0, _ConvertFlowNodes.convertFlowNodes)(res, nodesOfType, subtype);
|
|
18
|
+
}
|
|
19
|
+
return res;
|
|
20
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Flow } from "../models/Flow";
|
|
2
|
+
import { FlowNode } from "../models/FlowNode";
|
|
3
|
+
export declare class Compiler {
|
|
4
|
+
visitedElements: Set<string>;
|
|
5
|
+
constructor();
|
|
6
|
+
traverseFlow(flow: Flow, startElementName: string, visitCallback: (element: FlowNode) => void, endElementName?: string): void;
|
|
7
|
+
private findNextElements;
|
|
8
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "Compiler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return Compiler;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function _define_property(obj, key, value) {
|
|
12
|
+
if (key in obj) {
|
|
13
|
+
Object.defineProperty(obj, key, {
|
|
14
|
+
value: value,
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true
|
|
18
|
+
});
|
|
19
|
+
} else {
|
|
20
|
+
obj[key] = value;
|
|
21
|
+
}
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
let Compiler = class Compiler {
|
|
25
|
+
traverseFlow(flow, startElementName, visitCallback, endElementName) {
|
|
26
|
+
// Iterative Deepening Depth-First Search (IDDFS)
|
|
27
|
+
let elementsToVisit = [
|
|
28
|
+
startElementName
|
|
29
|
+
];
|
|
30
|
+
while(elementsToVisit.length > 0){
|
|
31
|
+
const nextElements = [];
|
|
32
|
+
for (const elementName of elementsToVisit){
|
|
33
|
+
if (!this.visitedElements.has(elementName)) {
|
|
34
|
+
var _flow_elements;
|
|
35
|
+
const currentElement = (_flow_elements = flow.elements) === null || _flow_elements === void 0 ? void 0 : _flow_elements.find((element)=>element.name === elementName);
|
|
36
|
+
if (currentElement) {
|
|
37
|
+
visitCallback(currentElement);
|
|
38
|
+
this.visitedElements.add(elementName);
|
|
39
|
+
nextElements.push(...this.findNextElements(flow, currentElement, endElementName));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (nextElements.length === 0) {
|
|
44
|
+
break; // Terminate the traversal
|
|
45
|
+
}
|
|
46
|
+
elementsToVisit = nextElements;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
findNextElements(flow, currentElement, endElementName) {
|
|
50
|
+
const nextElements = [];
|
|
51
|
+
if (!currentElement.connectors || currentElement.connectors.length === 0) {
|
|
52
|
+
return nextElements;
|
|
53
|
+
}
|
|
54
|
+
for (const connector of currentElement.connectors){
|
|
55
|
+
var _connector_connectorTargetReference, _flow_elements;
|
|
56
|
+
var _connector_connectorTargetReference_targetReference;
|
|
57
|
+
const targetReference = (_connector_connectorTargetReference_targetReference = connector === null || connector === void 0 ? void 0 : (_connector_connectorTargetReference = connector.connectorTargetReference) === null || _connector_connectorTargetReference === void 0 ? void 0 : _connector_connectorTargetReference.targetReference) !== null && _connector_connectorTargetReference_targetReference !== void 0 ? _connector_connectorTargetReference_targetReference : connector.reference;
|
|
58
|
+
// Check if the reference exists in the flow elements
|
|
59
|
+
const nextElement = (_flow_elements = flow.elements) === null || _flow_elements === void 0 ? void 0 : _flow_elements.find((element)=>element.metaType === "node" && element.name === targetReference);
|
|
60
|
+
if (nextElement && nextElement.metaType === "node" && nextElement.name !== endElementName) {
|
|
61
|
+
nextElements.push(nextElement.name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return nextElements;
|
|
65
|
+
}
|
|
66
|
+
constructor(){
|
|
67
|
+
_define_property(this, "visitedElements", void 0);
|
|
68
|
+
this.visitedElements = new Set();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function convertFlowNodes(obj: any, nodes: any, key: any): any;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "convertFlowNodes", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return convertFlowNodes;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
function convertFlowNodes(obj, nodes, key) {
|
|
12
|
+
obj[key] = nodes.map((node)=>node.element);
|
|
13
|
+
return obj;
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "DynamicRule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return DynamicRule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _DefaultRuleStore = require("../store/DefaultRuleStore");
|
|
12
|
+
let DynamicRule = class DynamicRule {
|
|
13
|
+
constructor(className){
|
|
14
|
+
if (!_DefaultRuleStore.DefaultRuleStore.hasOwnProperty(className) && _DefaultRuleStore.BetaRuleStore.hasOwnProperty(className)) {
|
|
15
|
+
return new _DefaultRuleStore.BetaRuleStore[className]();
|
|
16
|
+
}
|
|
17
|
+
return new _DefaultRuleStore.DefaultRuleStore[className]();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get FixFlows () {
|
|
13
|
+
return FixFlows;
|
|
14
|
+
},
|
|
15
|
+
get fix () {
|
|
16
|
+
return fix;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _BuildFlow = require("./BuildFlow");
|
|
20
|
+
const _internals = /*#__PURE__*/ _interop_require_wildcard(require("../internals/internals"));
|
|
21
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
22
|
+
if (typeof WeakMap !== "function") return null;
|
|
23
|
+
var cacheBabelInterop = new WeakMap();
|
|
24
|
+
var cacheNodeInterop = new WeakMap();
|
|
25
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
26
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
27
|
+
})(nodeInterop);
|
|
28
|
+
}
|
|
29
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
30
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
34
|
+
return {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
39
|
+
if (cache && cache.has(obj)) {
|
|
40
|
+
return cache.get(obj);
|
|
41
|
+
}
|
|
42
|
+
var newObj = {
|
|
43
|
+
__proto__: null
|
|
44
|
+
};
|
|
45
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
46
|
+
for(var key in obj){
|
|
47
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
48
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
49
|
+
if (desc && (desc.get || desc.set)) {
|
|
50
|
+
Object.defineProperty(newObj, key, desc);
|
|
51
|
+
} else {
|
|
52
|
+
newObj[key] = obj[key];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
newObj.default = obj;
|
|
57
|
+
if (cache) {
|
|
58
|
+
cache.set(obj, newObj);
|
|
59
|
+
}
|
|
60
|
+
return newObj;
|
|
61
|
+
}
|
|
62
|
+
function fix(results) {
|
|
63
|
+
const newResults = [];
|
|
64
|
+
for (const result of results){
|
|
65
|
+
if (result.ruleResults && result.ruleResults.length > 0) {
|
|
66
|
+
const fixables = result.ruleResults.filter((r)=>r.ruleName === "UnusedVariable" && r.occurs || r.ruleName === "UnconnectedElement" && r.occurs // TODO: this should be rule.occurs && rule.ruleDefinition.fixable
|
|
67
|
+
);
|
|
68
|
+
if ((fixables === null || fixables === void 0 ? void 0 : fixables.length) > 0) {
|
|
69
|
+
const newFlow = FixFlows(result.flow, fixables);
|
|
70
|
+
result.flow = newFlow;
|
|
71
|
+
newResults.push(result);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return newResults;
|
|
76
|
+
}
|
|
77
|
+
function FixFlows(flow, ruleResults) {
|
|
78
|
+
var _flow_elements;
|
|
79
|
+
// TODO: this should be defined on the rule
|
|
80
|
+
const unusedVariableRes = ruleResults.find((r)=>r.ruleName === "UnusedVariable");
|
|
81
|
+
const unusedVariableReferences = unusedVariableRes && unusedVariableRes.details && unusedVariableRes.details.length > 0 ? unusedVariableRes.details.map((d)=>d.name) : [];
|
|
82
|
+
const unconnectedElementsRes = ruleResults.find((r)=>r.ruleName === "UnconnectedElement");
|
|
83
|
+
const unconnectedElementsReferences = unconnectedElementsRes && unconnectedElementsRes.details && unconnectedElementsRes.details.length > 0 ? unconnectedElementsRes.details.map((d)=>d.name) : [];
|
|
84
|
+
const nodesToBuild = (_flow_elements = flow.elements) === null || _flow_elements === void 0 ? void 0 : _flow_elements.filter((node)=>{
|
|
85
|
+
switch(node.metaType){
|
|
86
|
+
case "variable":
|
|
87
|
+
{
|
|
88
|
+
const nodeVar = node;
|
|
89
|
+
if (!unusedVariableReferences.includes(nodeVar.name)) {
|
|
90
|
+
return node;
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case "node":
|
|
95
|
+
{
|
|
96
|
+
const nodeElement = node;
|
|
97
|
+
if (!unconnectedElementsReferences.includes(nodeElement.name)) {
|
|
98
|
+
return node;
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case "metadata":
|
|
103
|
+
case "resource":
|
|
104
|
+
return node;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
const xmldata = (0, _BuildFlow.BuildFlow)(nodesToBuild);
|
|
108
|
+
const newFlow = new _internals.Flow(flow.fsPath, xmldata);
|
|
109
|
+
return newFlow;
|
|
110
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { IRuleDefinition } from "../interfaces/IRuleDefinition";
|
|
2
|
+
import { IRulesConfig } from "../interfaces/IRulesConfig";
|
|
3
|
+
export declare function GetRuleDefinitions(ruleConfig?: Map<string, unknown>, options?: IRulesConfig): IRuleDefinition[];
|
|
4
|
+
export declare function getRules(ruleNames?: string[], options?: IRulesConfig): IRuleDefinition[];
|
|
5
|
+
export declare function getBetaRules(): IRuleDefinition[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get GetRuleDefinitions () {
|
|
13
|
+
return GetRuleDefinitions;
|
|
14
|
+
},
|
|
15
|
+
get getBetaRules () {
|
|
16
|
+
return getBetaRules;
|
|
17
|
+
},
|
|
18
|
+
get getRules () {
|
|
19
|
+
return getRules;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _DefaultRuleStore = require("../store/DefaultRuleStore");
|
|
23
|
+
const _DynamicRule = require("./DynamicRule");
|
|
24
|
+
function GetRuleDefinitions(ruleConfig, options) {
|
|
25
|
+
const selectedRules = [];
|
|
26
|
+
const includeBeta = (options === null || options === void 0 ? void 0 : options.betamode) === true;
|
|
27
|
+
if (ruleConfig && ruleConfig instanceof Map) {
|
|
28
|
+
for (const ruleName of ruleConfig.keys()){
|
|
29
|
+
let severity = "warning";
|
|
30
|
+
try {
|
|
31
|
+
var _ruleConfig_get;
|
|
32
|
+
const configuredSeverity = (_ruleConfig_get = ruleConfig.get(ruleName)) === null || _ruleConfig_get === void 0 ? void 0 : _ruleConfig_get["severity"];
|
|
33
|
+
if (configuredSeverity && (configuredSeverity === "error" || configuredSeverity === "warning" || configuredSeverity === "note")) {
|
|
34
|
+
severity = configuredSeverity;
|
|
35
|
+
}
|
|
36
|
+
const matchedRule = new _DynamicRule.DynamicRule(ruleName);
|
|
37
|
+
if (configuredSeverity) {
|
|
38
|
+
matchedRule.severity = severity;
|
|
39
|
+
}
|
|
40
|
+
selectedRules.push(matchedRule);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.log(error.message);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
// Load all defaults
|
|
47
|
+
for(const rule in _DefaultRuleStore.DefaultRuleStore){
|
|
48
|
+
const matchedRule = new _DynamicRule.DynamicRule(rule);
|
|
49
|
+
selectedRules.push(matchedRule);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// Append all beta rules if opted in (skip if already included via config/default)
|
|
53
|
+
if (includeBeta) {
|
|
54
|
+
for(const betaRuleName in _DefaultRuleStore.BetaRuleStore){
|
|
55
|
+
if (!selectedRules.some((r)=>r.name === betaRuleName)) {
|
|
56
|
+
const betaRule = new _DynamicRule.DynamicRule(betaRuleName);
|
|
57
|
+
selectedRules.push(betaRule);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return selectedRules;
|
|
62
|
+
}
|
|
63
|
+
function getRules(ruleNames, options) {
|
|
64
|
+
if (ruleNames && ruleNames.length > 0) {
|
|
65
|
+
const ruleSeverityMap = new Map(ruleNames.map((name)=>[
|
|
66
|
+
name,
|
|
67
|
+
{
|
|
68
|
+
severity: "error"
|
|
69
|
+
}
|
|
70
|
+
]));
|
|
71
|
+
return GetRuleDefinitions(ruleSeverityMap, options);
|
|
72
|
+
} else {
|
|
73
|
+
return GetRuleDefinitions(undefined, options);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function getBetaRules() {
|
|
77
|
+
return getBetaDefinition();
|
|
78
|
+
}
|
|
79
|
+
function getBetaDefinition() {
|
|
80
|
+
return Object.values(_DefaultRuleStore.BetaRuleStore).map((rule)=>new rule());
|
|
81
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "parse", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return parse;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fastxmlparser = require("fast-xml-parser");
|
|
12
|
+
const _fs = require("fs");
|
|
13
|
+
const _path = /*#__PURE__*/ _interop_require_wildcard(require("path"));
|
|
14
|
+
const _Flow = require("../models/Flow");
|
|
15
|
+
const _ParsedFlow = require("../models/ParsedFlow");
|
|
16
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
17
|
+
try {
|
|
18
|
+
var info = gen[key](arg);
|
|
19
|
+
var value = info.value;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
reject(error);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (info.done) {
|
|
25
|
+
resolve(value);
|
|
26
|
+
} else {
|
|
27
|
+
Promise.resolve(value).then(_next, _throw);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function _async_to_generator(fn) {
|
|
31
|
+
return function() {
|
|
32
|
+
var self = this, args = arguments;
|
|
33
|
+
return new Promise(function(resolve, reject) {
|
|
34
|
+
var gen = fn.apply(self, args);
|
|
35
|
+
function _next(value) {
|
|
36
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
37
|
+
}
|
|
38
|
+
function _throw(err) {
|
|
39
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
40
|
+
}
|
|
41
|
+
_next(undefined);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
46
|
+
if (typeof WeakMap !== "function") return null;
|
|
47
|
+
var cacheBabelInterop = new WeakMap();
|
|
48
|
+
var cacheNodeInterop = new WeakMap();
|
|
49
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
50
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
51
|
+
})(nodeInterop);
|
|
52
|
+
}
|
|
53
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
54
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
55
|
+
return obj;
|
|
56
|
+
}
|
|
57
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
58
|
+
return {
|
|
59
|
+
default: obj
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
63
|
+
if (cache && cache.has(obj)) {
|
|
64
|
+
return cache.get(obj);
|
|
65
|
+
}
|
|
66
|
+
var newObj = {
|
|
67
|
+
__proto__: null
|
|
68
|
+
};
|
|
69
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
70
|
+
for(var key in obj){
|
|
71
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
72
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
73
|
+
if (desc && (desc.get || desc.set)) {
|
|
74
|
+
Object.defineProperty(newObj, key, desc);
|
|
75
|
+
} else {
|
|
76
|
+
newObj[key] = obj[key];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
newObj.default = obj;
|
|
81
|
+
if (cache) {
|
|
82
|
+
cache.set(obj, newObj);
|
|
83
|
+
}
|
|
84
|
+
return newObj;
|
|
85
|
+
}
|
|
86
|
+
function parse(selectedUris) {
|
|
87
|
+
return _async_to_generator(function*() {
|
|
88
|
+
const parseResults = [];
|
|
89
|
+
const parser = new _fastxmlparser.XMLParser({
|
|
90
|
+
attributeNamePrefix: "@_",
|
|
91
|
+
ignoreAttributes: false,
|
|
92
|
+
// @ts-expect-error type issue
|
|
93
|
+
ignoreNameSpace: false,
|
|
94
|
+
parseTagValue: false,
|
|
95
|
+
textNodeName: "#text"
|
|
96
|
+
});
|
|
97
|
+
for (const uri of selectedUris){
|
|
98
|
+
try {
|
|
99
|
+
const normalizedURI = _path.normalize(uri);
|
|
100
|
+
const content = yield _fs.promises.readFile(normalizedURI, "utf8");
|
|
101
|
+
const parsed = parser.parse(content);
|
|
102
|
+
const flowObj = parsed.Flow;
|
|
103
|
+
parseResults.push(new _ParsedFlow.ParsedFlow(uri, new _Flow.Flow(uri, flowObj)));
|
|
104
|
+
} catch (e) {
|
|
105
|
+
var _e_message;
|
|
106
|
+
parseResults.push(new _ParsedFlow.ParsedFlow(uri, undefined, (_e_message = e.message) !== null && _e_message !== void 0 ? _e_message : e.toString()));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return parseResults;
|
|
110
|
+
})();
|
|
111
|
+
}
|