Skip to content

Interest checks for integrating dts formatter #3399

Description

@urob

Opening this issue to see if there is demand for a PR that integrates auto-formatting of Devicetree files (dts, dtsi, overlay, keymap) using dts-linter.

Background

dts-linter is the CLI frontend to dts-lsp. Both projects are quite new and explicitly tailored towards zephyr Devicetree files. By default, the formatting adheres to the Zephyr's Devicetree styleguide. The project maintainer @kylebonnici and I have worked together for the past weeks to fix various bugs in the LSP that prevented it from running on the ZMK codebase (okay, it was mainly Kyle doing the fixing), as well as add a few customization flags to the CLI frontend needed for ZMK.

Suggested plan

  • Prepare existing codebase
    • Fix one code instance where the linter errors (and which can't be fixed on the linter-side)
    • Guard manually aligned arrays (bindings, map and a few others) with dts-format off (if reformatting of the existing codebase is desired)
  • Apply formatter to existing codebase (???)
  • Add dts-linter pre-commit hook and move ownership of the hook to zmkfirmware or kylebonnici if desired.
  • Add a GHA check for formatting of Devicetree files for new PRs
  • Document formatter usage

If those sound like useful additions, I'd be happy to draft PRs to implement any that make sense.

Open questions

  • Formatter setup: dts-linter allows for a few custom settings. Do the following make sense?

    • Indent with spaces using 4 spaces
    • Max linewidth of 120 (except when guarded with dts-format off)
    • Otherwise apply the Zephyr Style
  • Formatting fences: If reformatting of the existing codebase is desired, what should be fenced off?

    • Keymap bindings if currently manually aligned (yes?)
    • bindings for 2x2 test keymaps (no?)
    • Matrix transform maps if currently manually aligned (??)
    • Physical layout keys if w, h, x, y, rot, rx, ry is aligned (yes?)
    • Anything else?
  • Config file: dts-linter currently doesn't have the option to add a configuration file. This isn't a problem for the pre-commit hook or when configuring the LSP through the editor, but for local development on the CLI it's a nuisance. We can either try to convince @kylebonnici to add a config option or add a small shell-wrapper to the zmk repo that calls dts-linter with the appropriate CLI args.

Diff against current codebase

https://github.com/zmkfirmware/zmk/compare/main...urob:zmk:dts-linter-diff?expand=1

A few observations:

  • Manual aligned arrays require dts-format off fences (see above)
  • Lack of placement formatting for in-line comments. Mainly a consistency issue?
  • Lot's of changes due to applying the Zephyr Style Guide (I find them largely sensible)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions