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

Refactor the internal API #6415

Merged
merged 1 commit into from Oct 17, 2022
Merged

Refactor the internal API #6415

merged 1 commit into from Oct 17, 2022

Conversation

ybiquitous
Copy link
Member

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

None.

Is there anything in the PR that needs further explanation?

This refactoring aims to make the codebase around the internal API more consistent.

Our codebase is mostly FP style, so the OOP-like code using .bind() seems inconsistent to me.

Also, the dependency between the internal modules seems implicit through .bind().

This refactoring aims to make the codebase around the internal API more consistent.

Our codebase is mostly FP style, so the OOP-like code using `.bind()` seems inconsistent to me.

Also, the dependency between the internal modules seems implicit through `.bind()`.
@changeset-bot
Copy link

changeset-bot bot commented Oct 17, 2022

⚠️ No Changeset found

Latest commit: 39166e8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

) => Promise<LintResult>;

getConfigForFile: (searchPath?: string, filePath?: string) => Promise<CosmiconfigResult>;
isPathIgnored: (s?: string) => Promise<boolean>;
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] I believe InternalApi and createLinter is private and never break our ecosystem.

/**
* Internal use only. Do not use or rely on this method. It may
* change at any time.
* @internal
*/
createLinter: (options: LinterOptions) => InternalApi;

However, if this pull request would harm the ecosystem, I'd like to close it.

@ybiquitous ybiquitous marked this pull request as ready for review October 17, 2022 13:57
@@ -0,0 +1,26 @@
'use strict';
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] createLinter.test.js is divided into two files.

const ignoreFiles = /** @type {Array<string>} */ (result.config.ignoreFiles || []).map((s) =>
normalizePath(s),
);
const ignoreFiles = [result.config.ignoreFiles || []].flat().map((s) => normalizePath(s));
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] The technique using .flat() has an advantage for the type inference.

throw err;
});
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] This refactoring makes the code consistent using async/await.

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.

LGTM, thank you!

@ybiquitous ybiquitous merged commit cb425cb into main Oct 17, 2022
@ybiquitous ybiquitous deleted the refactor-internal-api branch October 17, 2022 15:24
@ybiquitous
Copy link
Member Author

Thanks for the quick review! 😄

@ricardogobbosouza
Copy link

ricardogobbosouza commented Dec 5, 2022

Hi @jeddy3
This was a significant change...
Its broke some plugins, like for example https://github.com/webpack-contrib/stylelint-webpack-plugin
It should be a breaking change, no?

@alexander-akait
Copy link
Member

@jeddy3 @ybiquitous Friendly ping

@ybiquitous
Copy link
Member Author

@ricardogobbosouza @alexander-akait
Thanks for sharing the problem. As I commented on #6415 (comment), I thought InternalApi was internal, so safe to change.

/**
* Internal use only. Do not use or rely on this type. It may change at
* any time.
* @internal
*/
export type InternalApi = {

However, I'll gladly cooperate to fix the problem.

@alexander-akait
Copy link
Member

@ybiquitous Yeah, I think we should move such things from public api to prevent such situaltion, or use # or _ to indicate them, because other tools can faced with it too

@ybiquitous
Copy link
Member Author

Agree. I'll add @internal annotations to the internal type definitions.

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.

None yet

4 participants