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

Fix plugins.md document and createPlugin type definition #6264

Merged
merged 1 commit into from Aug 16, 2022
Merged

Conversation

ybiquitous
Copy link
Member

Which issue, if any, is this issue related to?

Closes #6245

Is there anything in the PR that needs further explanation?

This PR mainly fixes the incorrect examples on the plugin document. Also, this improves the type definition of the stylelint.createPlugin() API, although it may be called refactorings.

The incorrect part on the doc is here: ⬇️

module.exports.ruleName = ruleName;
module.exports.messages = messages;
module.exports.meta = meta;

Because stylelint.createPlugin() returns an object { ruleName: string, rule: Function },

function createPlugin(ruleName, rule) {
return {
ruleName,
rule,
};
}

the following code using module.exports produces an incorrect object { ruleName: string, rule: Function, messages: Object, meta: Object }.

module.exports.ruleName = ruleName;
module.exports.messages = messages;
module.exports.meta = meta;

To be correct, the rule function should have the ruleName, messages, and meta properties as below. The current example on the doc is confusing.

const ruleFunc = () => { /* .. */ };

ruleFunc.ruleName = ruleName;
ruleFunc.messages = messages;
ruleFunc.meta = meta;

For example, the stylelint-scss plugin sets the properties correctly.

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.

This all LGTM, thank you!

@ybiquitous ybiquitous merged commit 8d79dd4 into main Aug 16, 2022
@ybiquitous ybiquitous deleted the issue-6245 branch August 16, 2022 00:13
@ybiquitous
Copy link
Member Author

@jeddy3 Thanks for the review!

Changelog entry added:

  • Fixed: plugins document and createPlugin type definition (#6264).

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.

Fix URL metadata for plugins
2 participants