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.