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

Change type names to be more consistent #6503

Merged
merged 2 commits into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/early-penguins-know.md
@@ -0,0 +1,5 @@
---
"stylelint": major
Copy link
Member Author

@ybiquitous ybiquitous Dec 5, 2022

Choose a reason for hiding this comment

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

I doubt if only type definition change should be considered as a breaking. Such a change does not break anything about runtime behavior but may raise a type-check error.

Do you have any (semver) guidelines about such a change?

EDIT: If considered as breaking, it will not be possible to refactor the type definitions easily.

Copy link
Member

Choose a reason for hiding this comment

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

Do you have any (semver) guidelines about such a change?

We don't. Is there a defacto approach for packages that publish types that we could adopt?

If not, let's just switch back to refactor like you originally had it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a defacto approach for packages that publish types that we could adopt?

I'm not sure if it exists or not... 🤷🏼

Copy link
Member Author

@ybiquitous ybiquitous Dec 5, 2022

Choose a reason for hiding this comment

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

When I googled, the following website is found:

Semantic Versioning for TypeScript Types - https://www.semver-ts.org/

EDIT: I guess this guide is not defacto, maybe.

Copy link
Member Author

Choose a reason for hiding this comment

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

When I read semver-ts.org, I feel a bit too strict, honestly.

However, aside from the future, because it's obvious that there's a possibility of breaking anything, I have no objections to considering this PR as breaking. 👍🏼

---

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