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 19.4.1



details:   https://anonhg.NetBSD.org/pkgsrc/rev/6bf0bc469093
branches:  trunk
changeset: 346914:6bf0bc469093
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Jan 04 19:53:13 2020 +0000

description:
pkgtools/pkglint: update to 19.4.1

Changes since 19.4.0:

The notes for inserting an empty line have been changed from "insert
after this line" to "insert before this line" to make the line numbers
in the diagnostics contiguous. There had been several places where the
diagnostics went from line 1 to line 2 and then back to line 1, which
was confusing.

The lines in ALTERNATIVES files are checked for trailing whitespace.
This is only for consistency with the other checks. In the whole pkgsrc
tree all ALTERNATIVES files are already fine.

The diagnostics for comments in .endif/.endfor lines that don't
correspond to their .if/.elif/.for counterparts now includes the exact
line number of the corresponding condition, to make the warning easier
to fix.

The diagnostics for wrong variable value alignment now mention the
current column in addition to the desired column, to make it easier to
see by how much and in which direction the indentation should be fixed.

Variables that are used in conditions before they are actually defined
need the :U modifier.

diffstat:

 pkgtools/pkglint/Makefile                      |    4 +-
 pkgtools/pkglint/PLIST                         |    3 +-
 pkgtools/pkglint/files/alternatives.go         |   19 +-
 pkgtools/pkglint/files/alternatives_test.go    |   11 +-
 pkgtools/pkglint/files/autofix.go              |   10 +-
 pkgtools/pkglint/files/autofix_test.go         |  123 ++++++++++++---
 pkgtools/pkglint/files/buildlink3.go           |   28 +-
 pkgtools/pkglint/files/buildlink3_test.go      |    7 +-
 pkgtools/pkglint/files/category.go             |   27 ++-
 pkgtools/pkglint/files/category_test.go        |   66 +++++++-
 pkgtools/pkglint/files/check_test.go           |   21 +-
 pkgtools/pkglint/files/distinfo.go             |    2 +-
 pkgtools/pkglint/files/distinfo_test.go        |   58 ++++++-
 pkgtools/pkglint/files/files.go                |   42 ++--
 pkgtools/pkglint/files/files_test.go           |   14 +-
 pkgtools/pkglint/files/licenses.go             |   11 +-
 pkgtools/pkglint/files/line.go                 |   10 +-
 pkgtools/pkglint/files/linechecker.go          |    8 +-
 pkgtools/pkglint/files/lineslexer.go           |    6 +-
 pkgtools/pkglint/files/logging.go              |    2 +-
 pkgtools/pkglint/files/mkassignchecker.go      |   14 +-
 pkgtools/pkglint/files/mkassignchecker_test.go |   78 ++++++---
 pkgtools/pkglint/files/mkcondchecker.go        |    5 +-
 pkgtools/pkglint/files/mkcondchecker_test.go   |   57 +++---
 pkgtools/pkglint/files/mklexer.go              |    6 +-
 pkgtools/pkglint/files/mkline.go               |   33 ++-
 pkgtools/pkglint/files/mkline_test.go          |   14 +-
 pkgtools/pkglint/files/mklinechecker.go        |   36 ++--
 pkgtools/pkglint/files/mklinechecker_test.go   |   23 +-
 pkgtools/pkglint/files/mklineparser.go         |    3 +-
 pkgtools/pkglint/files/mklineparser_test.go    |    6 +-
 pkgtools/pkglint/files/mklines.go              |  198 +++++++++++++----------
 pkgtools/pkglint/files/mklines_test.go         |   29 ++-
 pkgtools/pkglint/files/mkparser.go             |    5 +-
 pkgtools/pkglint/files/mkshwalker.go           |   30 ---
 pkgtools/pkglint/files/mkshwalker_test.go      |   33 +++-
 pkgtools/pkglint/files/mkvarusechecker.go      |   53 ++---
 pkgtools/pkglint/files/mkvarusechecker_test.go |    5 +-
 pkgtools/pkglint/files/options.go              |    6 +-
 pkgtools/pkglint/files/package.go              |   55 +++---
 pkgtools/pkglint/files/package_test.go         |  104 ++++++------
 pkgtools/pkglint/files/patches.go              |   10 +-
 pkgtools/pkglint/files/patches_test.go         |   76 ++++----
 pkgtools/pkglint/files/path_test.go            |    3 +-
 pkgtools/pkglint/files/pkglint.go              |   84 ++++-----
 pkgtools/pkglint/files/pkglint_test.go         |   76 +++++---
 pkgtools/pkglint/files/pkgsrc.go               |   51 +++--
 pkgtools/pkglint/files/pkgsrc_test.go          |   38 ++-
 pkgtools/pkglint/files/plist.go                |    4 +-
 pkgtools/pkglint/files/plist_test.go           |   28 +-
 pkgtools/pkglint/files/shell.go                |   29 +--
 pkgtools/pkglint/files/shell_test.go           |   37 ++-
 pkgtools/pkglint/files/shtokenizer.go          |    5 +-
 pkgtools/pkglint/files/shtokenizer_test.go     |   18 +-
 pkgtools/pkglint/files/substcontext.go         |   20 +-
 pkgtools/pkglint/files/substcontext_test.go    |   18 +-
 pkgtools/pkglint/files/textproc/lexer.go       |    8 +-
 pkgtools/pkglint/files/textproc/lexer_test.go  |   10 +
 pkgtools/pkglint/files/tools.go                |   10 +-
 pkgtools/pkglint/files/toplevel.go             |    4 +-
 pkgtools/pkglint/files/toplevel_test.go        |    5 +-
 pkgtools/pkglint/files/util.go                 |   79 +++++---
 pkgtools/pkglint/files/util_test.go            |    5 +-
 pkgtools/pkglint/files/varalignblock.go        |   42 +++-
 pkgtools/pkglint/files/varalignblock_test.go   |  203 +++++++++++++-----------
 pkgtools/pkglint/files/vardefs.go              |   10 +-
 pkgtools/pkglint/files/vargroups.go            |  181 ++++++++++-----------
 pkgtools/pkglint/files/vartypecheck.go         |   24 +-
 pkgtools/pkglint/files/vartypecheck_test.go    |   58 ++++---
 69 files changed, 1369 insertions(+), 1032 deletions(-)

diffs (truncated from 6074 to 300 lines):

diff -r 9800a31a3fbd -r 6bf0bc469093 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sat Jan 04 19:11:10 2020 +0000
+++ b/pkgtools/pkglint/Makefile Sat Jan 04 19:53:13 2020 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.621 2019/12/30 16:27:13 rillig Exp $
+# $NetBSD: Makefile,v 1.622 2020/01/04 19:53:13 rillig Exp $
 
-PKGNAME=       pkglint-19.4.0
+PKGNAME=       pkglint-19.4.1
 CATEGORIES=    pkgtools
 DISTNAME=      tools
 MASTER_SITES=  ${MASTER_SITE_GITHUB:=golang/}
diff -r 9800a31a3fbd -r 6bf0bc469093 pkgtools/pkglint/PLIST
--- a/pkgtools/pkglint/PLIST    Sat Jan 04 19:11:10 2020 +0000
+++ b/pkgtools/pkglint/PLIST    Sat Jan 04 19:53:13 2020 +0000
@@ -1,4 +1,4 @@
-@comment $NetBSD: PLIST,v 1.22 2019/12/15 01:29:06 rillig Exp $
+@comment $NetBSD: PLIST,v 1.23 2020/01/04 19:53:13 rillig Exp $
 bin/pkglint
 gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint.a
 gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/getopt.a
@@ -29,7 +29,6 @@
 gopkg/src/netbsd.org/pkglint/getopt/getopt_test.go
 gopkg/src/netbsd.org/pkglint/histogram/histogram.go
 gopkg/src/netbsd.org/pkglint/histogram/histogram_test.go
-gopkg/src/netbsd.org/pkglint/intqa/ideas.go
 gopkg/src/netbsd.org/pkglint/intqa/qa.go
 gopkg/src/netbsd.org/pkglint/intqa/qa_test.go
 gopkg/src/netbsd.org/pkglint/licenses.go
diff -r 9800a31a3fbd -r 6bf0bc469093 pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go    Sat Jan 04 19:11:10 2020 +0000
+++ b/pkgtools/pkglint/files/alternatives.go    Sat Jan 04 19:53:13 2020 +0000
@@ -5,14 +5,14 @@
        "strings"
 )
 
-func CheckFileAlternatives(filename CurrPath) {
+func CheckFileAlternatives(filename CurrPath, pkg *Package) {
        lines := Load(filename, NotEmpty|LogErrors)
        if lines == nil {
                return
        }
 
        var ck AlternativesChecker
-       ck.Check(lines, G.Pkg)
+       ck.Check(lines, pkg)
 }
 
 type AlternativesChecker struct{}
@@ -24,15 +24,14 @@
        }
 
        for _, line := range lines.Lines {
-               ck.checkLine(line, plistFiles)
+               ck.checkLine(line, plistFiles, pkg)
        }
 }
 
 // checkLine checks a single line for the following format:
 //  wrapper alternative [optional arguments]
-func (ck *AlternativesChecker) checkLine(line *Line, plistFiles map[RelPath]*PlistLine) {
-       // TODO: Add $ to the regex, just for confidence
-       m, wrapper, space, alternative := match3(line.Text, `^([^\t ]+)([ \t]+)([^\t ]+)`)
+func (ck *AlternativesChecker) checkLine(line *Line, plistFiles map[RelPath]*PlistLine, pkg *Package) {
+       m, wrapper, space, alternative := match3(line.Text, `^([^\t ]+)([ \t]+)([^\t ]+).*$`)
        if !m {
                line.Errorf("Invalid line %q.", line.Text)
                line.Explain(
@@ -44,10 +43,12 @@
                ck.checkWrapperPlist(line, NewRelPathString(wrapper), plistFiles)
        }
        if plistFiles != nil {
-               ck.checkAlternativePlist(line, alternative, plistFiles)
+               ck.checkAlternativePlist(line, alternative, plistFiles, pkg)
        }
 
        ck.checkAlternativeAbs(alternative, line, space)
+
+       LineChecker{line}.CheckTrailingWhitespace()
 }
 
 func (ck *AlternativesChecker) checkWrapperAbs(line *Line, wrapper Path) bool {
@@ -85,7 +86,7 @@
 }
 
 func (ck *AlternativesChecker) checkAlternativePlist(line *Line, alternative string,
-       plistFiles map[RelPath]*PlistLine) {
+       plistFiles map[RelPath]*PlistLine, pkg *Package) {
 
        relImplementation := strings.Replace(alternative, "@PREFIX@/", "", 1)
        plistName := replaceAll(relImplementation, `@(\w+)@`, "${$1}")
@@ -96,7 +97,7 @@
        }
 
        rel := NewRelPathString(plistName)
-       if plistFiles[rel] != nil || G.Pkg.vars.IsDefined("ALTERNATIVES_SRC") {
+       if plistFiles[rel] != nil || pkg.vars.IsDefined("ALTERNATIVES_SRC") {
                return
        }
        if plistFiles[rel.Replace("${PKGMANDIR}", "man")] != nil {
diff -r 9800a31a3fbd -r 6bf0bc469093 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go       Sat Jan 04 19:11:10 2020 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go       Sat Jan 04 19:53:13 2020 +0000
@@ -8,9 +8,9 @@
        t.Chdir("category/package")
        t.CreateFileLines("ALTERNATIVES")
 
-       G.Pkg = NewPackage(".")
+       pkg := NewPackage(".")
 
-       CheckFileAlternatives("ALTERNATIVES")
+       CheckFileAlternatives("ALTERNATIVES", pkg)
 
        t.CheckOutputLines(
                "ERROR: ALTERNATIVES: Must not be empty.")
@@ -92,7 +92,7 @@
                "bin/no-args @PREFIX@/bin/echo",
                "bin/with-args @PREFIX@/bin/echo hello,",
                "bin/with-quoted-args @PREFIX@/bin/echo \"hello, world\" \\ cowboy",
-               "bin/trailing @PREFIX@/bin/echo spaces ", // TODO: warn about this
+               "bin/trailing @PREFIX@/bin/echo spaces ",
                "/abs-echo @PREFIX@/bin/echo")
        t.CreateFileLines("PLIST",
                PlistCvsID,
@@ -102,7 +102,8 @@
        G.Check(".")
 
        t.CheckOutputLines(
-               "ERROR: ALTERNATIVES:5: Alternative wrapper \"/abs-echo\" " +
+               "NOTE: ALTERNATIVES:4: Trailing whitespace.",
+               "ERROR: ALTERNATIVES:5: Alternative wrapper \"/abs-echo\" "+
                        "must be relative to PREFIX.")
 }
 
@@ -113,7 +114,7 @@
                "relative @PREFIX@/bin/echo",
                "/absolute @PREFIX@/bin/echo")
 
-       CheckFileAlternatives(t.File("ALTERNATIVES"))
+       CheckFileAlternatives(t.File("ALTERNATIVES"), nil)
 
        t.CheckOutputLines(
                "ERROR: ~/ALTERNATIVES:2: Alternative wrapper \"/absolute\" " +
diff -r 9800a31a3fbd -r 6bf0bc469093 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sat Jan 04 19:11:10 2020 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sat Jan 04 19:53:13 2020 +0000
@@ -142,13 +142,6 @@
        assert(from != to)
        fix.assertRealLine()
 
-       // XXX: This should only affect the diagnostics, but not the modifications
-       //  to the text of the affected line, since that text will be used in
-       //  further checks.
-       if fix.skip() {
-               return
-       }
-
        rawLine := fix.line.raw[rawIndex]
        assert(textIndex < len(rawLine.textnl))
        assert(hasPrefix(rawLine.textnl[textIndex:], from))
@@ -166,6 +159,9 @@
        //  This probably requires a generic notification mechanism.
        _, fix.line.Text = replaceOnce(fix.line.Text, from, to)
 
+       if fix.skip() {
+               return
+       }
        fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
 }
 
diff -r 9800a31a3fbd -r 6bf0bc469093 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Sat Jan 04 19:11:10 2020 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Sat Jan 04 19:53:13 2020 +0000
@@ -341,6 +341,32 @@
                "WARN: Makefile:14: The word ABC should not be used.")
 }
 
+// Contrary to Line.Autofix(), the NewAutofix constructor does not check
+// whether the previous autofix is already finished, since it cannot know.
+func (s *Suite) Test_NewAutofix(c *check.C) {
+       t := s.Init(c)
+
+       line := t.NewLine("filename.mk", 123, "")
+
+       fix := NewAutofix(line)
+       fix2 := NewAutofix(line)
+
+       t.Check(fix2, check.Not(check.Equals), fix)
+}
+
+func (s *Suite) Test_Autofix_Errorf(c *check.C) {
+       t := s.Init(c)
+
+       line := t.NewLine("DESCR", 1, "Description of the package")
+
+       fix := line.Autofix()
+       fix.Errorf("Error.")
+       fix.Apply()
+
+       t.CheckOutputLines(
+               "ERROR: DESCR:1: Error.")
+}
+
 func (s *Suite) Test_Autofix_Warnf__duplicate(c *check.C) {
        t := s.Init(c)
 
@@ -351,6 +377,19 @@
        t.ExpectAssert(func() { fix.Warnf("Warning 2.") })
 }
 
+func (s *Suite) Test_Autofix_Notef(c *check.C) {
+       t := s.Init(c)
+
+       line := t.NewLine("DESCR", 1, "Description of the package")
+
+       fix := line.Autofix()
+       fix.Notef("Note.")
+       fix.Apply()
+
+       t.CheckOutputLines(
+               "NOTE: DESCR:1: Note.")
+}
+
 func (s *Suite) Test_Autofix_Explain__without_explain_option(c *check.C) {
        t := s.Init(c)
 
@@ -465,6 +504,23 @@
        t.CheckEquals(fix.RawText(), "before\nText\nafter\n")
 }
 
+func (s *Suite) Test_Autofix_Replace(c *check.C) {
+       t := s.Init(c)
+
+       doTest := func(bool) {
+               line := t.NewLine("filename.mk", 123, "text")
+               fix := line.Autofix()
+               fix.Warnf("Warning.")
+               fix.Replace("text", "replacement")
+               fix.Apply()
+       }
+
+       t.ExpectDiagnosticsAutofix(
+               doTest,
+               "WARN: filename.mk:123: Warning.",
+               "AUTOFIX: filename.mk:123: Replacing \"text\" with \"replacement\".")
+}
+
 func (s *Suite) Test_Autofix_ReplaceAfter__autofix_in_continuation_line(c *check.C) {
        t := s.Init(c)
 
@@ -708,6 +764,24 @@
                ">\toriginal")
 }
 
+func (s *Suite) Test_Autofix_InsertAfter(c *check.C) {
+       t := s.Init(c)
+
+       doTest := func(bool) {
+               line := t.NewLine("DESCR", 1, "Description of the package")
+
+               fix := line.Autofix()
+               fix.Errorf("Error.")
+               fix.InsertAfter("after")
+               fix.Apply()
+       }
+
+       t.ExpectDiagnosticsAutofix(
+               doTest,
+               "ERROR: DESCR:1: Error.",
+               "AUTOFIX: DESCR:1: Inserting a line \"after\" after this line.")
+}
+
 func (s *Suite) Test_Autofix_Delete(c *check.C) {
        t := s.Init(c)
 
@@ -821,6 +895,29 @@
        t.CheckEquals(lines.Lines[2].Text, "LINE3")
 }
 
+func (s *Suite) Test_Autofix_Describef(c *check.C) {
+       t := s.Init(c)
+
+       doTest := func(bool) {
+               line := t.NewLine("DESCR", 1, "Description of the package")
+
+               fix := line.Autofix()
+               fix.Errorf("Error.")
+               fix.Custom(func(showAutofix, autofix bool) {
+                       fix.Describef(123, "Masking.")
+                       raw := line.raw[0]
+                       raw.textnl = replaceAll(raw.Text(), `\p{L}`, "*") + "\n"
+               })
+               fix.Apply()
+               t.CheckEquals(line.raw[0].Text(), "*********** ** *** *******")
+       }
+
+       t.ExpectDiagnosticsAutofix(
+               doTest,
+               "ERROR: DESCR:123: Error.",
+               "AUTOFIX: DESCR:123: Masking.")



Home | Main Index | Thread Index | Old Index