diff --git a/v23/mklinechecker_test.go b/v23/mklinechecker_test.go index e291e222..4d547587 100644 --- a/v23/mklinechecker_test.go +++ b/v23/mklinechecker_test.go @@ -1153,5 +1153,7 @@ func (s *Suite) Test_MkLineChecker_checkDependencyTarget(c *check.C) { mklines.Check() t.CheckOutputLines( - "WARN: filename.mk:3: Undeclared target \"unknown-target\".") + "WARN: filename.mk:3: Undeclared target \"unknown-target\".", + "NOTE: filename.mk:4: A trailing semicolon "+ + "at the end of a shell command line is redundant.") } diff --git a/v23/shell.go b/v23/shell.go index eb58c793..7474845c 100644 --- a/v23/shell.go +++ b/v23/shell.go @@ -610,6 +610,14 @@ func (ck *ShellLineChecker) CheckShellCommandLine(shelltext string) { ck.CheckShellCommand(lexer.Rest(), &setE, RunTime) ck.checkMultiLineComment() + if hasSuffix(shelltext, ";") && !contains(shelltext, "#") { + fix := line.Autofix() + fix.Notef("A trailing semicolon at the end of a shell command line is redundant.") + if strings.Count(shelltext, ";") == 1 { + fix.Replace(";", "") + } + fix.Apply() + } } func (ck *ShellLineChecker) checkHiddenAndSuppress(hiddenAndSuppress, rest string) { diff --git a/v23/shell_test.go b/v23/shell_test.go index a3fc78f3..0ea9b675 100644 --- a/v23/shell_test.go +++ b/v23/shell_test.go @@ -1347,6 +1347,22 @@ func (s *Suite) Test_ShellLineChecker_CheckShellCommandLine__install_option_d(c "NOTE: filename.mk:1: You can use \"INSTALLATION_DIRS+= dir2\" instead of \"${INSTALL} -d\".") } +func (s *Suite) Test_ShellLineChecker_CheckShellCommandLine__trailing_semicolon(c *check.C) { + t := s.Init(c) + t.SetUpTool("mkdir", "", AfterPrefsMk) + + mklines := t.NewMkLines("Makefile", + MkCvsID, + "do-configure:", + "\tmkdir -p dirname;") + + mklines.Check() + + t.CheckOutputLines( + "NOTE: Makefile:3: A trailing semicolon " + + "at the end of a shell command line is redundant.") +} + func (s *Suite) Test_ShellLineChecker_checkHiddenAndSuppress(c *check.C) { t := s.Init(c)