-
-
Notifications
You must be signed in to change notification settings - Fork 934
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
Document approach to using private utils #6866
Comments
If this feature is needed, I can create a PR for it |
@Max10240 Thanks for the report and the pull request. I understand your pain, but I don't think your pull request #6867 is a good solution. My concerns:
|
Yes, I thought about both when I created this PR. |
At least, we can publicly expose stylelint/docs/developer-guide/rules.md Line 112 in c81e63f
If doing so, it seems better to expose them under the public API Lines 24 to 29 in c81e63f
Any thoughts? |
I think 'typeGuards' and' eachDeclarationBlock 'would be useful as well. Maybe we can just talk about what shouldn't be exported and export the other utils functions so TS users can use them as they want. I don't think exporting a little more is particularly unacceptable. But I'm also in favor of exporting as little as necessary (just a trade-off between ease of use and closure). |
Considering our maintenance difficulty, I can't entirely agree with exposing all internal utilities.
|
I respect your idea, let's start by exporting
import { isExpressionStatement, isForOfStatement /*...*/ } from '@babel/types';
// -------------------------------
import { ASTUtils, /*...*/ } from '@typescript-eslint/utils';
ASTUtils.isIdentifier(/*...*/) It seems not like "just for internal use".
// @filename types/index.d.ts
declare module 'stylelint/lib/utils/typeGuards' {
import { Node, Root } from 'postcss';
export function isRoot(node: Node): node is Root;
// ...
}
// @filename: src/custom-rule.ts
import { isRoot } from 'stylelint/lib/utils/typeGuards';
import type { Node } from 'postcss';
declare const node: Node;
isRoot(node);
declare module 'stylelint/lib/utils/typeGuards' {
/* paste content.... */
} |
Also let's keep the issue open and listen to other people's opinions~ |
lib/utils/
)
Sounds good. I'll close #5669 in favour of this broader discussion issue. |
related: #6258 |
I agree with @ybiquitous sentiment here and in #5669 that we should limit our public API to refactor as a small team of volunteers efficiently. Keeping Stylelint maintained benefits all our users. The utilities we currently expose make sense. For example, I had wondered about the I suggest we clarify in our docs that utils should be copied and not required. Then, either for |
I agree with this @jeddy3's idea. 👍🏼 |
It would be more future-proof to have a whitelist—instead of a blacklist—so that the new utils will be automatically considered not exposed by default and we won't have to update that list until #6258.
👍 for 16 |
What is the problem you're trying to solve?
I'm writting a custom stylelint rule in TS, as mentioned in the document:
doc link
I want to use some utils functions to help me implement the rule, like:
example-rule.ts
But TS complained that it could not find the declaration file:
What solution would you like to see?
I can write my rule like the code above without any type errors and get type hints.
for now, I do this by modifying the local
stylelint
repository and linking to mycustom-rule
repository via "npm link", and it works well.I create a new tsconfig file in my local
stylelint
project to emit declaration files:tsconfig.emit.json
then, i run
tsc -p tsconfig.emit.json
to emit declaration files, and linkstylelint
to global bynpm link
.After that, I switch to my
custom-rule
project and runnpm link stylelint
, everything is fine.The text was updated successfully, but these errors were encountered: