bpmn-io / bpmnlint

Validate BPMN diagrams based on configurable lint rules.
MIT License
121 stars 36 forks source link

Be able to resolve local rules / define rules outside of a plug-in #81

Open philippfromme opened 2 years ago

philippfromme commented 2 years ago

Is your feature request related to a problem? Please describe

The linter can be configured using NodeResolver, StaticResolver or a custom one. Figuring out how to do this is quite difficult (cf. https://github.com/camunda/web-modeler/pull/1249#issuecomment-1125971172). In fact defining local rules is impossible at the moment.

Describe the solution you'd like

There should be a well documented way how to configure a custom lint rule outside of a plug-in:

Describe alternatives you've considered

Using the source code and the tests I eventually figured out how to configure the linter but it took me quite long, and I don't know if I did it the way it's intended (cf. https://github.com/camunda/camunda-modeler/pull/2958).

nikku commented 2 years ago

Root causing this:

nikku commented 2 years ago

There should be documentation or an example of configuring the linter without a plugin.

I'd be interested in a short summary, what you're trying to do: How do you want to configure / consume rules outside of a plug-in and how would you assume this works?

nikku commented 2 years ago

Created a simple example to reproduce this case.

JessYan0913 commented 2 years ago

I want to customize the rules, but I don't know how to add the custom rules to the cache of bpmnlint 1653354997(1) 1653355055(1) 1653355071(1)

nikku commented 2 years ago

@JessYan0913 Thanks for sharing your use-case. We want to look into this some time in the future.

JessYan0913 commented 2 years ago

Thanks for sharing your use-case. We want to look into this some time in the future. I think it's OK to add the custom check method to the cache, but can the cache be added by setlinterconfig()? 1653470961(1)

nikku commented 2 years ago

No. The cache is internal and not meant to fiddle around with.

Instead: Consider how you mark your rules as local in .bpmnlintrc. Allow the parse to recognize these local rules.

JessYan0913 commented 2 years ago

No. The cache is internal and not meant to fiddle around with.

Instead: Consider how you mark your rules as local in .bpmnlintrc. Allow the parse to recognize these local rules.

How should i make it .bpmnlinter recognizes local rules

nikku commented 2 years ago

Instead: Consider how you mark your rules as local in .bpmnlintrc. Allow the parse to recognize these local rules

Not you should consider it, but we have to build it. It is a missing feature.

As a workaround you have to define your rules in a dedicated bpmnlint plug-in. Local rules are not supported at the moment.

JessYan0913 commented 2 years ago

Instead: Consider how you mark your rules as local in .bpmnlintrc. Allow the parse to recognize these local rules

Not you should consider it, but we have to build it. It is a missing feature.

As a workaround you have to define your rules in a dedicated bpmnlint plug-in. Local rules are not supported at the moment.

OK, I hope I can use it as soon as possible 😂

Duman105934 commented 9 months ago

@JessYan0913 hello, I currently have the same need as you. I need to supplement with my own rules. If you were able to add them, could you please share your experience on how you managed to do so?

sl45sms commented 3 months ago

Maybe you can override requireLocal option to load your custom rules

  const config = {
    config: {
      extends: ['bpmnlint:myrules']
    },
    resolver: new NodeResolver({
      requireLocal:(path) => {
        if (path.includes('config/myrules')) {
        const mrequire = createRequire(import.meta.url);
        return mrequire("/app/config/myrules");
        }
        if (path.includes('rules')) {
          //extract rule name from path
          const ruleName = path.split('/').pop();
          const mrequire = createRequire(import.meta.url);
          return mrequire("/app/rules/"+ruleName);
        }
        return null;
      }
    })
  };

  const linter = new Linter(config);

I have not tested through, but a similar technique has used to load on a nextjs app.

nikku commented 3 months ago

Folks I apprechiate your input on this topic! To drive this forward I propose that someone contributes a "local rules" setup to our integration tests. We could then go ahead and turn the nobs to make it happen: