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

Add support for JS functions in plugins list in Stylelint config #6452

Closed
phoenisx opened this issue Nov 5, 2022 · 4 comments · Fixed by #6481
Closed

Add support for JS functions in plugins list in Stylelint config #6452

phoenisx opened this issue Nov 5, 2022 · 4 comments · Fixed by #6481
Labels
status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules

Comments

@phoenisx
Copy link
Contributor

phoenisx commented Nov 5, 2022

What is the problem you're trying to solve?

Using stylelint as a library in JS (NodeJS/Deno) does not accept JS functions as plugins: [] config values. It only works with string type for now.

Is it possible to support both?

What solution would you like to see?

Allow developers to, when using stylelint as JS library, to pass locally developed stylelint plugins as config param. For e.g.

stylelint({
  rules: {
    "private/rule-name": true,
  },
  plugins: [require("./plugin-path")],
})

I guess this can be resolved easily if we add a check in lib/augmentConfig.js#addPluginFunctions to separate string and JS function types as plugins passed in the config and run the logic accordingly.

@ybiquitous ybiquitous added the status: needs discussion triage needs further discussion label Nov 7, 2022
@ybiquitous
Copy link
Member

@phoenisx Thanks for the proposal. As you commented, I also guess it's possible to implement this feature relatively easily.

I'd just like to confirm, what kind of use cases do you have? The following simple case seems to have not much benefit. 🤔

-plugins: ["./plugin-path"],
+plugins: [require("./plugin-path")],

@phoenisx
Copy link
Contributor Author

phoenisx commented Nov 7, 2022

Hi @ybiquitous! Thanks for the quick reply 🙇🏽

I'd just like to confirm, what kind of use cases do you have?

If stylelint is used as a library and bundled into a project that can run in a different context (environment, directory etc.), while the end-user using that bundled project running it in a different context, stylelint fails to require inlined (private) plugins that got bundled in it.
For e.g Editor extensions, where the extension's runtime context is kept separate from a user's runtime context.

There's a hack I've been using right now, which seems okay, but would love to see this in-built.
I see even PostCSS plugin API supports such an API.
Would love to help add support for this, if approved!!

P.S: I already have a working patch ready for this 😉

@ybiquitous
Copy link
Member

@phoenisx Thank you for your explanation. I understand your background well. Also, it's so nice if you have a patch already.

Since I believe this addition would not break anything, I've labeled the issue as ready to implement.

If anyone has concerns, please feel free to comment.

@ybiquitous ybiquitous added status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules and removed status: needs discussion triage needs further discussion labels Nov 8, 2022
@phoenisx
Copy link
Contributor Author

Apologies for the delay, was a bit occupied.
I raised the PR with the required changes #6481 🙌🏽

@jeddy3 jeddy3 changed the title Support to accept JS functions in plugins list in Stylelint config Add support for JS functions in plugins list in Stylelint config Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules
Development

Successfully merging a pull request may close this issue.

2 participants