[PR #1014] [CLOSED] Implement TypeScript type generation for the configuration #3016

Closed
opened 2026-03-07 20:11:41 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/DavidAnson/markdownlint/pull/1014
Author: @Lehoczky
Created: 10/21/2023
Status: Closed

Base: nextHead: next


📝 Commits (3)

  • cb40a37 Implement TypeScript type generation for the configuration
  • e32742a pin quicktype dependency
  • 1473def Fix typo

📊 Changes

11 files changed (+1535 additions, -26 deletions)

View changed files

📝 .eslintrc.json (+8 -0)
📝 .gitignore (+1 -0)
📝 demo/markdownlint-browser.js (+19 -7)
📝 lib/markdownlint.d.ts (+14 -8)
📝 lib/markdownlint.js (+19 -7)
📝 micromark/exports-html.mjs (+1 -1)
📝 micromark/exports.mjs (+0 -2)
📝 package.json (+4 -1)
schema/build-config-declaration.js (+191 -0)
schema/markdownlint-config.d.ts (+1268 -0)
📝 test/markdownlint-test.js (+10 -0)

📄 Description

Resolves #1004

📚Description

This PR adds a new script to the project: schema/build-config-declaration.js. The script takes the existing configuration schema, and generated a new file markdownlint-config.d.ts with type declaration for the config. This script now runs as part of the build-declaration npm script.

The generated type is then used in the libs/markdownlint.js file to enrich the existing Configuration type:

/**
 * Rule configuration object.
 *
- * @typedef {Object.<string, RuleConfiguration>} Configuration
+ * @typedef {import("../schema/markdownlint-config").Config} Configuration
 */

With this change, the functions that already used this type now has proper suggestions:

image

A new defineConfig() function was added as well to make it easier to define configurations in js files, like vite, astro or nuxt does.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/DavidAnson/markdownlint/pull/1014 **Author:** [@Lehoczky](https://github.com/Lehoczky) **Created:** 10/21/2023 **Status:** ❌ Closed **Base:** `next` ← **Head:** `next` --- ### 📝 Commits (3) - [`cb40a37`](https://github.com/DavidAnson/markdownlint/commit/cb40a3700a58f2426092c5a57284a30380d1801a) Implement TypeScript type generation for the configuration - [`e32742a`](https://github.com/DavidAnson/markdownlint/commit/e32742a1b86c41ddea486fca4d1e8743d17b52bc) pin quicktype dependency - [`1473def`](https://github.com/DavidAnson/markdownlint/commit/1473defc1f4859d0de25a3141d32fd589dc21431) Fix typo ### 📊 Changes **11 files changed** (+1535 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `.eslintrc.json` (+8 -0) 📝 `.gitignore` (+1 -0) 📝 `demo/markdownlint-browser.js` (+19 -7) 📝 `lib/markdownlint.d.ts` (+14 -8) 📝 `lib/markdownlint.js` (+19 -7) 📝 `micromark/exports-html.mjs` (+1 -1) 📝 `micromark/exports.mjs` (+0 -2) 📝 `package.json` (+4 -1) ➕ `schema/build-config-declaration.js` (+191 -0) ➕ `schema/markdownlint-config.d.ts` (+1268 -0) 📝 `test/markdownlint-test.js` (+10 -0) </details> ### 📄 Description Resolves #1004 ## 📚Description This PR adds a new script to the project: `schema/build-config-declaration.js`. The script takes the existing configuration schema, and generated a new file `markdownlint-config.d.ts` with type declaration for the config. This script now runs as part of the `build-declaration` npm script. The generated type is then used in the `libs/markdownlint.js` file to enrich the existing `Configuration` type: ```diff /** * Rule configuration object. * - * @typedef {Object.<string, RuleConfiguration>} Configuration + * @typedef {import("../schema/markdownlint-config").Config} Configuration */ ``` With this change, the functions that already used this type now has proper suggestions: ![image](https://github.com/DavidAnson/markdownlint/assets/31937175/5b41e2da-212a-459e-8f99-d413108187dd) A new `defineConfig()` function was added as well to make it easier to define configurations in `js` files, like [vite](https://vitejs.dev/guide/using-plugins.html#adding-a-plugin), [astro](https://docs.astro.build/en/guides/configuring-astro/#the-astro-config-file) or [nuxt](https://nuxt.com/docs/getting-started/configuration#nuxt-configuration) does. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-07 20:11:41 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#3016
No description provided.