[BACK]Return to shell.go CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / pkgsrc / pkgtools / pkglint / files

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /pkgsrc/pkgtools/pkglint/files/Attic/shell.go between version 1.50 and 1.51

version 1.50, 2019/11/27 22:10:07 version 1.51, 2019/12/02 23:32:09
Line 57  func (scc *SimpleCommandChecker) checkCo
Line 57  func (scc *SimpleCommandChecker) checkCo
                 break                  break
         case matches(shellword, `\$\{(PKGSRCDIR|PREFIX)(:Q)?\}`):          case matches(shellword, `\$\{(PKGSRCDIR|PREFIX)(:Q)?\}`):
                 break                  break
         case scc.handleComment():  
                 break  
         default:          default:
                 if G.Opts.WarnExtra && !scc.MkLines.indentation.DependsOn("OPSYS") {                  if G.Opts.WarnExtra && !scc.MkLines.indentation.DependsOn("OPSYS") {
                         scc.mkline.Warnf("Unknown shell command %q.", shellword)                          scc.mkline.Warnf("Unknown shell command %q.", shellword)
Line 145  func (scc *SimpleCommandChecker) handleS
Line 143  func (scc *SimpleCommandChecker) handleS
         return false          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() {  func (scc *SimpleCommandChecker) checkRegexReplace() {
         if trace.Tracing {          if trace.Tracing {
                 defer trace.Call0()()                  defer trace.Call0()()
Line 575  func NewShellLineChecker(mklines *MkLine
Line 536  func NewShellLineChecker(mklines *MkLine
         return &ShellLineChecker{mklines, mkline, true}          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) {  func (ck *ShellLineChecker) CheckShellCommands(shellcmds string, time ToolTime) {
         setE := true          setE := true
         ck.CheckShellCommand(shellcmds, &setE, time)          ck.CheckShellCommand(shellcmds, &setE, time)
Line 630  func (ck *ShellLineChecker) CheckShellCo
Line 593  func (ck *ShellLineChecker) CheckShellCo
         }          }
   
         ck.CheckShellCommand(lexer.Rest(), &setE, RunTime)          ck.CheckShellCommand(lexer.Rest(), &setE, RunTime)
           ck.checkMultiLineComment()
 }  }
   
 func (ck *ShellLineChecker) checkHiddenAndSuppress(hiddenAndSuppress, rest string) {  func (ck *ShellLineChecker) checkHiddenAndSuppress(hiddenAndSuppress, rest string) {
Line 1029  func (ck *ShellLineChecker) checkInstall
Line 993  func (ck *ShellLineChecker) checkInstall
         }          }
 }  }
   
   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{}) {  func (ck *ShellLineChecker) Errorf(format string, args ...interface{}) {
         ck.mkline.Errorf(format, args...)          ck.mkline.Errorf(format, args...)
 }  }

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.51

CVSweb <webmaster@jp.NetBSD.org>