Custom bpmnlint rule calling an async function

Is it possible to make a custom bpmnlint rule that calls an async function? I have integrated bpmnlint and bpmn-js-lint into my react project. In doing so, I’m writing a custom bpmnlint that needs to make an api call to verify that the data associated with a task on the diagram is correct. However, creating an async rule that calls await causes the console to print this error:

export ‘default’ (imported as ‘rule_11’) was not found in 'bpmnlint-plugin-rules/rules/test-rule'

In my project, I have a directory called bpmnlint-plugin-rules/rules where all my custom rules are located and here is what my rule looks like:


/** bpmnlint-plugin-rules/rules/test-rule.js */
module.exports = () => {
    const check = async (node, reporter) => {
        if (is(node, 'bpmn:Task') && node.name) {
            const data = await someApiCall();
            // do some comparisons with data and node.$attrs
            reporter.report(node.id, 'some message');
        }
    };
    return { check };
};

Could you explain your issue in a structured and detailed manner, so anyone has a fair chance to understand your use case?

If you are stuck with a particular problem, provide the necessary context. Phrase your post so that we can follow your line of thought, step by step.

Please revise your post; we may not be able to help you otherwise. We may also close topics of low quality to prevent spam.

Thanks :heart:

Thanks for updating your post to provide further details!

In bpmnlint evaluating a rule, i.e. check is always synchronous. This is to make sure that rules can be evaluated blazing fast, on the fly, as a user edits a diagram.

What is possible is to define a rule itself. This allows you to load and cache data required for validation before rule evaluation:

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

  const data = await someApiCall();

  function check(node, reporter) {
    if (is(node, 'bpmn:Task') && node.name) {

      // do some comparisons with data and node.$attrs
      reporter.report(node.id, 'some message');
    }
  };

  return { check };
}

Does that help you? If not I’d be interested in some additional details what you are going to lint (and why check-time checks are required for that.

I’m sorry if it’s not allowed to bump old topics, but otherwise, I would have to create exactly the same again.

I’ve stumbled upon this question, and would like to run a async check in a bpmnlint rule to validate Javascript code that is embedded in a script task.

I’m looping over all ServiceTask to extract the body of inputParameters with type Script and language Javascript to verify if the Javascript looks valid.

I could easily use the API of eslint for this, and pass the extracted body to eslint.lintText(body) like documented here: Node.js API Reference - ESLint - Pluggable JavaScript Linter

Since this API is async, I would have to await the result of this call somehow.

Is this possible by now? I’ve noticed a few commits related to running code async, but it doesn’t look like there are any rules that run async code.

No, this is still not possible yet. You could take a stab at this issue, checkout the library workings and see if it is feasible to add such support.