Skip to content

zig fmt does not support doc comments on function parameters without trailing comma #25267

@Toxaris

Description

@Toxaris

Zig Version

0.15.1

Steps to Reproduce

zig fmt --stdin <<EOF
fn f(
    /// comment
    x: u32,
    y: u32
) void {}
EOF

Observed Behavior

fn f(/// comment
x: u32, y: u32) void {}

Expected Behavior

fn f(
    /// comment
    x: u32,
    y: u32,
) void {}

Further thoughts

  1. This means zig fmt is not idempotent because the following errors out ("same line documentation comment"):

    zig fmt --stdin <<EOF | zig fmt --stdin
    fn f(
        /// comment
        x: u32,
        y: u32
    ) void {}
    EOF
  2. It works with a trailing comma after the last parameter:

    zig fmt --stdin <<EOF
    fn f(
        /// comment
        x: u32,
        y: u32,
    ) void {}
    EOF
  3. It works for regular comments even without a trailing comma after the last parameter:

    zig fmt --stdin <<EOF
    fn f(
        // comment
        x: u32,
        y: u32
    ) void {}
    EOF

I found some issue about similar problems that are supposedly fixed. Maybe this got fixed in the past for // but not for /// for some reason?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions