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.7.16
details: https://anonhg.NetBSD.org/pkgsrc/rev/3ff1b1aa9265
branches: trunk
changeset: 398250:3ff1b1aa9265
user: rillig <rillig%pkgsrc.org@localhost>
date: Sun Jul 14 21:25:47 2019 +0000
description:
pkgtools/pkglint: update to 5.7.16
Changes since 5.7.15:
* Completely rewrote the code for aligning multiple variable assignment
lines. It works on the actual lines of the file now instead of the
parsed lines. This provides more exact diagnostics and also makes the
handling of these lines easier so that future requirements can be
implemented more easily.
* Added support for exotic conditions in .if clauses. These conditions
are not seen in the wild though.
* Fixed wrong diagnostics for ALTERNATIVES files that appear
conditionally in the PLIST.
* As always: lots of refactorings and newly added tests.
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/PLIST | 5 +-
pkgtools/pkglint/files/alternatives.go | 4 +-
pkgtools/pkglint/files/alternatives_test.go | 26 +
pkgtools/pkglint/files/autofix.go | 119 +-
pkgtools/pkglint/files/autofix_test.go | 215 +-
pkgtools/pkglint/files/buildlink3.go | 4 +-
pkgtools/pkglint/files/category.go | 2 +-
pkgtools/pkglint/files/category_test.go | 10 +-
pkgtools/pkglint/files/check_test.go | 37 +-
pkgtools/pkglint/files/distinfo_test.go | 4 +-
pkgtools/pkglint/files/files_test.go | 64 +-
pkgtools/pkglint/files/licenses.go | 2 +-
pkgtools/pkglint/files/line.go | 52 +-
pkgtools/pkglint/files/line_test.go | 8 +-
pkgtools/pkglint/files/linelexer_test.go | 10 +-
pkgtools/pkglint/files/logging.go | 76 +-
pkgtools/pkglint/files/logging_test.go | 66 +-
pkgtools/pkglint/files/mkline.go | 121 +-
pkgtools/pkglint/files/mkline_test.go | 562 +++-
pkgtools/pkglint/files/mklinechecker.go | 47 +-
pkgtools/pkglint/files/mklinechecker_test.go | 143 +-
pkgtools/pkglint/files/mklines.go | 256 +--
pkgtools/pkglint/files/mklines_test.go | 221 +-
pkgtools/pkglint/files/mklines_varalign_test.go | 1092 ---------
pkgtools/pkglint/files/mkparser.go | 333 +-
pkgtools/pkglint/files/mkparser_test.go | 288 +-
pkgtools/pkglint/files/mkshparser_test.go | 79 +-
pkgtools/pkglint/files/mkshwalker_test.go | 8 +-
pkgtools/pkglint/files/mktokenslexer_test.go | 122 +-
pkgtools/pkglint/files/mktypes.go | 2 +-
pkgtools/pkglint/files/mktypes_test.go | 66 +-
pkgtools/pkglint/files/package.go | 62 +-
pkgtools/pkglint/files/package_test.go | 84 +-
pkgtools/pkglint/files/paragraph.go | 4 +-
pkgtools/pkglint/files/pkglint.go | 2 +-
pkgtools/pkglint/files/pkglint_test.go | 92 +-
pkgtools/pkglint/files/pkgsrc.go | 21 +-
pkgtools/pkglint/files/pkgsrc_test.go | 179 +-
pkgtools/pkglint/files/plist.go | 14 +-
pkgtools/pkglint/files/plist_test.go | 2 +-
pkgtools/pkglint/files/redundantscope_test.go | 31 +-
pkgtools/pkglint/files/shell.go | 14 +-
pkgtools/pkglint/files/shell_test.go | 131 +-
pkgtools/pkglint/files/shtokenizer_test.go | 29 +-
pkgtools/pkglint/files/shtypes_test.go | 28 +-
pkgtools/pkglint/files/substcontext.go | 6 +-
pkgtools/pkglint/files/substcontext_test.go | 18 +-
pkgtools/pkglint/files/testnames_test.go | 1 -
pkgtools/pkglint/files/textproc/lexer_test.go | 2 +-
pkgtools/pkglint/files/tools.go | 2 +-
pkgtools/pkglint/files/tools_test.go | 140 +-
pkgtools/pkglint/files/toplevel.go | 15 +-
pkgtools/pkglint/files/toplevel_test.go | 27 +-
pkgtools/pkglint/files/util.go | 38 +-
pkgtools/pkglint/files/util_test.go | 425 ++-
pkgtools/pkglint/files/var_test.go | 98 +-
pkgtools/pkglint/files/varalignblock.go | 631 +++++
pkgtools/pkglint/files/varalignblock_test.go | 2566 +++++++++++++++++++++++
pkgtools/pkglint/files/vardefs_test.go | 18 +-
pkgtools/pkglint/files/vartype.go | 20 +-
pkgtools/pkglint/files/vartype_test.go | 67 +-
pkgtools/pkglint/files/vartypecheck.go | 18 +-
pkgtools/pkglint/files/vartypecheck_test.go | 16 +-
64 files changed, 5776 insertions(+), 3073 deletions(-)
diffs (truncated from 13692 to 300 lines):
diff -r d1c28e8725c0 -r 3ff1b1aa9265 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sun Jul 14 20:49:07 2019 +0000
+++ b/pkgtools/pkglint/Makefile Sun Jul 14 21:25:47 2019 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.587 2019/07/01 22:25:52 rillig Exp $
+# $NetBSD: Makefile,v 1.588 2019/07/14 21:25:47 rillig Exp $
-PKGNAME= pkglint-5.7.15
+PKGNAME= pkglint-5.7.16
CATEGORIES= pkgtools
DISTNAME= tools
MASTER_SITES= ${MASTER_SITE_GITHUB:=golang/}
diff -r d1c28e8725c0 -r 3ff1b1aa9265 pkgtools/pkglint/PLIST
--- a/pkgtools/pkglint/PLIST Sun Jul 14 20:49:07 2019 +0000
+++ b/pkgtools/pkglint/PLIST Sun Jul 14 21:25:47 2019 +0000
@@ -1,4 +1,4 @@
-@comment $NetBSD: PLIST,v 1.12 2019/06/10 19:51:57 rillig Exp $
+@comment $NetBSD: PLIST,v 1.13 2019/07/14 21:25:47 rillig Exp $
bin/pkglint
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint.a
gopkg/pkg/${GO_PLATFORM}/netbsd.org/pkglint/getopt.a
@@ -54,7 +54,6 @@
gopkg/src/netbsd.org/pkglint/mklinechecker_test.go
gopkg/src/netbsd.org/pkglint/mklines.go
gopkg/src/netbsd.org/pkglint/mklines_test.go
-gopkg/src/netbsd.org/pkglint/mklines_varalign_test.go
gopkg/src/netbsd.org/pkglint/mkparser.go
gopkg/src/netbsd.org/pkglint/mkparser_test.go
gopkg/src/netbsd.org/pkglint/mkshparser.go
@@ -113,6 +112,8 @@
gopkg/src/netbsd.org/pkglint/util_test.go
gopkg/src/netbsd.org/pkglint/var.go
gopkg/src/netbsd.org/pkglint/var_test.go
+gopkg/src/netbsd.org/pkglint/varalignblock.go
+gopkg/src/netbsd.org/pkglint/varalignblock_test.go
gopkg/src/netbsd.org/pkglint/vardefs.go
gopkg/src/netbsd.org/pkglint/vardefs_test.go
gopkg/src/netbsd.org/pkglint/vartype.go
diff -r d1c28e8725c0 -r 3ff1b1aa9265 pkgtools/pkglint/files/alternatives.go
--- a/pkgtools/pkglint/files/alternatives.go Sun Jul 14 20:49:07 2019 +0000
+++ b/pkgtools/pkglint/files/alternatives.go Sun Jul 14 21:25:47 2019 +0000
@@ -17,7 +17,7 @@
}
checkPlistWrapper := func(line *Line, wrapper string) {
- if plist.Files[wrapper] {
+ if plist.Files[wrapper] != nil {
line.Errorf("Alternative wrapper %q must not appear in the PLIST.", wrapper)
}
}
@@ -25,7 +25,7 @@
checkPlistAlternative := func(line *Line, alternative string) {
relImplementation := strings.Replace(alternative, "@PREFIX@/", "", 1)
plistName := replaceAll(relImplementation, `@(\w+)@`, "${$1}")
- if plist.Files[plistName] || G.Pkg.vars.Defined("ALTERNATIVES_SRC") {
+ if plist.Files[plistName] != nil || G.Pkg.vars.Defined("ALTERNATIVES_SRC") {
return
}
diff -r d1c28e8725c0 -r 3ff1b1aa9265 pkgtools/pkglint/files/alternatives_test.go
--- a/pkgtools/pkglint/files/alternatives_test.go Sun Jul 14 20:49:07 2019 +0000
+++ b/pkgtools/pkglint/files/alternatives_test.go Sun Jul 14 21:25:47 2019 +0000
@@ -47,6 +47,32 @@
"AUTOFIX: ALTERNATIVES:4: Replacing \"bin/vim\" with \"@PREFIX@/bin/vim\".")
}
+// A file that is mentioned in the ALTERNATIVES file must appear
+// in the package's PLIST files. It may appear there conditionally,
+// assuming that manual testing will reveal inconsistencies. Or
+// that this scenario is an edge case anyway.
+func (s *Suite) Test_CheckFileAlternatives__PLIST_conditional(c *check.C) {
+ t := s.Init(c)
+
+ t.SetUpPackage("category/package")
+ t.Chdir("category/package")
+ t.CreateFileLines("ALTERNATIVES",
+ "bin/wrapper1 @PREFIX@/bin/always-exists",
+ "bin/wrapper2 @PREFIX@/bin/conditional",
+ "bin/wrapper3 @PREFIX@/bin/not-found")
+ t.CreateFileLines("PLIST",
+ PlistCvsID,
+ "bin/always-exists",
+ "${PLIST.cond}bin/conditional")
+ t.FinishSetUp()
+
+ G.Check(".")
+
+ t.CheckOutputLines(
+ "ERROR: ALTERNATIVES:3: Alternative implementation \"@PREFIX@/bin/not-found\" " +
+ "must appear in the PLIST as \"bin/not-found\".")
+}
+
func (s *Suite) Test_CheckFileAlternatives__empty(c *check.C) {
t := s.Init(c)
diff -r d1c28e8725c0 -r 3ff1b1aa9265 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sun Jul 14 20:49:07 2019 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sun Jul 14 21:25:47 2019 +0000
@@ -125,6 +125,41 @@
}
}
+// ReplaceAt replaces the text "from" with "to", a single time.
+// But only if the text at the given position is indeed "from".
+func (fix *Autofix) ReplaceAt(rawIndex int, column int, from string, to string) {
+ assert(from != to)
+ fix.assertRealLine()
+
+ if fix.skip() {
+ return
+ }
+
+ rawLine := fix.line.raw[rawIndex]
+ if column >= len(rawLine.textnl) || !hasPrefix(rawLine.textnl[column:], from) {
+ return
+ }
+
+ replaced := rawLine.textnl[:column] + to + rawLine.textnl[column+len(from):]
+
+ if G.Logger.IsAutofix() {
+ rawLine.textnl = replaced
+
+ // Fix the parsed text as well.
+ // This is only approximate and won't work in some edge cases
+ // that involve escaped comments or replacements across line breaks.
+ //
+ // TODO: Do this properly by parsing the whole line again,
+ // and ideally everything that depends on the parsed line.
+ // This probably requires a generic notification mechanism.
+ if strings.Count(fix.line.Text, from) == 1 {
+ fix.line.Text = strings.Replace(fix.line.Text, from, to, 1)
+ }
+ }
+ fix.Describef(rawLine.Lineno, "Replacing %q with %q.", from, to)
+ return
+}
+
// ReplaceRegex replaces the first howOften or all occurrences (if negative)
// of the `from` pattern with the fixed string `toText`.
//
@@ -313,11 +348,12 @@
logFix := G.Logger.IsAutofix()
if logDiagnostic {
+ linenos := fix.affectedLinenos()
msg := sprintf(fix.diagFormat, fix.diagArgs...)
- if !logFix && G.Logger.FirstTime(line.Filename, line.Linenos(), msg) {
- line.showSource(G.Logger.out)
+ if !logFix && G.Logger.FirstTime(line.Filename, linenos, msg) {
+ G.Logger.showSource(line)
}
- G.Logger.Logf(fix.level, line.Filename, line.Linenos(), fix.diagFormat, msg)
+ G.Logger.Logf(fix.level, line.Filename, linenos, fix.diagFormat, msg)
}
if logFix {
@@ -332,7 +368,7 @@
if logDiagnostic || logFix {
if logFix {
- line.showSource(G.Logger.out)
+ G.Logger.showSource(line)
}
if logDiagnostic && len(fix.explanation) > 0 {
line.Explain(fix.explanation...)
@@ -347,66 +383,31 @@
reset()
}
-func (fix *Autofix) Realign(mkline *MkLine, newWidth int) {
-
- // XXX: Check whether this method can be implemented as Custom fix.
- // This complicated code should not be in the Autofix type.
-
- fix.assertRealLine()
- assert(mkline.IsMultiline())
- assert(mkline.IsVarassign() || mkline.IsCommentedVarassign())
-
- if fix.skip() {
- return
+func (fix *Autofix) affectedLinenos() string {
+ if len(fix.actions) == 0 {
+ return fix.line.Linenos()
}
- normalized := true // Whether all indentation is tabs, followed by spaces.
- oldWidth := 0 // The minimum required indentation in the original lines.
+ var first, last int
+ for _, action := range fix.actions {
+ if action.lineno == 0 {
+ continue
+ }
- {
- // Parsing the continuation marker as variable value is cheating but works well.
- text := strings.TrimSuffix(mkline.raw[0].orignl, "\n")
- data := MkLineParser{}.split(nil, text)
- _, a := MkLineParser{}.MatchVarassign(mkline.Line, text, data)
- if a.value != "\\" {
- oldWidth = tabWidth(a.valueAlign)
+ if last == 0 || action.lineno < first {
+ first = action.lineno
+ }
+ if last == 0 || action.lineno > last {
+ last = action.lineno
}
}
- for _, rawLine := range fix.line.raw[1:] {
- _, comment, space := match2(rawLine.textnl, `^(#?)([ \t]*)`)
- width := tabWidth(comment + space)
- if (oldWidth == 0 || width < oldWidth) && width >= 8 {
- oldWidth = width
- }
- if !matches(space, `^\t* {0,7}$`) {
- normalized = false
- }
- }
-
- if normalized && newWidth == oldWidth {
- return
- }
-
- // 8 spaces is the minimum possible indentation that can be
- // distinguished from an initial line, by looking only at the
- // beginning of the line. Therefore, this indentation is always
- // regarded as intentional and is not realigned.
- if oldWidth == 8 {
- return
- }
-
- for _, rawLine := range fix.line.raw[1:] {
- _, comment, oldSpace := match2(rawLine.textnl, `^(#?)([ \t]*)`)
- 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.Logger.IsAutofix() {
- rawLine.textnl = replaced
- }
- fix.Describef(rawLine.Lineno, "Replacing indentation %q with %q.", oldSpace, newSpace)
- }
+ if last == 0 {
+ return fix.line.Linenos()
+ } else if first < last {
+ return sprintf("%d--%d", first, last)
+ } else {
+ return strconv.Itoa(first)
}
}
@@ -425,6 +426,8 @@
fix.diagArgs = args
}
+// skip returns whether this autofix should be skipped because
+// its message is matched by one of the --only command line options.
func (fix *Autofix) skip() bool {
assert(fix.diagFormat != "") // The diagnostic must be given before the action.
diff -r d1c28e8725c0 -r 3ff1b1aa9265 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go Sun Jul 14 20:49:07 2019 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go Sun Jul 14 21:25:47 2019 +0000
@@ -35,14 +35,14 @@
fix.Delete()
fix.Apply()
- c.Check(fix.RawText(), equals, ""+
+ t.CheckEquals(fix.RawText(), ""+
"# row 1 \\\n"+
"continuation of row 1\n")
t.CheckOutputLines(
">\t# row 1 \\",
">\tcontinuation of row 1",
"WARN: ~/Makefile:1--2: Row should be replaced with line.")
- c.Check(fix.modified, equals, true)
+ t.CheckEquals(fix.modified, true)
}
func (s *Suite) Test_Autofix__show_autofix_modifies_line(c *check.C) {
@@ -63,7 +63,7 @@
fix.Delete()
fix.Apply()
- c.Check(fix.RawText(), equals, ""+
+ t.CheckEquals(fix.RawText(), ""+
"above\n"+
"below\n")
t.CheckOutputLines(
@@ -78,7 +78,7 @@
"-\t# row 1 \\",
"-\tcontinuation of row 1",
"+\tbelow")
- c.Check(fix.modified, equals, true)
+ t.CheckEquals(fix.modified, true)
}
func (s *Suite) Test_Autofix_ReplaceAfter__autofix_in_continuation_line(c *check.C) {
@@ -153,7 +153,7 @@
fix.Apply()
Home |
Main Index |
Thread Index |
Old Index