Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.0.8 #14

Merged
merged 7 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"source.fixAll.eslint": "explicit"
},
"cSpell.words": [
"subflow",
"subflows",
"unconfigured"
]
}
13 changes: 10 additions & 3 deletions docs/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "@ping-identity/dvlint-base-rule-pack",
"description": "Collection of base rules used to lint DaVinci flows.",
"version": "1.0.7",
"version": "1.0.8",
"rules": [
{
"id": "dv-rule-annotations-001",
Expand Down Expand Up @@ -178,15 +178,15 @@
"dv-er-node-001": {
"description": "Disabled Node Found",
"message": "Disabled node % found",
"type": "best-practice",
"type": "error",
"recommendation": "A disabled '%' node has been found. Consider removing it from the flow.",
"code": "dv-er-node-001"
},
"dv-er-node-002": {
"description": "Connector Capability not configured",
"message": "Connector Capability not configured",
"type": "error",
"recommendation": "Configure a capability in <%> connector to ensure proper operation.",
"recommendation": "Configure a capability in '%' to ensure proper operation.",
"code": "dv-er-node-002"
}
},
Expand Down Expand Up @@ -276,6 +276,13 @@
"type": "error",
"recommendation": "The '%' variable is not defined within a variable connector, which may lead to unexpected behavior. Define the variable appropriately.",
"code": "dv-er-variable-002"
},
"dv-er-variable-003": {
"description": "Referenced node in variable doesn't exist",
"message": "Referenced node in local variable doesn't exist",
"type": "error",
"recommendation": "The local variable(s) - '%' contains a node id which doesn't exist within the flow",
"code": "dv-er-variable-003"
}
},
"reference": "",
Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ping-identity/dvlint-base-rule-pack",
"version": "1.0.7",
"version": "1.0.8",
"description": "Collection of base rules used to lint DaVinci flows.",
"main": "RulePack.js",
"scripts": {
Expand Down Expand Up @@ -35,6 +35,6 @@
"prettier": "^2.7.1"
},
"dependencies": {
"@ping-identity/dvlint": "^1.0.3"
"@ping-identity/dvlint": "^1.0.4"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"errors": [
{
"code": "dv-bp-annotation-001",
"flowId": "d493071599c7996c28591f29b3578f2e",
"message": "Annotation color is not in palette [#3030aeff] (4pmrtt0pi7)",
"type": "best-practice",
"recommendation": "The annotation color is not part of the recommended palette. To ensure optimal results, use the suggested colors.",
"nodeId": "4pmrtt0pi7"
},
{
"code": "dv-bp-missing-title-annotation-001",
"flowId": "d493071599c7996c28591f29b3578f2e",
"message": "Each flow should contain a title annotation node with a background color of #4462ed",
"type": "best-practice",
"recommendation": "This flow is missing a title annotation node with a proper description. To improve flow organization, add a title annotation node and set the background color to #4462ed."
Expand All @@ -38,13 +40,15 @@
"errors": [
{
"code": "dv-bp-annotation-001",
"flowId": "d493071599c7996c28591f29b3578f2e",
"message": "Annotation color is not in palette [#3030aeff] (4pmrtt0pi7)",
"type": "best-practice",
"recommendation": "The annotation color is not part of the recommended palette. To ensure optimal results, use the suggested colors.",
"nodeId": "4pmrtt0pi7"
},
{
"code": "dv-bp-missing-title-annotation-001",
"flowId": "d493071599c7996c28591f29b3578f2e",
"message": "Each flow should contain a title annotation node with a background color of #4462ed",
"type": "best-practice",
"recommendation": "This flow is missing a title annotation node with a proper description. To improve flow organization, add a title annotation node and set the background color to #4462ed."
Expand Down
2 changes: 2 additions & 0 deletions rules/dv-rule-empty-flow-001/tests/EmptyFlow.expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"errors": [
{
"code": "dv-er-empty-flow-001",
"flowId": "f00277aa69f1e332c262eea5e8ae2663",
"message": "Flow is empty",
"type": "error",
"recommendation": "An empty flow has been found. If it's not being used, remove it."
Expand All @@ -32,6 +33,7 @@
"errors": [
{
"code": "dv-er-empty-flow-001",
"flowId": "f00277aa69f1e332c262eea5e8ae2663",
"message": "Flow is empty",
"type": "error",
"recommendation": "An empty flow has been found. If it's not being used, remove it."
Expand Down
1 change: 1 addition & 0 deletions rules/dv-rule-node-001/NodeRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class NodeRule extends LintRule {
if (
data.nodeType === "CONNECTION" &&
data.connectorId === "pingOneFormsConnector" &&
data.capabilityName === "customForm" &&
!data.properties?.form?.value
) {
this.addError("dv-er-node-004", {
Expand Down
7 changes: 4 additions & 3 deletions rules/dv-rule-node-002/DisabledNodeRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ class DisabledNodeRule extends LintRule {
this.addCode("dv-er-node-001", {
description: "Disabled Node Found",
message: "Disabled node % found",
type: "best-practice",
type: "error",
recommendation: "A disabled '%' node has been found. Consider removing it from the flow.",
});
this.addCode("dv-er-node-002", {
description: "Connector Capability not configured",
message: "Connector Capability not configured",
type: "error",
recommendation: "Configure a capability in <%> connector to ensure proper operation.",
recommendation: "Configure a capability in '%' to ensure proper operation.",
});

}
Expand All @@ -39,8 +39,9 @@ class DisabledNodeRule extends LintRule {
}

if (data.status === 'unconfigured') {
const connectorInstanceName = data.name.toLowerCase().includes('connector') ? data.name : data.name + ' connector';
this.addError("dv-er-node-002", {
recommendationArgs: [`${data.name}`],
recommendationArgs: [`${connectorInstanceName}`],
nodeId: data.id,
});
}
Expand Down
4 changes: 2 additions & 2 deletions rules/dv-rule-node-002/tests/DisabledNodeRule.expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{
"code": "dv-er-node-001",
"message": "Disabled node (v9172ugldd) found",
"type": "best-practice",
"type": "error",
"recommendation": "A disabled '(v9172ugldd)' node has been found. Consider removing it from the flow.",
"nodeId": "v9172ugldd"
}
Expand All @@ -34,7 +34,7 @@
{
"code": "dv-er-node-001",
"message": "Disabled node (v9172ugldd) found",
"type": "best-practice",
"type": "error",
"recommendation": "A disabled '(v9172ugldd)' node has been found. Consider removing it from the flow.",
"nodeId": "v9172ugldd"
}
Expand Down
7 changes: 6 additions & 1 deletion rules/dv-rule-subflow-001/SubflowRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,14 @@ class DVRule extends LintRule {
let subflowIdInputSchemaMap = {};
subflows?.forEach((subflow) => {
if (!subflow.name) {
this.addError("dv-er-subflow-001", { messageArgs: [subflow.flowId] });
this.addError("dv-er-subflow-001", {
flowId: subflow.flowId,
messageArgs: [subflow.flowId]
});
} else {
if (subflow.name !== subflow.label) {
this.addError("dv-er-subflow-001", {
flowId: subflow.flowId,
messageArgs: [subflow.flowId],
recommendationArgs: [subflow.flowId],
});
Expand All @@ -69,6 +73,7 @@ class DVRule extends LintRule {
)
) {
this.addError("dv-er-subflow-002", {
flowId: subflow.flowId,
messageArgs: [subflow.name, targetFlow.name],
recommendationArgs: [subflow.name, targetFlow.name],
});
Expand Down
2 changes: 2 additions & 0 deletions rules/dv-rule-subflow-001/tests/SubflowRule1.expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"errorCount": 1,
"errors": [
{
"flowId": "6cc59b44515ba46f388c87ef52a00ec9",
"code": "dv-er-subflow-001",
"message": "Incorrect or Missing Subflow in (6cc59b44515ba46f388c87ef52a00ec9)",
"type": "error",
Expand All @@ -31,6 +32,7 @@
"errorCount": 1,
"errors": [
{
"flowId": "6cc59b44515ba46f388c87ef52a00ec9",
"code": "dv-er-subflow-001",
"message": "Incorrect or Missing Subflow in (6cc59b44515ba46f388c87ef52a00ec9)",
"type": "error",
Expand Down
2 changes: 2 additions & 0 deletions rules/dv-rule-subflow-001/tests/SubflowRule2.expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"errors": [
{
"code": "dv-er-subflow-002",
"flowId": "e33c447380e79c7f622953e0057080a8",
"message": "Circular SubFlow Dependency Found - 'TLS Main' points back to 'TLS Subflow' via subflow",
"type": "error",
"recommendation": "In this subflow, 'TLS Main' points back to 'TLS Subflow', which can cause import and export errors. Configure the subflow to return to the parent flow."
Expand All @@ -32,6 +33,7 @@
"errors": [
{
"code": "dv-er-subflow-002",
"flowId": "e33c447380e79c7f622953e0057080a8",
"message": "Circular SubFlow Dependency Found - 'TLS Main' points back to 'TLS Subflow' via subflow",
"type": "error",
"recommendation": "In this subflow, 'TLS Main' points back to 'TLS Subflow', which can cause import and export errors. Configure the subflow to return to the parent flow."
Expand Down
1 change: 1 addition & 0 deletions rules/dv-rule-subflow-001/tests/SubflowRule3.expect.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"errorCount": 1,
"errors": [
{
"flowId": "536d2240bb70b78137416562a87f1f81",
"code": "dv-er-subflow-003",
"message": "Input Schema values for 'subflow1' subflow is not configured.",
"type": "error",
Expand Down
52 changes: 52 additions & 0 deletions rules/dv-rule-variables-001/VariableRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ class DVRule extends LintRule {
recommendation:
"The '%' variable is not defined within a variable connector, which may lead to unexpected behavior. Define the variable appropriately.",
});

this.addCode("dv-er-variable-003", {
description: "Referenced node in variable doesn't exist",
message: "Referenced node in local variable doesn't exist",
type: "error",
recommendation: "The local variable(s) - '%' contains a node id which doesn't exist within the flow"
});
}

runRule() {
Expand Down Expand Up @@ -53,6 +60,51 @@ class DVRule extends LintRule {
this.addError("dv-er-variable-001", { messageArgs: [v.ref], recommendationArgs: [v.ref] });
}
});


// Logic to check if local variable nodeId is from the same flow
const targetFlow = this.mainFlow;
const mainFlowNodeIdArr = targetFlow?.graphData.elements?.nodes?.map(node => node.data.id);

targetFlow?.graphData?.elements?.nodes?.forEach((node) => {
let stringVal = JSON.stringify(node.data.properties) || '';

const pattern = /\{\{(.*?)\}\}/g; // regex pattern to match all instances of {{...}}
const matches = [...stringVal.matchAll(pattern)];
const localVarArray = matches.map(match => match[1]);
const uniqueLocalVariables = [...new Set(localVarArray)];

const nodeIdPattern = /\b[a-z0-9]{10}\b/g; // regx to pick nodeIds
let localVarNodeIdArr = []
uniqueLocalVariables.forEach(v => {
if (v.includes('local.')) {
const matchesNodeId = [...v.matchAll(nodeIdPattern)];
let nodeIds = matchesNodeId.map(match => match[0])
localVarNodeIdArr = [...localVarNodeIdArr, ...nodeIds];
}
})
const uniqueNodeIds = [...new Set(localVarNodeIdArr)];

let errorIdToShow = []
uniqueNodeIds.forEach(nodeId => {
if (!mainFlowNodeIdArr.includes(nodeId)) {
errorIdToShow.push(nodeId);
}
});

if (errorIdToShow.length > 0) {
const matchingFullStrings = uniqueLocalVariables.filter(fullString =>
errorIdToShow.some(substring => fullString.includes(substring))
);

this.addError("dv-er-variable-003", {
recommendationArgs: [matchingFullStrings.join(', '), node.data.id],
nodeId: node.data.id
});
}

});

} catch (err) {
this.addError(undefined, { messageArgs: [`${err}`] });
}
Expand Down
Loading
Loading