Skip to content

Commit

Permalink
Change type names to be more consistent (#6503)
Browse files Browse the repository at this point in the history
The `Plugin` type should be used as a return type of the `createPlugin()` function.

Co-authored-by: Richard Hallows <jeddy3@users.noreply.github.com>
  • Loading branch information
ybiquitous and jeddy3 committed Dec 5, 2022
1 parent c6823ba commit 8a56ccc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-penguins-know.md
@@ -0,0 +1,5 @@
---
"stylelint": major
---

Changed: type names to be more consistent
8 changes: 3 additions & 5 deletions types/stylelint/index.d.ts
Expand Up @@ -7,10 +7,10 @@ declare module 'stylelint' {
export type Severity = 'warning' | 'error';

export type ConfigExtends = string | string[];
export type PluginType =
export type Plugin =
| { default?: { ruleName: string; rule: Rule } }
| { ruleName: string; rule: Rule };
export type ConfigPlugins = string | PluginType | (string | PluginType)[];
export type ConfigPlugins = string | Plugin | (string | Plugin)[];
export type ConfigProcessor = string | [string, Object];
export type ConfigProcessors = string | ConfigProcessor[];
export type ConfigIgnoreFiles = string | string[];
Expand Down Expand Up @@ -196,8 +196,6 @@ declare module 'stylelint' {
meta?: RuleMeta;
};

export type Plugin = RuleBase;

export type GetPostcssOptions = {
code?: string;
codeFilename?: string;
Expand Down Expand Up @@ -449,7 +447,7 @@ declare module 'stylelint' {
/**
* Creates a Stylelint plugin.
*/
createPlugin: (ruleName: string, rule: Rule) => { ruleName: string; rule: Rule };
createPlugin: (ruleName: string, rule: Rule) => Plugin;
/**
* Internal use only. Do not use or rely on this method. It may
* change at any time.
Expand Down
16 changes: 8 additions & 8 deletions types/stylelint/type-test.ts
Expand Up @@ -11,8 +11,8 @@ import type {
FormatterType,
LintResult,
LinterResult,
Plugin,
Rule,
RuleBase,
RuleMeta,
Warning,
} from 'stylelint';
Expand Down Expand Up @@ -89,9 +89,9 @@ const meta: RuleMeta = { url: '...' };
const problemMessage: string = messages.problem;
const problemFunc: (...reason: string[]) => string = messages.warning;

const testPlugin: Plugin = (options) => {
const testRule: RuleBase = (option) => {
return (root, result) => {
const validOptions = stylelint.utils.validateOptions(result, ruleName, { actual: options });
const validOptions = stylelint.utils.validateOptions(result, ruleName, { actual: option });
if (!validOptions) {
return;
}
Expand All @@ -117,12 +117,12 @@ const testPlugin: Plugin = (options) => {
};
};

(testPlugin as Rule).ruleName = ruleName;
(testPlugin as Rule).messages = messages;
(testPlugin as Rule).primaryOptionArray = true;
(testPlugin as Rule).meta = meta;
(testRule as Rule).ruleName = ruleName;
(testRule as Rule).messages = messages;
(testRule as Rule).primaryOptionArray = true;
(testRule as Rule).meta = meta;

stylelint.createPlugin(ruleName, testPlugin as Rule);
stylelint.createPlugin(ruleName, testRule as Rule);

messages.withNarrowedParam('should work');

Expand Down

0 comments on commit 8a56ccc

Please sign in to comment.