diff options
author | rillig <rillig@pkgsrc.org> | 2019-12-02 23:32:09 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2019-12-02 23:32:09 +0000 |
commit | 5377c50298528311f0bcefc9ed218493115964ce (patch) | |
tree | 7c1090453caf98d02038142e538c457b30085e97 /pkgtools/pkglint/files/shell.go | |
parent | faa58f4289200c48fa0fba875743330ea06728bf (diff) | |
download | pkgsrc-5377c50298528311f0bcefc9ed218493115964ce.tar.gz |
pkgtools/pkglint: update to 19.3.13
Changes since 19.3.12:
The command line option -Wspace has been removed. Warnings and notes
about whitespace are now generated by default and cannot be switched
off. This is to ensure a consistent visual appearance of the package
Makefiles.
Shell programs that are indented unnecessarily deep generate a note by
default now. Before, the option -Wall was necessary to get these notes.
The check for unintended comments in multi-line shell programs is now
enabled again. It had been disabled some time ago as byproduct of a bug
fix in the shell parser.
The check for unique buildlink3 package identifiers now also works if
pkglint is run from a package directory instead of the pkgsrc root
directory.
Diffstat (limited to 'pkgtools/pkglint/files/shell.go')
-rw-r--r-- | pkgtools/pkglint/files/shell.go | 92 |
1 files changed, 53 insertions, 39 deletions
diff --git a/pkgtools/pkglint/files/shell.go b/pkgtools/pkglint/files/shell.go index 98d3db152ed..98be396918d 100644 --- a/pkgtools/pkglint/files/shell.go +++ b/pkgtools/pkglint/files/shell.go @@ -57,8 +57,6 @@ func (scc *SimpleCommandChecker) checkCommandStart() { break case matches(shellword, `\$\{(PKGSRCDIR|PREFIX)(:Q)?\}`): break - case scc.handleComment(): - break default: if G.Opts.WarnExtra && !scc.MkLines.indentation.DependsOn("OPSYS") { scc.mkline.Warnf("Unknown shell command %q.", shellword) @@ -145,43 +143,6 @@ func (scc *SimpleCommandChecker) handleShellBuiltin() bool { return false } -func (scc *SimpleCommandChecker) handleComment() bool { - if trace.Tracing { - defer trace.Call0()() - } - - shellword := scc.strcmd.Name - if trace.Tracing { - defer trace.Call1(shellword)() - } - - if !hasPrefix(shellword, "#") { - return false - } - - if !scc.mkline.IsMultiline() { - return false - } - - scc.mkline.Warnf("A shell comment does not stop at the end of line.") - scc.Explain( - "When a shell command is split into multiple lines that are", - "continued with a backslash, they will nevertheless be converted to", - "a single line before the shell sees them.", - "", - "This means that even if it looks as if the comment only spanned", - "one line in the Makefile, in fact it spans until the end of the whole", - "shell command.", - "", - "To insert a comment into shell code, you can write it like this:", - "", - "\t"+"${SHCOMMENT} \"The following command might fail; this is ok.\"", - "", - "Note that any special characters in the comment are still", - "interpreted by the shell.") - return true -} - func (scc *SimpleCommandChecker) checkRegexReplace() { if trace.Tracing { defer trace.Call0()() @@ -575,6 +536,8 @@ func NewShellLineChecker(mklines *MkLines, mkline *MkLine) *ShellLineChecker { return &ShellLineChecker{mklines, mkline, true} } +// CheckShellCommands checks for a list of shell commands, of which each one +// is terminated with a semicolon. These are used in GENERATE_PLIST. func (ck *ShellLineChecker) CheckShellCommands(shellcmds string, time ToolTime) { setE := true ck.CheckShellCommand(shellcmds, &setE, time) @@ -630,6 +593,7 @@ func (ck *ShellLineChecker) CheckShellCommandLine(shelltext string) { } ck.CheckShellCommand(lexer.Rest(), &setE, RunTime) + ck.checkMultiLineComment() } func (ck *ShellLineChecker) checkHiddenAndSuppress(hiddenAndSuppress, rest string) { @@ -1029,6 +993,56 @@ func (ck *ShellLineChecker) checkInstallCommand(shellcmd string) { } } +func (ck *ShellLineChecker) checkMultiLineComment() { + mkline := ck.mkline + if !mkline.IsMultiline() || !contains(mkline.Text, "#") { + return + } + + for _, line := range mkline.raw[:len(mkline.raw)-1] { + text := strings.TrimSuffix(line.textnl, "\\\n") + + tokens, rest := splitIntoShellTokens(nil, text) + if rest != "" { + return + } + + for _, token := range tokens { + if hasPrefix(token, "#") { + ck.warnMultiLineComment(line) + return + } + } + } +} + +func (ck *ShellLineChecker) warnMultiLineComment(raw *RawLine) { + text := strings.TrimSuffix(raw.textnl, "\n") + line := NewLine(ck.mkline.Filename, raw.Lineno, text, raw) + + line.Warnf("The shell comment does not stop at the end of this line.") + line.Explain( + "When a shell command is spread out on multiple lines that are", + "continued with a backslash, they will nevertheless be converted to", + "a single line before the shell sees them.", + "", + "This means that even if it looks as if the comment only spanned", + "one line in the Makefile, in fact it spans until the end of the whole", + "shell command.", + "", + "To insert a comment into shell code, you can write it like this:", + "", + "\t${SHCOMMENT} \"The following command might fail; this is ok.\"", + "", + "Note that any special characters in the comment are still", + "interpreted by the shell.", + "", + "If that is not possible, you can apply the :D modifier to the", + "variable with the empty name, which is guaranteed to be undefined:", + "", + "\t${:D this is commented out}") +} + func (ck *ShellLineChecker) Errorf(format string, args ...interface{}) { ck.mkline.Errorf(format, args...) } |