Skip to content

Commit

Permalink
Note redundant semicolons at the end of a shell command
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Sep 12, 2024
1 parent eefc3bb commit cce87d9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion v23/mklinechecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
8 changes: 8 additions & 0 deletions v23/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions v23/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit cce87d9

Please sign in to comment.