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.5.13



details:   https://anonhg.NetBSD.org/pkgsrc/rev/e913d34b4b6f
branches:  trunk
changeset: 382731:e913d34b4b6f
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Thu Jul 12 16:23:36 2018 +0000

description:
pkgtools/pkglint: Update to 5.5.13

Changes since 5.5.12:

* Allow underscore in package version.
* Warn about SUBST in post-patch and pre-patch phases.
* Allow multiple SUBST blocks per paragraph.
* Code cleanup.

diffstat:

 pkgtools/pkglint/Makefile                    |   5 +-
 pkgtools/pkglint/files/alternatives.go       |   3 +-
 pkgtools/pkglint/files/autofix.go            |  26 ++++++----
 pkgtools/pkglint/files/autofix_test.go       |  30 +++++++++--
 pkgtools/pkglint/files/buildlink3.go         |   7 +--
 pkgtools/pkglint/files/buildlink3_test.go    |   4 +-
 pkgtools/pkglint/files/category_test.go      |   2 +-
 pkgtools/pkglint/files/codewalk.md           |  34 +++++++++----
 pkgtools/pkglint/files/line.go               |   2 +
 pkgtools/pkglint/files/logging.go            |   8 ++-
 pkgtools/pkglint/files/mkline.go             |  14 ++--
 pkgtools/pkglint/files/mkline_test.go        |  12 ++--
 pkgtools/pkglint/files/mklinechecker.go      |  14 ++--
 pkgtools/pkglint/files/mklinechecker_test.go |   6 +-
 pkgtools/pkglint/files/mklines.go            |   6 +-
 pkgtools/pkglint/files/package.go            |  12 ++--
 pkgtools/pkglint/files/package_test.go       |   6 +-
 pkgtools/pkglint/files/patches.go            |   6 +-
 pkgtools/pkglint/files/pkglint_test.go       |   2 +-
 pkgtools/pkglint/files/pkgver/vercmp.go      |   2 +-
 pkgtools/pkglint/files/pkgver/vercmp_test.go |   6 +-
 pkgtools/pkglint/files/plist.go              |   5 ++
 pkgtools/pkglint/files/shell_test.go         |  30 ++++++------
 pkgtools/pkglint/files/shtokenizer.go        |  10 ++-
 pkgtools/pkglint/files/substcontext.go       |  21 ++++++++-
 pkgtools/pkglint/files/substcontext_test.go  |  69 ++++++++++++++++++++++++++++
 pkgtools/pkglint/files/toplevel.go           |   2 +-
 pkgtools/pkglint/files/toplevel_test.go      |   2 +-
 pkgtools/pkglint/files/vartypecheck_test.go  |  20 ++++++++
 29 files changed, 259 insertions(+), 107 deletions(-)

diffs (truncated from 1050 to 300 lines):

diff -r b73eaa2ed87f -r e913d34b4b6f pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Thu Jul 12 14:10:34 2018 +0000
+++ b/pkgtools/pkglint/Makefile Thu Jul 12 16:23:36 2018 +0000
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.540 2018/06/12 17:50:26 bsiegert Exp $
+# $NetBSD: Makefile,v 1.541 2018/07/12 16:23:36 rillig Exp $
 
-PKGNAME=       pkglint-5.5.12
-PKGREVISION=   1
+PKGNAME=       pkglint-5.5.13
 DISTFILES=     # none
 CATEGORIES=    pkgtools
 
diff -r b73eaa2ed87f -r e913d34b4b6f pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go    Thu Jul 12 14:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/alternatives.go    Thu Jul 12 16:23:36 2018 +0000
@@ -30,7 +30,8 @@
                        fix := line.Autofix()
                        fix.Notef("@PREFIX@/ can be omitted from the file name.")
                        fix.Explain(
-                               "The alternative implementation is always interpreted relative to ${PREFIX}.")
+                               "The alternative implementation is always interpreted relative to",
+                               "${PREFIX}.")
                        fix.ReplaceAfter(space, "@PREFIX@/", "")
                        fix.Apply()
                } else {
diff -r b73eaa2ed87f -r e913d34b4b6f pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Thu Jul 12 14:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/autofix.go Thu Jul 12 16:23:36 2018 +0000
@@ -211,23 +211,17 @@
 
 // Notef remembers the note for logging it later when Apply is called.
 func (fix *Autofix) Notef(format string, args ...interface{}) {
-       fix.level = llNote
-       fix.diagFormat = format
-       fix.diagArgs = args
+       fix.setDiag(llNote, format, args)
 }
 
 // Warnf remembers the warning for logging it later when Apply is called.
 func (fix *Autofix) Warnf(format string, args ...interface{}) {
-       fix.level = llWarn
-       fix.diagFormat = format
-       fix.diagArgs = args
+       fix.setDiag(llWarn, format, args)
 }
 
 // Errorf remembers the error for logging it later when Apply is called.
 func (fix *Autofix) Errorf(format string, args ...interface{}) {
-       fix.level = llError
-       fix.diagFormat = format
-       fix.diagArgs = args
+       fix.setDiag(llError, format, args)
 }
 
 // Explain remembers the explanation for logging it later when Apply is called.
@@ -263,13 +257,13 @@
                                if action.lineno != 0 {
                                        lineno = strconv.Itoa(action.lineno)
                                }
-                               logs(llAutofix, line.Filename, lineno, "", action.description)
+                               logs(llAutofix, line.Filename, lineno, "Magic-Autofix-Format", action.description)
                        }
                }
 
                if logDiagnostic || logRepair {
                        line.printSource(G.logOut)
-                       if G.opts.Explain && logDiagnostic && len(fix.explanation) != 0 {
+                       if logDiagnostic && len(fix.explanation) != 0 {
                                Explain(fix.explanation...)
                        } else if G.opts.PrintSource {
                                G.logOut.Separate()
@@ -286,6 +280,16 @@
        fix.explanation = nil
 }
 
+func (fix *Autofix) setDiag(level *LogLevel, format string, args []interface{}) {
+       if G.Testing && format != "Silent-Magic-Diagnostic" && !hasSuffix(format, ".") {
+               panic(fmt.Sprintf("Autofix: format %q must end with a period.", format))
+       }
+
+       fix.level = level
+       fix.diagFormat = format
+       fix.diagArgs = args
+}
+
 func (fix *Autofix) skip() bool {
        // This check is necessary for the --only command line option.
        if fix.diagFormat == "" {
diff -r b73eaa2ed87f -r e913d34b4b6f pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go    Thu Jul 12 14:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go    Thu Jul 12 16:23:36 2018 +0000
@@ -287,12 +287,12 @@
        line := t.NewLine("Makefile", 30, "original")
 
        fix := line.Autofix()
-       fix.Warnf("Dummy")
+       fix.Warnf("Dummy.")
        fix.InsertBefore("inserted")
        fix.Apply()
 
        t.CheckOutputLines(
-               "WARN: Makefile:30: Dummy",
+               "WARN: Makefile:30: Dummy.",
                "AUTOFIX: Makefile:30: Inserting a line \"inserted\" before this line.",
                "+\tinserted",
                ">\toriginal")
@@ -305,12 +305,12 @@
        line := t.NewLine("Makefile", 30, "to be deleted")
 
        fix := line.Autofix()
-       fix.Warnf("Dummy")
+       fix.Warnf("Dummy.")
        fix.Delete()
        fix.Apply()
 
        t.CheckOutputLines(
-               "WARN: Makefile:30: Dummy",
+               "WARN: Makefile:30: Dummy.",
                "AUTOFIX: Makefile:30: Deleting this line.",
                "-\tto be deleted")
 }
@@ -401,7 +401,7 @@
 
        doFix := func(line Line) {
                fix := line.Autofix()
-               fix.Warnf("Please write in ALL-UPPERCASE")
+               fix.Warnf("Please write in ALL-UPPERCASE.")
                fix.Custom(func(printAutofix, autofix bool) {
                        fix.Describef(int(line.firstLine), "Converting to uppercase")
                        if printAutofix || autofix {
@@ -414,14 +414,14 @@
        doFix(lines[0])
 
        t.CheckOutputLines(
-               "WARN: Makefile:1: Please write in ALL-UPPERCASE")
+               "WARN: Makefile:1: Please write in ALL-UPPERCASE.")
 
        t.SetupCommandLine("--show-autofix")
 
        doFix(lines[1])
 
        t.CheckOutputLines(
-               "WARN: Makefile:2: Please write in ALL-UPPERCASE",
+               "WARN: Makefile:2: Please write in ALL-UPPERCASE.",
                "AUTOFIX: Makefile:2: Converting to uppercase")
        c.Check(lines[1].Text, equals, "LINE2")
 
@@ -433,3 +433,19 @@
                "AUTOFIX: Makefile:3: Converting to uppercase")
        c.Check(lines[2].Text, equals, "LINE3")
 }
+
+func (s *Suite) Test_Autofix_Explain(c *check.C) {
+       t := s.Init(c)
+
+       line := t.NewLine("Makefile", 74, "line1")
+
+       fix := line.Autofix()
+       fix.Warnf("Please write row instead of line.")
+       fix.Replace("line", "row")
+       fix.Explain("Explanation")
+       fix.Apply()
+
+       t.CheckOutputLines(
+               "WARN: Makefile:74: Please write row instead of line.")
+       c.Check(G.explanationsAvailable, equals, true)
+}
diff -r b73eaa2ed87f -r e913d34b4b6f pkgtools/pkglint/files/buildlink3.go
--- a/pkgtools/pkglint/files/buildlink3.go      Thu Jul 12 14:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/buildlink3.go      Thu Jul 12 16:23:36 2018 +0000
@@ -101,7 +101,7 @@
        indentLevel := 1 // The first .if is from the second paragraph.
        for {
                if exp.EOF() {
-                       exp.CurrentLine().Warnf("Expected .endif")
+                       exp.CurrentLine().Warnf("Expected \".endif\".")
                        return
                }
 
@@ -113,11 +113,6 @@
                        varname, value := mkline.Varname(), mkline.Value()
                        doCheck := false
 
-                       const (
-                               reDependencyCmp      = `^((?:\$\{[\w_]+\}|[\w_\.+]|-[^\d])+)[<>]=?(\d[^-*?\[\]]*)$`
-                               reDependencyWildcard = `^(-(?:\[0-9\]\*|\d[^-]*)$`
-                       )
-
                        if varname == "BUILDLINK_ABI_DEPENDS."+pkgbase {
                                abiLine = line
                                parser := NewParser(line, value, false)
diff -r b73eaa2ed87f -r e913d34b4b6f pkgtools/pkglint/files/buildlink3_test.go
--- a/pkgtools/pkglint/files/buildlink3_test.go Thu Jul 12 14:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/buildlink3_test.go Thu Jul 12 16:23:36 2018 +0000
@@ -206,7 +206,7 @@
        ChecklinesBuildlink3Mk(mklines)
 
        t.CheckOutputLines(
-               "WARN: buildlink3.mk:6: UNRELATED_BUILDLINK3_MK is defined but not used. Spelling mistake?",
+               "WARN: buildlink3.mk:6: UNRELATED_BUILDLINK3_MK is defined but not used.",
                "WARN: buildlink3.mk:6: This line should contain the following text: HS_X11_BUILDLINK3_MK:=")
 }
 
@@ -225,7 +225,7 @@
        ChecklinesBuildlink3Mk(mklines)
 
        t.CheckOutputLines(
-               "WARN: buildlink3.mk:EOF: Expected .endif")
+               "WARN: buildlink3.mk:EOF: Expected \".endif\".")
 }
 
 func (s *Suite) Test_ChecklinesBuildlink3Mk_unknown_dependency_patterns(c *check.C) {
diff -r b73eaa2ed87f -r e913d34b4b6f pkgtools/pkglint/files/category_test.go
--- a/pkgtools/pkglint/files/category_test.go   Thu Jul 12 14:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/category_test.go   Thu Jul 12 16:23:36 2018 +0000
@@ -20,7 +20,7 @@
        t.CheckOutputLines(
                "ERROR: ~/archivers/Makefile:1: Expected \"# $"+"NetBSD$\".",
                "WARN: ~/archivers/Makefile:4: Line contains invalid characters (U+2019).",
-               "WARN: ~/archivers/Makefile:4: SUBDIR- is defined but not used. Spelling mistake?",
+               "WARN: ~/archivers/Makefile:4: SUBDIR- is defined but not used.",
                "ERROR: ~/archivers/Makefile:6: \"../mk/category.mk\" does not exist.",
                "ERROR: ~/archivers/Makefile:2: COMMENT= line expected.",
                "WARN: ~/archivers/Makefile:2: Indentation should be a single tab character.",
diff -r b73eaa2ed87f -r e913d34b4b6f pkgtools/pkglint/files/codewalk.md
--- a/pkgtools/pkglint/files/codewalk.md        Thu Jul 12 14:10:34 2018 +0000
+++ b/pkgtools/pkglint/files/codewalk.md        Thu Jul 12 16:23:36 2018 +0000
@@ -24,7 +24,7 @@
 It contains the whole global state of pkglint.
 (Except for some of the subpackages, which have to be initialized separately.)
 All the interesting code is in the `Pkglint` type.
-This code structure makes it easy to test the code.
+Having only a single global variable makes it easy to reset the global state during testing.
 
 ### Testing pkglint
 
@@ -80,8 +80,9 @@
 line argument, which in this file is `DESCR`. From there, the pkgsrc
 root is usually reachable via `../../`, and this is what pkglint tries.
 
-After the initialization of everything,
-all items from the TODO list are worked off and handed over to `CheckDirent`.
+After initializing the pkgsrc metadata,
+all items from the TODO list are worked off and handed over to `CheckDirent`,
+one after another.
 
 ```codewalk
 file   pkglint.go
@@ -121,7 +122,10 @@
 Now we are where the actual action takes place.
 The code looks straight-forward here.
 First, each line is checked on its own,
-and the final check is for too long files. 
+and the final check is for too long files.
+Pkglint takes great care to output all diagnostics in a logical order,
+that is file by file, and top to bottom within each file.
+Therefore the checks for individual lines happen before the other check.
 
 The call to `SaveAutofixChanges` at the end looks a bit strange
 since none of the visible checks fixes anything.
@@ -135,7 +139,8 @@
 ```
 
 This code is a typical example for using the autofix feature.
-Some more details are described at the `Autofix` type itself:
+Some more details are described at the `Autofix` type itself
+and at its typical call site `Line.Autofix()`:
 
 ```codewalk
 file   linechecker.go
@@ -143,6 +148,12 @@
 end    /^type Autofix/
 ```
 
+```codewalk
+file   line.go
+start  /^func .* Autofix/ upwhile /^\/\//
+end    /^func .* Autofix/
+```
+
 The journey ends here, and it hasn't been that difficult.
 If that was too easy, have a look at the complex cases here:
 
@@ -184,6 +195,11 @@
 
 ### MkLine
 
+Most of the pkgsrc infrastructure is written in Makefiles. 
+In these, there may be line continuations  (the ones ending in backslash).
+Plus, they may contain Make variables of the form `${VARNAME}` or `${VARNAME:Modifiers}`,
+and these are handled specially.
+
 ```codewalk
 file   mkline.go
 start  ^type MkLine =
@@ -195,14 +211,10 @@
 end    ^\}
 ```
 



Home | Main Index | Thread Index | Old Index