Skip to content

feat: upgrade dprint-plugin-markdown to 0.21.1 with heading_kind option#10

Merged
fahchen merged 6 commits into
mainfrom
upgrade-dprint-0.21.1
Apr 18, 2026
Merged

feat: upgrade dprint-plugin-markdown to 0.21.1 with heading_kind option#10
fahchen merged 6 commits into
mainfrom
upgrade-dprint-0.21.1

Conversation

@fahchen

@fahchen fahchen commented Apr 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Upgrade Rust dep dprint-plugin-markdown 0.18.0 → 0.21.1 (3 minor versions; 0.21.0 never published to crates.io). dprint-core stays on 0.67.4 (already latest).
  • Expose new :heading_kind option (:atx | :setext, default :atx) across Config, Validator, Native typespec, and Mix formatter integration. String form ("atx" / "setext") accepted in mix.exs like other atom-choice fields.
  • Rust-side tags (also newly required by 0.21.1 Configuration) hardcoded to HashMap::new() — the NIF's format_code_block_text callback is still |_, _, _| Ok(None), so exposing tags has no observable effect yet. Will ship alongside external-formatter dispatch when that lands.
  • Refactor: Config validate_option/2 (6 × 3 clauses) collapsed into a single dispatch over an @atom_choices table plus validate_atom_choice/2 helper. Rust 6 build_* functions generated from a single build_enum_option! macro. Net -96 lines.
  • Also loosens typed_structor version constraint (~> 0.5.0~> 0.5).

Incidental fixes

  • Config.to_nif_config/1 spec: line_width was non_neg_integer(), should be pos_integer() to match the struct.
  • format_elixir_source: dead [] -> pattern (dialyzer warning on Elixir 1.19) cleaned up while preserving single-pass IO.iodata_to_binary.
  • Config.load/0 doctest with environment-dependent output removed.

Known behavior changes from dprint 0.21.1 upstream

None of the existing fixtures broke, but upstream notes flag (none triggered here):

  • #144 (0.20.0): JSONC code blocks no longer mis-identified as JSON.
  • #169 (0.21.1): setext heading underline length is now variable-width.
  • #173 (0.21.1): whitespace trim correction around code blocks.

Test plan

  • mix test — 28 doctests, 112 tests, 0 failures, 1 skipped
  • mix dialyzer — 0 errors
  • mix format --check-formatted — clean
  • cargo build / cargo fmt --check / cargo clippy --all-targets -- -D warnings — zero warnings
  • Smoke test: format("# Hello", heading_kind: :setext)"Hello\n=====\n"; default atx preserved

🤖 Generated with Claude Code

fahchen and others added 6 commits April 18, 2026 22:13
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Bump native dep 0.18.0 → 0.21.1; Configuration gains heading_kind and
  tags fields (both mandatory in the new version)
- Add :heading_kind option (:atx | :setext, default :atx) across Config,
  Validator, and Native typespec; string form accepted in mix.exs
- Hardcode Rust-side tags to HashMap::new() — no external formatter
  dispatch yet, not worth exposing
- Activate DprintMarkdownFormatter.Config doctest via new config_test.exs
- Fix to_nif_config/1 spec: line_width non_neg_integer → pos_integer
- Fix format_elixir_source dialyzer warning on unreachable [] pattern

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Collapse 6 × 3 validate_option/2 clauses in Config into a single
  dispatch backed by an @atom_choices table plus a shared
  validate_atom_choice/2 helper; error messages unchanged (including
  Oxford comma for 3+ choices)
- Introduce build_enum_option! macro in the NIF to generate 6 build_*
  functions from a single pattern; import the dprint enums directly so
  each call site fits on a few lines
- No behavior change; 112 tests + dialyzer still green

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The previous iex> examples were removed because they would fail as
doctests once the module's doctest was activated. Restore the example
using a #=> comment so it's shown in generated docs without being
executed as a test.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The pattern-matching on `Code.format_string!/2` output directly works on
Elixir 1.19 where dialyzer infers binary() | nonempty_improper_list(),
but fails on Elixir 1.18 where the return type is [binary()] and the
"" pattern cannot match. Normalize to binary first so the check is
version-agnostic.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Credo flags bare `_` as inconsistent with the project's `_foo` style.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fahchen
fahchen merged commit cf4605f into main Apr 18, 2026
8 checks passed
@fahchen
fahchen deleted the upgrade-dprint-0.21.1 branch April 18, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant