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 rule metadata to public API #6082

Closed
ybiquitous opened this issue May 13, 2022 · 1 comment · Fixed by #6166
Closed

Add rule metadata to public API #6082

ybiquitous opened this issue May 13, 2022 · 1 comment · Fixed by #6166
Labels
status: wip is being 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?

I want to write a custom formatter with rule metadata (e.g. rule doc URL), but now there is no way to use easily rule metadata.

For example, the built-in verbose formatter uses an internal API (_postcssResult):

function ruleMetadata(results) {
const firstResult = results[0];
return (
(firstResult &&
firstResult._postcssResult &&
firstResult._postcssResult.stylelint &&
firstResult._postcssResult.stylelint.ruleMetadata) ||
{}
);
}

I want to use a public API for this purpose.

What solution would you like to see?

I think that the simplest way is to add a property for rule metadata to LinterResult (used as the second argument of Formatter). See the relevant type definitions:

Formatter:

export type Formatter = (results: LintResult[], returnValue?: LinterResult) => string;

NOTE: It looks possible to change returnValue?: LinterResult (optional) to returnValue: LinterResult (required).

LinterResult:

export type LinterResult = {
/**
* The working directory from which the linter was run when the
* results were generated.
*/
cwd: string;
results: LintResult[];
errored: boolean;
output: any;
maxWarningsExceeded?: {
maxWarnings: number;
foundWarnings: number;
};
reportedDisables: DisableOptionsReport;
descriptionlessDisables?: DisableOptionsReport;
needlessDisables?: DisableOptionsReport;
invalidScopeDisables?: DisableOptionsReport;
};

The use of LinterResult on the public API:

export type PublicApi = PostCSS.PluginCreator<PostcssPluginOptions> & {
/**
* Runs stylelint with the given options and returns a Promise that
* resolves to the results.
*/
lint: (options: LinterOptions) => Promise<LinterResult>;

If you know of a better way, please let me know.

@ybiquitous ybiquitous added status: needs discussion triage needs further discussion type: enhancement a new feature that isn't related to rules labels May 13, 2022
@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone and removed status: needs discussion triage needs further discussion labels Jun 6, 2022
@jeddy3 jeddy3 changed the title Custom formatter with rule metadata Add rule metadata to public API Jun 6, 2022
@jeddy3
Copy link
Member

jeddy3 commented Jun 6, 2022

I think that the simplest way is to add a property for rule metadata to LinterResult (used as the second argument of Formatter).

SGTM. Labelled as ready to implement.

@ybiquitous ybiquitous added status: wip is being worked on by someone and removed status: ready to implement is ready to be worked on by someone labels Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wip is being 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