Skip to content

Commit 0e457a3

Browse files
committed
Format the code before the keymaps.
1 parent f0f8ba4 commit 0e457a3

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "qmkfmt"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55
license = "MIT"
66
description = "Formatter for QMK keymaps"

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ fn format(text: &str, output: &mut impl Write, cli: &Cli) {
9797
let keymaps = find_keymaps(&language, &tree, &text).expect("No keymaps found");
9898
let prefix = &text.as_bytes()[0..keymaps.start_byte()];
9999
let prefix = str::from_utf8(prefix).expect("Text is not utf-8");
100-
write!(output, "{prefix}").expect("Failed to write prefix");
100+
let prefix = clang_format(prefix);
101+
102+
// clang-format will strip trailing newlines here, but we want to
103+
// keep a space between the prefix and the keymaps, so use writeln
104+
writeln!(output, "{prefix}").expect("Failed to write prefix");
101105
let mut last_byte = keymaps.start_byte();
102106

103107
let query = tree_sitter::Query::new(

tests/snapshots/integration_test__fmt_moonlander.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ expression: actual
1515
#define LYR_FUN 5
1616

1717
enum custom_keycodes {
18-
RGB_SLD = ML_SAFE_RANGE,
18+
RGB_SLD = ML_SAFE_RANGE,
1919
};
2020

2121
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

0 commit comments

Comments
 (0)