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

feat(rules): add feel linting rule #51

Merged
merged 4 commits into from
Oct 26, 2022
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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const camundaCloud10Rules = {
'no-zeebe-properties': 'error',
'subscription': 'error',
'timer': [ 'error', timerConfig.camundaCloud10 ],
'user-task-form': 'error'
'user-task-form': 'error',
'feel': 'error'
};

const camundaCloud11Rules = {
Expand Down
155 changes: 155 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"zeebe-bpmn-moddle": "^0.14.0"
},
"dependencies": {
"@bpmn-io/feel-lint": "^0.1.0",
"@bpmn-io/moddle-utils": "^0.1.0",
"bpmnlint-utils": "^1.0.2",
"min-dash": "^3.8.1"
Expand Down
66 changes: 66 additions & 0 deletions rules/feel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const { is } = require('bpmnlint-utils');
const { lintExpression } = require('@bpmn-io/feel-lint');

const { reportErrors } = require('./utils/reporter');
const { getPath } = require('@bpmn-io/moddle-utils');
const { ERROR_TYPES } = require('./utils/error-types');

module.exports = function() {
function check(node, reporter) {

const parentNode = findFlowElement(node);
const errors = [];

if (!parentNode) {
return;
}
Comment on lines +14 to +16
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should never happen, but it does: bpmn-io/bpmn-js#1754

Better be safe than blow up 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤡


Object.entries(node).forEach(([ propertyName, value ]) => {
if (isFeelValue([ propertyName, value ])) {
const lintErrors = lintExpression(value.substring(1));

// syntax error
if (lintErrors.find(({ type }) => type === 'syntaxError')) {
const path = getPath(node, parentNode);

errors.push(
{
message: `Property <${ propertyName }> is not valid FEEL expression`,
path: path
? [ ...path, propertyName ]
: [ propertyName ],
error: {
type: ERROR_TYPES.FEEL_INVALID,
node: node,
parentNode,
property: propertyName
}
}
);
}
}
});

errors.length && reportErrors(parentNode, reporter, errors);
}

return {
check
};
};

const isFeelValue = ([ key, value ]) => {
return shouldCheck(key) && typeof value === 'string' && value.startsWith('=');
};

const shouldCheck = key => {
return !key.startsWith('$');
};

const findFlowElement = node => {
while (node && !is(node, 'bpmn:FlowElement')) {
node = node.$parent;
}

return node;
};
1 change: 1 addition & 0 deletions rules/utils/error-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports.ERROR_TYPES = Object.freeze({
PROPERTY_TYPE_NOT_ALLOWED: 'propertyTypeNotAllowed',
PROPERTY_VALUE_DUPLICATED: 'propertyValueDuplicated',
PROPERTY_VALUE_NOT_ALLOWED: 'propertyValueNotAllowed',
FEEL_INVALID: 'feelInvalid'
});
Loading