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

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

Open
2 tasks
philippfromme opened this issue May 13, 2022 · 13 comments
Open
2 tasks
Labels
backlog Queued in backlog enhancement New feature or request spring cleaning Could be cleaned up one day

Comments

@philippfromme
Copy link
Contributor

philippfromme commented May 13, 2022

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:

  • Local rule can be discovered (NodeJS)
  • Local rule can be compiled to a bundle

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. camunda/camunda-modeler#2958).

@philippfromme philippfromme added enhancement New feature or request spring cleaning Could be cleaned up one day labels May 13, 2022
@philippfromme philippfromme changed the title Document Configuration Options Other Than Plugin or or Add Example Document Configuration Options Other Than Plugin or Add Example May 13, 2022
@nikku
Copy link
Member

nikku commented May 13, 2022

Root causing this:

  • One of the issues is how bpmnlint currently resolves names. You can find out what it does here.
  • In a nutshell, it won't ever resolve foo to the actual package foo but would always assume it is called bpmnlint-plugin-foo

@nikku
Copy link
Member

nikku commented May 13, 2022

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 nikku added the help wanted Extra attention is needed label May 13, 2022
@nikku nikku self-assigned this May 13, 2022
@nikku
Copy link
Member

nikku commented May 13, 2022

Created a simple example to reproduce this case.

@JessYan0913
Copy link

JessYan0913 commented May 24, 2022

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 nikku removed their assignment May 25, 2022
@nikku
Copy link
Member

nikku commented May 25, 2022

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

@nikku nikku added the backlog Queued in backlog label May 25, 2022
@JessYan0913
Copy link

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
Copy link
Member

nikku commented May 25, 2022

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
Copy link

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
Copy link
Member

nikku commented May 25, 2022

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.

@nikku nikku changed the title Document Configuration Options Other Than Plugin or Add Example Be able to resolve local rules / define rules outside of a plug-in May 25, 2022
@nikku nikku removed the help wanted Extra attention is needed label May 25, 2022
@JessYan0913
Copy link

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
Copy link

@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
Copy link

sl45sms commented Jun 2, 2024

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
Copy link
Member

nikku commented Jun 3, 2024

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:

  • Ensure rule compilation works with local rules
  • Ensure that rule discovery (NodeJS) works with local rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog Queued in backlog enhancement New feature or request spring cleaning Could be cleaned up one day
Projects
None yet
Development

No branches or pull requests

5 participants