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 meta.url to enable links in terminal #5842

Closed
ybiquitous opened this issue Jan 17, 2022 · 3 comments · Fixed by #5845
Closed

Add support for meta.url to enable links in terminal #5842

ybiquitous opened this issue Jan 17, 2022 · 3 comments · Fixed by #5845
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

@ybiquitous
Copy link
Member

What is the problem you're trying to solve?

As discussed with #2622, I think it is very useful if stylelint rules (including plugins) could have metadata with doc URL, deprecated, etc. like ESLint.

For example, use cases:

Actually, we had metadata with the deprecated property:

rule.meta = { deprecated: true };

Also, the Stylelint document below has described rule metadata:

2. Add the appropriate meta data to mark the rule as deprecated.

What solution would you like to see?

I propose to define a metadata schema via the document and type definitions (TypeScript).

For example of a rule with metadata:

// lib/rules/color-no-invalid-hex/index.js
rule.ruleName = ruleName;
rule.messages = messages;

rule.meta = {
  type: 'problem', // or 'convention' etc.
  docs: {
    description: 'Disallow invalid hex colors.',
    url: 'https://stylelint.io/user-guide/rules/list/color-no-invalid-hex',
  },
  deprecated: false,
  fixable: true,
  schema: [
    { type: 'boolean' }, // primary
  ],
};

module.exports = rule;

For the Rule type of the TypeScript definitions, we would add a meta property:

export type RuleBase<P = any, S = any> = (
primaryOption: P,
secondaryOptions: Record<string, S>,
context: PluginContext,
) => (root: PostCSS.Root, result: PostcssResult) => Promise<void> | void;
export type Rule<P = any, S = any> = RuleBase<P, S> & {
ruleName: string;
messages: RuleMessages;
primaryOptionArray?: boolean;
};

@ybiquitous ybiquitous added the status: needs discussion triage needs further discussion label Jan 17, 2022
@jeddy3
Copy link
Member

jeddy3 commented Jan 18, 2022

SGTM. I suggest we start with meta.url so that plugins can opt into the terminal links. We can open up follow up issues for other properties as we need them / want to work on them.

Should we explicitly define the URL for the built-in rules or continue to build it from the rule name?

@ybiquitous
Copy link
Member Author

@jeddy3 Thanks for the feedback!

I agree with the small start to add meta.url. 👍🏼

And, I think it better to "explicitly define the URL for the built-in rules" like ESLint does. It is straightforward and doesn't require any extra build steps.

@jeddy3 jeddy3 changed the title Define rule metadata schema Add support for meta.url to enable links in terminal Jan 18, 2022
@jeddy3 jeddy3 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 Jan 18, 2022
@jeddy3
Copy link
Member

jeddy3 commented Jan 18, 2022

Labelled as ready.

Let's include updating the plugin docs as part of the pull request.

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