-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeel.js
86 lines (66 loc) · 2.08 KB
/
feel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const { isString } = require('min-dash');
const {
is,
isAny
} = require('bpmnlint-utils');
const { lintExpression } = require('@bpmn-io/feel-lint');
const { getPath } = require('@bpmn-io/moddle-utils');
const { reportErrors } = require('../utils/reporter');
const { ERROR_TYPES } = require('../utils/error-types');
const { skipInNonExecutableProcess } = require('../utils/rule');
module.exports = skipInNonExecutableProcess(function() {
function check(node, reporter) {
if (is(node, 'bpmn:Expression')) {
return;
}
const parentNode = findParentNode(node);
if (!parentNode) {
return;
}
const errors = [];
Object.entries(node).forEach(([ propertyName, propertyValue ]) => {
if (propertyValue && is(propertyValue, 'bpmn:Expression')) {
propertyValue = propertyValue.get('body');
}
if (isFeelProperty([ propertyName, propertyValue ])) {
const lintErrors = lintExpression(propertyValue.substring(1));
// syntax error
if (lintErrors.find(({ type }) => type === 'Syntax Error')) {
const path = getPath(node, parentNode);
errors.push(
{
message: `Property <${ propertyName }> is not a valid FEEL expression`,
path: path
? [ ...path, propertyName ]
: [ propertyName ],
data: {
type: ERROR_TYPES.FEEL_EXPRESSION_INVALID,
node,
parentNode,
property: propertyName
}
}
);
}
}
});
if (errors && errors.length) {
reportErrors(parentNode, reporter, errors);
}
}
return {
check
};
});
const isFeelProperty = ([ propertyName, value ]) => {
return !isIgnoredProperty(propertyName) && isString(value) && value.startsWith('=');
};
const isIgnoredProperty = propertyName => {
return propertyName.startsWith('$');
};
const findParentNode = node => {
while (node && !isAny(node, [ 'bpmn:FlowElement', 'bpmn:FlowElementsContainer' ])) {
node = node.$parent;
}
return node;
};