mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 17:26:22 +03:00
[GH-ISSUE #1004] Create or document how to use a TypeScript type for configuration schema #591
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#591
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Lehoczky on GitHub (Oct 14, 2023).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1004
Hi David 👋
What is your opinion on generating a TS type for the configuration?
Right now people using a
jsonconfig file get autocompletion thanks to themarkdownlint-config-schema.json, but it's not possible to get the same experience forjsfiles.Prettier and tailwind for example has such a type exported, which can be used in config files.
Another thing that could be done, is to have a
defineConfig()function like vite, nuxt or astro has.I've created a package as a POC (the generated type can be found here) so you can check out the idea, and whether you think it would be worth it to add this to the library.
@DavidAnson commented on GitHub (Oct 14, 2023):
The idea makes sense and I see how this could be useful! Thanks for the suggestion!
If I were to add to this library, I would want to generate the types from the JSON schema because that already captures everything that's needed and it isn't necessary to duplicate information. After a very brief bit of research, these two packages seem to offer that capability:
But I also found the following package which seems to offer the same capability dynamically at runtime, thereby avoiding the need to generate/commit an artifact at all:
If it works, my preference would be for something like the last one because it seems universally applicable and limits complexity to just those scenarios that need it (i.e., pay for play).
@Lehoczky commented on GitHub (Oct 14, 2023):
I tried out json-schema-to-typescript but in the end I used quicktype, because it created a more readable output.
I also looked at json-schema-to-ts, but there are multiple issues open mentioning performance issues, which don't surprise me, because it can be a lot of work for the TypeScript language server to handle the conversion of big json schemas at runtime:
Fortunately, because I implemented the TypeScript type generation using the existing json schema which is the same approach you prefer, I can make draft pull request pretty quickly. I just have to migrate the code I've already written:D
@DavidAnson commented on GitHub (Oct 14, 2023):
The performance issues you reference above do not seem like they would be problematic in this scenario with a single/small schema and file. That said, there is an opportunity to improve the fidelity of the existing
type Configurationdefinition. I'm not sure how everything needs to be wired up but my expectation is something like a single new.d.tsfile created from the existing JSON schema using a tool like those referenced above. Then make a reference to that in the existing JSDoc comments inmarkdownlint.jswhich leads to everything composing together intomarkdownlint.d.tsfile by the TypeScript step that's already run.@DavidAnson commented on GitHub (Nov 14, 2023):
v0.32.0