Warn for unindented case switches

Bug #1698091 reported by Austin English
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
bash8
New
Undecided
Unassigned

Bug Description

I've got some legacy code that does:

case foo in
asdf) echo hi ;;
f) echo hi ;;
*) echo foo ;;
esac

I'd like to see a warning, as it should be:
case foo in
    asdf) echo hi ;;
    f) echo hi ;;
    *) echo foo ;;
esac

an automated check for that would be very helpful!

Revision history for this message
mcandre (andrew-pennebaker) wrote :

Alternatively, shfmt recommends maintaining the same indentation level for each pattern as the opening "case" keyword. Yes, this is a somewhat subjective choice, but as there is now a semistandard tool for styling shell script code, we might as well follow it:

https://github.com/mvdan/sh

So bashate could offer an optional setting for a case indentation preference, but should default to shfmt style so that these two powerful tools do not clash.

Revision history for this message
Austin English (austinenglish) wrote :

shfmt is a new one, hadn't heard of it. I don't know how widespread their standard is.

OTOH, Google's style guide (which a lot of individuals and projects follow), recommends indenting one level:

""""""
    Indent alternatives by 2 spaces.
    A one-line alternative needs a space after the close parenthesis of the pattern and before the ;;.
    Long or multi-command alternatives should be split over multiple lines with the pattern, actions, and ;; on separate lines.

The matching expressions are indented one level from the 'case' and 'esac'. Multiline actions are indented another level. In general, there is no need to quote match expressions. Pattern expressions should not be preceded by an open parenthesis. Avoid the ;& and ;;& notations.
""""""

https://google.github.io/styleguide/shell.xml#Case_statement

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.