pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint pkgtools/pkglint: update to 5.6.7



details:   https://anonhg.NetBSD.org/pkgsrc/rev/5fedf58913f9
branches:  trunk
changeset: 326209:5fedf58913f9
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Dec 02 01:57:48 2018 +0000

description:
pkgtools/pkglint: update to 5.6.7

Changes since 5.6.6:

User-defined variables that are not yet added to BUILD_DEFS are only
reported once per file.

Unnecessary space after variable names is only worth a note instead of
a warning. Example:

        MASTER_SITES =  https://cdn.example.org/

All variable names that are defined in the pkgsrc infrastructure are
assumed to be available to the package Makefiles. This reduces the
number of wrong "used but not defined" warnings, at the expense of

Variable names that are used in other variable names are checked
whether they are defined somewhere. Example:

        CFLAGS+=        ${CFLAGS.${PARAM}}      # PARAM is now checked

In SUBST_SED, when the pattern is s,@VAR@,${VAR}, or a slight variant
thereof, pkglint suggests to define SUBST_VARS instead, which frees the
package author from thinking about how to escape special characters and
is generally easier to read. Example:

        SUBST_SED.class=        s,@VAR@,${VAR:Q},

        SUBST_VARS.class=       VAR

Directives like .if !defined(...) are now handled the same whether or
not there is a space after before the (...).

The check for locally modified files now works independently of the
timezone.

As always, lots of refactorings have happened under the hood. Many small
bugs have been discovered and fixed accordingly.

diffstat:

 pkgtools/pkglint/Makefile                           |    4 +-
 pkgtools/pkglint/files/alternatives.go              |    8 +-
 pkgtools/pkglint/files/alternatives_test.go         |    7 +-
 pkgtools/pkglint/files/autofix.go                   |   75 +-
 pkgtools/pkglint/files/autofix_test.go              |  116 ++-
 pkgtools/pkglint/files/buildlink3.go                |    2 +-
 pkgtools/pkglint/files/buildlink3_test.go           |   15 +-
 pkgtools/pkglint/files/check_test.go                |  110 +-
 pkgtools/pkglint/files/distinfo.go                  |   44 +-
 pkgtools/pkglint/files/distinfo_test.go             |    2 +-
 pkgtools/pkglint/files/files.go                     |   40 +-
 pkgtools/pkglint/files/files_test.go                |   38 +-
 pkgtools/pkglint/files/getopt/getopt.go             |   65 +-
 pkgtools/pkglint/files/getopt/getopt_test.go        |  142 +++-
 pkgtools/pkglint/files/intqa/ideas.go               |   17 +
 pkgtools/pkglint/files/intqa/testnames.go           |   90 +-
 pkgtools/pkglint/files/licenses.go                  |   33 +-
 pkgtools/pkglint/files/licenses/licenses.go         |   16 +-
 pkgtools/pkglint/files/licenses_test.go             |   65 +-
 pkgtools/pkglint/files/line.go                      |  108 +-
 pkgtools/pkglint/files/line_test.go                 |  100 +-
 pkgtools/pkglint/files/linechecker.go               |  107 +-
 pkgtools/pkglint/files/linechecker_test.go          |  111 ++-
 pkgtools/pkglint/files/lines.go                     |   54 +-
 pkgtools/pkglint/files/lines_test.go                |   54 +
 pkgtools/pkglint/files/logging.go                   |  336 +++++---
 pkgtools/pkglint/files/logging_test.go              |  661 +++++++++++++++++-
 pkgtools/pkglint/files/mkline.go                    |  727 +++++++++++--------
 pkgtools/pkglint/files/mkline_test.go               |  455 +++++++++---
 pkgtools/pkglint/files/mklinechecker.go             |  558 +++++++++-----
 pkgtools/pkglint/files/mklinechecker_test.go        |  196 +++-
 pkgtools/pkglint/files/mklines.go                   |   16 +-
 pkgtools/pkglint/files/mklines_test.go              |   99 +-
 pkgtools/pkglint/files/mkparser.go                  |  329 +++++---
 pkgtools/pkglint/files/mkparser_test.go             |  223 +++---
 pkgtools/pkglint/files/mkshparser.go                |    2 +-
 pkgtools/pkglint/files/mkshparser_test.go           |    1 +
 pkgtools/pkglint/files/mkshtypes.go                 |    8 +-
 pkgtools/pkglint/files/mkshwalker_test.go           |    8 +-
 pkgtools/pkglint/files/mktypes.go                   |    6 +-
 pkgtools/pkglint/files/options.go                   |   16 +-
 pkgtools/pkglint/files/package.go                   |  144 ++-
 pkgtools/pkglint/files/package_test.go              |    2 +-
 pkgtools/pkglint/files/parser.go                    |   77 +-
 pkgtools/pkglint/files/parser_test.go               |   54 +-
 pkgtools/pkglint/files/patches.go                   |   22 +-
 pkgtools/pkglint/files/patches_test.go              |   10 +-
 pkgtools/pkglint/files/pkglint.go                   |  334 ++++-----
 pkgtools/pkglint/files/pkglint_test.go              |  152 ++-
 pkgtools/pkglint/files/pkgsrc.go                    |  103 +-
 pkgtools/pkglint/files/pkgsrc_test.go               |   69 +-
 pkgtools/pkglint/files/plist.go                     |   44 +-
 pkgtools/pkglint/files/plist_test.go                |   18 +-
 pkgtools/pkglint/files/shell.go                     |  326 ++++----
 pkgtools/pkglint/files/shell.y                      |    6 +-
 pkgtools/pkglint/files/shell_test.go                |  311 ++++++--
 pkgtools/pkglint/files/shtokenizer.go               |  351 +++++----
 pkgtools/pkglint/files/shtokenizer_test.go          |  174 +++-
 pkgtools/pkglint/files/shtypes.go                   |   19 +-
 pkgtools/pkglint/files/shtypes_test.go              |   10 +-
 pkgtools/pkglint/files/substcontext.go              |   62 +-
 pkgtools/pkglint/files/substcontext_test.go         |   52 +-
 pkgtools/pkglint/files/textproc/lexer.go            |  108 ++-
 pkgtools/pkglint/files/textproc/lexer_bench_test.go |  189 +++++
 pkgtools/pkglint/files/textproc/lexer_test.go       |  168 +++-
 pkgtools/pkglint/files/tools.go                     |   19 +-
 pkgtools/pkglint/files/tools_test.go                |   19 +-
 pkgtools/pkglint/files/toplevel.go                  |    6 +-
 pkgtools/pkglint/files/trace/tracing.go             |   27 +-
 pkgtools/pkglint/files/util.go                      |  253 ++++--
 pkgtools/pkglint/files/util_test.go                 |   98 ++-
 pkgtools/pkglint/files/vardefs.go                   |   12 +-
 pkgtools/pkglint/files/vardefs_test.go              |    3 +-
 pkgtools/pkglint/files/vartype.go                   |   20 +-
 pkgtools/pkglint/files/vartype_test.go              |    2 +-
 pkgtools/pkglint/files/vartypecheck.go              |  132 +-
 pkgtools/pkglint/files/vartypecheck_test.go         |  416 ++++++-----
 77 files changed, 5754 insertions(+), 3122 deletions(-)

diffs (truncated from 16696 to 300 lines):

diff -r 72fa3ea82424 -r 5fedf58913f9 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun Dec 02 00:49:06 2018 +0000
+++ b/pkgtools/pkglint/Makefile Sun Dec 02 01:57:48 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.558 2018/11/11 20:55:23 rillig Exp $
+# $NetBSD: Makefile,v 1.559 2018/12/02 01:57:48 rillig Exp $
 
-PKGNAME=       pkglint-5.6.6
+PKGNAME=       pkglint-5.6.7
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 72fa3ea82424 -r 5fedf58913f9 pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go    Sun Dec 02 00:49:06 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives.go    Sun Dec 02 01:57:48 2018 +0000
@@ -2,8 +2,8 @@
 
 import "strings"
 
-func CheckfileAlternatives(fileName string) {
-       lines := Load(fileName, NotEmpty|LogErrors)
+func CheckfileAlternatives(filename string) {
+       lines := Load(filename, NotEmpty|LogErrors)
        if lines == nil {
                return
        }
@@ -32,7 +32,7 @@
                        }
 
                        fix := line.Autofix()
-                       fix.Notef("@PREFIX@/ can be omitted from the file name.")
+                       fix.Notef("@PREFIX@/ can be omitted from the filename.")
                        fix.Explain(
                                "The alternative implementation is always interpreted relative to",
                                "${PREFIX}.")
@@ -40,7 +40,7 @@
                        fix.Apply()
                } else {
                        line.Errorf("Invalid ALTERNATIVES line %q.", line.Text)
-                       Explain(
+                       G.Explain(
                                sprintf("Run %q for more information.", makeHelp("alternatives")))
                }
        }
diff -r 72fa3ea82424 -r 5fedf58913f9 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go       Sun Dec 02 00:49:06 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go       Sun Dec 02 01:57:48 2018 +0000
@@ -22,9 +22,10 @@
        G.CheckDirent(".")
 
        t.CheckOutputLines(
-               "ERROR: ALTERNATIVES:1: Alternative implementation \"@PREFIX@/sbin/sendmail.postfix@POSTFIXVER@\" must appear in the PLIST as \"sbin/sendmail.postfix${POSTFIXVER}\".",
-               "NOTE: ALTERNATIVES:1: @PREFIX@/ can be omitted from the file name.",
-               "NOTE: ALTERNATIVES:2: @PREFIX@/ can be omitted from the file name.",
+               "ERROR: ALTERNATIVES:1: Alternative implementation \"@PREFIX@/sbin/sendmail.postfix@POSTFIXVER@\" "+
+                       "must appear in the PLIST as \"sbin/sendmail.postfix${POSTFIXVER}\".",
+               "NOTE: ALTERNATIVES:1: @PREFIX@/ can be omitted from the filename.",
+               "NOTE: ALTERNATIVES:2: @PREFIX@/ can be omitted from the filename.",
                "ERROR: ALTERNATIVES:3: Alternative wrapper \"bin/echo\" must not appear in the PLIST.",
                "ERROR: ALTERNATIVES:3: Alternative implementation \"bin/gnu-echo\" must appear in the PLIST.",
                "ERROR: ALTERNATIVES:5: Invalid ALTERNATIVES line \"invalid\".")
diff -r 72fa3ea82424 -r 5fedf58913f9 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sun Dec 02 00:49:06 2018 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sun Dec 02 01:57:48 2018 +0000
@@ -99,7 +99,7 @@
                if rawLine.Lineno != 0 {
                        replaced := strings.Replace(rawLine.textnl, prefix+from, prefix+to, 1)
                        if replaced != rawLine.textnl {
-                               if G.Opts.ShowAutofix || G.Opts.Autofix {
+                               if G.Logger.IsAutofix() {
                                        rawLine.textnl = replaced
                                }
                                fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
@@ -136,7 +136,7 @@
 
                        replaced := replaceAllFunc(rawLine.textnl, from, replace)
                        if replaced != rawLine.textnl {
-                               if G.Opts.ShowAutofix || G.Opts.Autofix {
+                               if G.Logger.IsAutofix() {
                                        rawLine.textnl = replaced
                                }
                                for _, fromText := range froms {
@@ -175,7 +175,7 @@
                return
        }
 
-       fixer(G.Opts.ShowAutofix, G.Opts.Autofix)
+       fixer(G.Logger.Opts.ShowAutofix, G.Logger.Opts.Autofix)
 }
 
 // Describef is used while Autofix.Custom is called to remember a description
@@ -193,7 +193,7 @@
                return
        }
 
-       if G.Opts.ShowAutofix || G.Opts.Autofix {
+       if G.Logger.IsAutofix() {
                fix.linesBefore = append(fix.linesBefore, text+"\n")
        }
        fix.Describef(fix.line.raw[0].Lineno, "Inserting a line %q before this line.", text)
@@ -207,7 +207,7 @@
                return
        }
 
-       if G.Opts.ShowAutofix || G.Opts.Autofix {
+       if G.Logger.IsAutofix() {
                fix.linesAfter = append(fix.linesAfter, text+"\n")
        }
        fix.Describef(fix.line.raw[len(fix.line.raw)-1].Lineno, "Inserting a line %q after this line.", text)
@@ -223,7 +223,7 @@
        }
 
        for _, line := range fix.line.raw {
-               if G.Opts.ShowAutofix || G.Opts.Autofix {
+               if G.Logger.IsAutofix() {
                        line.textnl = ""
                }
                fix.Describef(line.Lineno, "Deleting this line.")
@@ -244,7 +244,7 @@
        // To fix this assertion, call one of Autofix.Errorf, Autofix.Warnf
        // or Autofix.Notef before calling Apply.
        G.Assertf(
-               fix.level != nil && fix.diagFormat != "",
+               fix.level != nil,
                "Each autofix must have a log level and a diagnostic.")
 
        reset := func() {
@@ -256,22 +256,23 @@
                fix.autofixShortTerm = autofixShortTerm{}
        }
 
-       G.explainNext = shallBeLogged(fix.diagFormat)
-       if !G.explainNext || len(fix.actions) == 0 {
+       if !G.Logger.Relevant(fix.diagFormat) || len(fix.actions) == 0 {
                reset()
                return
        }
 
-       logDiagnostic := (G.Opts.ShowAutofix || !G.Opts.Autofix) &&
+       logDiagnostic := (G.Logger.Opts.ShowAutofix || !G.Logger.Opts.Autofix) &&
                fix.diagFormat != SilentAutofixFormat
-       logFix := G.Opts.Autofix || G.Opts.ShowAutofix
+       logFix := G.Logger.IsAutofix()
 
        if logDiagnostic {
+               msg := fmt.Sprintf(fix.diagFormat, fix.diagArgs...)
                if !logFix {
-                       line.showSource(G.logOut)
+                       if fix.diagFormat == AutofixFormat || G.Logger.FirstTime(line.Filename, line.Linenos(), msg) {
+                               line.showSource(G.out)
+                       }
                }
-               msg := fmt.Sprintf(fix.diagFormat, fix.diagArgs...)
-               logf(fix.level, line.FileName, line.Linenos(), fix.diagFormat, msg)
+               G.Logf(fix.level, line.Filename, line.Linenos(), fix.diagFormat, msg)
        }
 
        if logFix {
@@ -280,20 +281,20 @@
                        if action.lineno != 0 {
                                lineno = strconv.Itoa(action.lineno)
                        }
-                       logf(AutofixLogLevel, line.FileName, lineno, AutofixFormat, action.description)
+                       G.Logf(AutofixLogLevel, line.Filename, lineno, AutofixFormat, action.description)
                }
        }
 
        if logDiagnostic || logFix {
                if logFix {
-                       line.showSource(G.logOut)
+                       line.showSource(G.out)
                }
                if logDiagnostic && len(fix.explanation) > 0 {
-                       Explain(fix.explanation...)
+                       G.Explain(fix.explanation...)
                }
-               if G.Opts.ShowSource {
-                       if !G.Opts.Explain || !logDiagnostic || len(fix.explanation) == 0 {
-                               G.logOut.Separate()
+               if G.Logger.Opts.ShowSource {
+                       if !G.Logger.Opts.Explain || !logDiagnostic || len(fix.explanation) == 0 {
+                               G.out.Separate()
                        }
                }
        }
@@ -348,11 +349,11 @@
 
        for _, rawLine := range fix.line.raw[1:] {
                _, comment, oldSpace := match2(rawLine.textnl, `^(#?)([ \t]*)`)
-               newWidth := tabWidth(oldSpace) - oldWidth + newWidth
-               newSpace := strings.Repeat("\t", newWidth/8) + strings.Repeat(" ", newWidth%8)
+               newLineWidth := tabWidth(oldSpace) - oldWidth + newWidth
+               newSpace := strings.Repeat("\t", newLineWidth/8) + strings.Repeat(" ", newLineWidth%8)
                replaced := strings.Replace(rawLine.textnl, comment+oldSpace, comment+newSpace, 1)
                if replaced != rawLine.textnl {
-                       if G.Opts.ShowAutofix || G.Opts.Autofix {
+                       if G.Logger.IsAutofix() {
                                rawLine.textnl = replaced
                        }
                        fix.Describef(rawLine.Lineno, "Replacing indentation %q with %q.", oldSpace, newSpace)
@@ -380,7 +381,7 @@
                fix.diagFormat != "",
                "Autofix: The diagnostic must be given before the action.")
        // This check is necessary for the --only command line option.
-       return !shallBeLogged(fix.diagFormat)
+       return !G.shallBeLogged(fix.diagFormat)
 }
 
 func (fix *Autofix) assertRealLine() {
@@ -397,13 +398,13 @@
        }
 
        // Fast lane for the case that nothing is written back to disk.
-       if !G.Opts.Autofix {
+       if !G.Logger.Opts.Autofix {
                for _, line := range lines.Lines {
                        if line.autofix != nil && line.autofix.modified {
                                G.autofixAvailable = true
-                               if G.Opts.ShowAutofix {
+                               if G.Logger.Opts.ShowAutofix {
                                        // Only in this case can the loaded lines be modified.
-                                       G.fileCache.Evict(line.FileName)
+                                       G.fileCache.Evict(line.Filename)
                                }
                        }
                }
@@ -413,10 +414,10 @@
        changes := make(map[string][]string)
        changed := make(map[string]bool)
        for _, line := range lines.Lines {
-               chlines := changes[line.FileName]
+               chlines := changes[line.Filename]
                if fix := line.autofix; fix != nil {
                        if fix.modified {
-                               changed[line.FileName] = true
+                               changed[line.Filename] = true
                        }
                        chlines = append(chlines, fix.linesBefore...)
                        for _, raw := range line.raw {
@@ -428,25 +429,25 @@
                                chlines = append(chlines, raw.textnl)
                        }
                }
-               changes[line.FileName] = chlines
+               changes[line.Filename] = chlines
        }
 
-       for fileName := range changed {
-               G.fileCache.Evict(fileName)
-               changedLines := changes[fileName]
-               tmpName := fileName + ".pkglint.tmp"
+       for filename := range changed {
+               G.fileCache.Evict(filename)
+               changedLines := changes[filename]
+               tmpName := filename + ".pkglint.tmp"
                text := ""
                for _, changedLine := range changedLines {
                        text += changedLine
                }
                err := ioutil.WriteFile(tmpName, []byte(text), 0666)
                if err != nil {
-                       logf(Error, tmpName, "", "Cannot write: %s", "Cannot write: "+err.Error())
+                       G.Logf(Error, tmpName, "", "Cannot write: %s", "Cannot write: "+err.Error())
                        continue
                }
-               err = os.Rename(tmpName, fileName)
+               err = os.Rename(tmpName, filename)
                if err != nil {
-                       logf(Error, tmpName, "",
+                       G.Logf(Error, tmpName, "",
                                "Cannot overwrite with autofixed content: %s",
                                "Cannot overwrite with autofixed content: "+err.Error())
                        continue
diff -r 72fa3ea82424 -r 5fedf58913f9 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Sun Dec 02 00:49:06 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Sun Dec 02 01:57:48 2018 +0000
@@ -101,8 +101,8 @@
                "AUTOFIX: ~/Makefile:1: Replacing \"n\" with \"v\".",
                "-\t# line 1 \\",
                "+\t# live 1 \\",
-               ">\tcontinuation 1 \\",
-               ">\tcontinuation 2")
+               "\tcontinuation 1 \\",
+               "\tcontinuation 2")
 }
 
 func (s *Suite) Test_Autofix_ReplaceRegex__show_autofix(c *check.C) {
@@ -261,7 +261,7 @@
 
        t.SetupCommandLine("--show-autofix", "--explain")
 
-       line := t.NewLine("fileName", 1, "original")
+       line := t.NewLine("filename", 1, "original")
 
        c.Check(line.autofix, check.IsNil)
        c.Check(line.raw, check.DeepEquals, t.NewRawLines(1, "original\n"))
@@ -276,7 +276,7 @@
        c.Check(line.autofix, check.NotNil)
        c.Check(line.raw, check.DeepEquals, t.NewRawLines(1, "original\n", "lriginao\n"))
        t.CheckOutputLines(



Home | Main Index | Thread Index | Old Index