From e4405de29e8bbd83d110f71b68a6ce5b13173500 Mon Sep 17 00:00:00 2001 From: Hakula Chen Date: Sun, 29 Nov 2026 00:00:20 +0800 Subject: [PATCH 1/5] feat(hooks): share formatter and linter policies with editors Expose the Markdown formatter and its config from the flake library, and build the Nix config from the native dprint config. Share markdownlint rules independently of CLI2 options and recognize standalone Prettier configs at the project root. --- .markdownlint-cli2.jsonc | 12 +----- .markdownlint.jsonc | 13 +++++++ docs/hooks.md | 16 ++++++-- dprint.json | 10 +++++ nix/dprint-config.nix | 22 +++++++++++ nix/hooks/baseline.nix | 50 ++++++++++++++++++++----- nix/hooks/default.nix | 4 ++ nix/hooks/dprint-config.nix | 21 ----------- nix/lib.nix | 10 +++++ nix/packages/dprint-plugin-markdown.nix | 3 +- tests/default.nix | 2 +- tests/dprint-markdown/default.nix | 17 ++------- 12 files changed, 119 insertions(+), 61 deletions(-) create mode 100644 .markdownlint.jsonc create mode 100644 dprint.json create mode 100644 nix/dprint-config.nix delete mode 100644 nix/hooks/dprint-config.nix diff --git a/.markdownlint-cli2.jsonc b/.markdownlint-cli2.jsonc index ecffe91..42d456b 100644 --- a/.markdownlint-cli2.jsonc +++ b/.markdownlint-cli2.jsonc @@ -1,16 +1,6 @@ { "config": { - "code-block-style": { "style": "fenced" }, - "line-length": false, - "no-duplicate-heading": { "siblings_only": true }, - "ol-prefix": { "style": "ordered" }, - - // The dprint hook runs before this linter, so these match its output. - "code-fence-style": { "style": "backtick" }, - "emphasis-style": { "style": "underscore" }, - "heading-style": { "style": "atx" }, - "strong-style": { "style": "asterisk" }, - "ul-style": { "style": "dash" }, + "extends": "./.markdownlint.jsonc", }, "gitignore": true, diff --git a/.markdownlint.jsonc b/.markdownlint.jsonc new file mode 100644 index 0000000..31a1bba --- /dev/null +++ b/.markdownlint.jsonc @@ -0,0 +1,13 @@ +{ + "code-block-style": { "style": "fenced" }, + "line-length": false, + "no-duplicate-heading": { "siblings_only": true }, + "ol-prefix": { "style": "ordered" }, + + // The dprint hook runs before this linter, so these match its output. + "code-fence-style": { "style": "backtick" }, + "emphasis-style": { "style": "underscore" }, + "heading-style": { "style": "atx" }, + "strong-style": { "style": "asterisk" }, + "ul-style": { "style": "dash" }, +} diff --git a/docs/hooks.md b/docs/hooks.md index 3d7804d..20d5e61 100644 --- a/docs/hooks.md +++ b/docs/hooks.md @@ -56,11 +56,17 @@ preCommit = dk.preCommit { ### Use a project configuration file -Prettier, Taplo, and markdownlint-cli2 use devkit's shared [Prettier style](../.prettierrc.json), [Taplo formatting](../.taplo.toml), and [markdownlint rules](../.markdownlint-cli2.jsonc). A `.prettierrc.json` or `.taplo.toml` at the source root replaces the shared file once the dev shell is re-entered, and a project `.markdownlint-cli2.jsonc` overrides individual shared rules. +Prettier, Taplo, and markdownlint-cli2 default to devkit's shared [Prettier style](../.prettierrc.json), [Taplo formatting](../.taplo.toml), and [markdownlint-cli2 config](../.markdownlint-cli2.jsonc). Re-enter the dev shell after adding a root Prettier or Taplo configuration so the corresponding hook picks it up. + +A standalone [Prettier configuration file](https://prettier.io/docs/configuration) at the project root replaces the shared file. The hook prefers `.prettierrc.json` if present and otherwise follows Prettier's order for standalone files. Keep one Prettier config at the project root for consistent editor and hook behavior. A JavaScript config such as `prettier.config.cjs` can load the shared JSON style from a workspace-relative path and export it with project overrides. The hook disables Prettier's EditorConfig integration, so put any formatting options that need to match in the Prettier config. To use a package manifest's `prettier` key or per-directory configuration, use native discovery with `configPath = ""`. Use basenames in the shared Prettier configuration's `overrides`, since Prettier resolves those globs from the configuration's Nix store directory. -Set `hooks..settings.configPath` to point markdownlint-cli2, Prettier, Ruff, or Taplo at another file, or to `""` to let the tool find its own. A `.markdownlint-cli2.jsonc` that loads relative `customRules` or `markdownItPlugins` needs `configPath = ".markdownlint-cli2.jsonc"`, which drops the shared rules. +A root `.taplo.toml` replaces the shared file. For editor and CLI discovery, copy devkit's [Taplo config](../.taplo.toml) to the project root and adapt it to the project. + +A project `.markdownlint-cli2.jsonc` overrides individual rules from the hook's base configuration. To share those rules with editors and direct CLI runs, make devkit's [pure rule file](../.markdownlint.jsonc) available in the workspace and set `config.extends` in the project `.markdownlint-cli2.jsonc` to its relative path. Keep project rule overrides beside `extends` and CLI2 options such as `gitignore` at the top level. + +Set `hooks..settings.configPath` to point markdownlint-cli2, Prettier, Ruff, or Taplo at another file, or to `""` to let the tool find its own. A `.markdownlint-cli2.jsonc` that loads relative `customRules` or `markdownItPlugins` needs `configPath = ".markdownlint-cli2.jsonc"`. In that case, use `config.extends` to retain the shared rules. ### Add a spelling dictionary @@ -72,11 +78,13 @@ doctoc fills a table of contents between `` and `` and `