Skip to content

syntax: case clause formatting can add empty line when removing a newline #779

Closed
@ainar-g

Description

Before:

case "$x"
in
(0)
        echo 'none!'
        ;;
(1)
        echo 'it'"'"'s one!'
        ;;
(*)
        echo 'something!'
        ;;
esac

After shfmt -p -s:

#!/bin/sh

set -e -f -u -x

x="${1:-0}"
readonly x

case "$x" in

0)
        echo 'none!'
        ;;
1)
        echo 'it'"'"'s one!'
        ;;
*)
        echo 'something!'
        ;;
esac

POSIX allows case items to start with a parenthesis, and I prefer it, because it makes case look more understandable, imo. I would like an option to either add them or at least not remove them.

(Also, I've noticed that shfmt seems to add an empty line after case … in, which looks like a bug.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions