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 plugin objects as config values #6481

Merged
merged 7 commits into from Dec 1, 2022

Conversation

phoenisx
Copy link
Contributor

Closes #6452

Allow users to pass Plugin functions, as well as string names for plugin config.

@changeset-bot
Copy link

changeset-bot bot commented Nov 18, 2022

🦋 Changeset detected

Latest commit: 7615c75

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@phoenisx
Copy link
Contributor Author

Need some help fixing the typing errors. The changes are logically correct, but I am not able to understand how to fix the typing errors. 🤦🏽

@phoenisx
Copy link
Contributor Author

The changes should also work with mergeConfigs() if a developer uses the same plugin import since stylelint runs on a single nodejs process.

PostCSS instead uses a format to pass an array of objects, which is helpful, because each plugin has a name, and if a plugin-name overlaps, we can exclude the previous one, while merging configs.

Not sure which pattern is preferred here. I feel the latter would provide more flexibility , but would be a breaking change, and we will have to keep the API backwards compatible, just in case.

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phoenisx Thanks for creating the pull request. I've left a suggestion comment to fix the type error.

types/stylelint/index.d.ts Outdated Show resolved Hide resolved
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, could you add test cases about the new feature to lib/__tests__/plugins.test.js?

@jeddy3 jeddy3 changed the title [Feat] enable passing plugin functions as config value Add support for plugin functions as config values Nov 18, 2022
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding test cases! Just in case, could you add more expectations, as I suggested?

lib/__tests__/plugins.test.js Show resolved Hide resolved
lib/__tests__/plugins.test.js Show resolved Hide resolved
@phoenisx phoenisx force-pushed the fix/issue-6452 branch 2 times, most recently from 60d5954 to 0bff714 Compare November 20, 2022 15:35
Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM 👍🏼

@ybiquitous ybiquitous mentioned this pull request Nov 21, 2022
6 tasks
@phoenisx
Copy link
Contributor Author

Shall I merge this, if this Looks good to everyone here?

@ybiquitous
Copy link
Member

@phoenisx I noticed it might be necessary to update the doc for plugins:

Could you please update it?

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phoenisx Thanks for the pull request. Almost looks ready to me. I've requested one change to the docs.

Comment on lines 237 to 246
- stylelint plugin object of format

```js
{
ruleName: "plugin-name",
rule: function plugin(opts) { /* Plugin Code */ }
}
```

> Read more about writing [Stylint Plugins here](../developer-guide/plugins.md).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert this change and then change the preceding paragraph so we don't mix terms like locators and functions:

"To use one, add a "plugins" array to your config, containing either plugin functions or "locaters" identifying the plugins you want to use. As with extends, above, a "locater" can be either a:"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also agree with @jeddy3's suggestion. Furthermore, "plugin objects" may be more accurate than "plugin functions" because a Stylelint plugin is an object:

module.exports = function createPlugin(ruleName, rule) {
return {
ruleName,
rule,
};
};

@ybiquitous ybiquitous self-requested a review November 29, 2022 23:16
@phoenisx
Copy link
Contributor Author

phoenisx commented Dec 1, 2022

Sure. I’ll fix this once I am back home 👍

@jeddy3 jeddy3 changed the title Add support for plugin functions as config values Add support for plugin objects as config values Dec 1, 2022
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks.

I made the doc change.

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. LGTM 👍🏼

@ybiquitous
Copy link
Member

Oops, a changelog entry is needed.

@ybiquitous
Copy link
Member

Changelog added via 40a3c1a

@ybiquitous ybiquitous merged commit 1916118 into stylelint:main Dec 1, 2022
@ybiquitous
Copy link
Member

@phoenisx Thanks for the contribution!

@phoenisx phoenisx deleted the fix/issue-6452 branch December 6, 2022 07:35
@phoenisx
Copy link
Contributor Author

phoenisx commented Dec 6, 2022

Thanks to you all for making the change, while I was away 🙇🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Add support for JS functions in plugins list in Stylelint config
3 participants