pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/pkgtools/pkglint Update pkglint to 5.5.7
details: https://anonhg.NetBSD.org/pkgsrc/rev/1cafdb25d879
branches: trunk
changeset: 377908:1cafdb25d879
user: rillig <rillig%pkgsrc.org@localhost>
date: Sat Mar 24 14:32:49 2018 +0000
description:
Update pkglint to 5.5.7
Changes since 5.5.6:
* When pkglint warns about files that are accidentally executable, it
offers to fix the file permissions.
* Warn about ${HOMEPAGE:=repository/}, since the := modifier should
only be used with MASTER_SITES.
* When the distinfo file is missing, suggest setting NO_CHECKSUM.
* Several refactorings.
diffstat:
pkgtools/pkglint/Makefile | 4 +-
pkgtools/pkglint/files/autofix.go | 34 +-
pkgtools/pkglint/files/autofix_test.go | 48 ++-
pkgtools/pkglint/files/buildlink3_test.go | 26 +-
pkgtools/pkglint/files/category_test.go | 4 +-
pkgtools/pkglint/files/check_test.go | 15 +-
pkgtools/pkglint/files/distinfo.go | 2 +-
pkgtools/pkglint/files/licenses.go | 4 +-
pkgtools/pkglint/files/licenses_test.go | 1 -
pkgtools/pkglint/files/line.go | 21 +
pkgtools/pkglint/files/linechecker.go | 27 +-
pkgtools/pkglint/files/mkline.go | 33 +-
pkgtools/pkglint/files/mkline_test.go | 72 +-
pkgtools/pkglint/files/mklinechecker.go | 30 +-
pkgtools/pkglint/files/mklinechecker_test.go | 55 +-
pkgtools/pkglint/files/mklines.go | 6 +-
pkgtools/pkglint/files/mklines_test.go | 22 +-
pkgtools/pkglint/files/mkparser_test.go | 2 +-
pkgtools/pkglint/files/package.go | 19 +-
pkgtools/pkglint/files/package_test.go | 16 +-
pkgtools/pkglint/files/pkglint.go | 56 +-
pkgtools/pkglint/files/pkglint_test.go | 52 +-
pkgtools/pkglint/files/pkgsrc.go | 605 +++++++++++++++++++++++++++
pkgtools/pkglint/files/pkgsrc_test.go | 143 ++++++
pkgtools/pkglint/files/plist.go | 4 +
pkgtools/pkglint/files/plist_test.go | 22 +
pkgtools/pkglint/files/shell.go | 12 +-
pkgtools/pkglint/files/shell_test.go | 20 +-
pkgtools/pkglint/files/tools.go | 116 +++++
pkgtools/pkglint/files/toplevel_test.go | 2 +-
pkgtools/pkglint/files/util.go | 82 +++-
pkgtools/pkglint/files/vardefs.go | 46 +-
pkgtools/pkglint/files/vartype_test.go | 8 +-
pkgtools/pkglint/files/vartypecheck.go | 10 +-
pkgtools/pkglint/files/vartypecheck_test.go | 11 +-
35 files changed, 1399 insertions(+), 231 deletions(-)
diffs (truncated from 2921 to 300 lines):
diff -r 5ddb02ab7882 -r 1cafdb25d879 pkgtools/pkglint/Makefile
--- a/pkgtools/pkglint/Makefile Sat Mar 24 14:29:33 2018 +0000
+++ b/pkgtools/pkglint/Makefile Sat Mar 24 14:32:49 2018 +0000
@@ -1,6 +1,6 @@
-# $NetBSD: Makefile,v 1.531 2018/03/04 20:34:32 rillig Exp $
+# $NetBSD: Makefile,v 1.532 2018/03/24 14:32:49 rillig Exp $
-PKGNAME= pkglint-5.5.6
+PKGNAME= pkglint-5.5.7
DISTFILES= # none
CATEGORIES= pkgtools
diff -r 5ddb02ab7882 -r 1cafdb25d879 pkgtools/pkglint/files/autofix.go
--- a/pkgtools/pkglint/files/autofix.go Sat Mar 24 14:29:33 2018 +0000
+++ b/pkgtools/pkglint/files/autofix.go Sat Mar 24 14:32:49 2018 +0000
@@ -38,6 +38,22 @@
lines: append([]*RawLine{}, line.raw...)}
}
+// Custom runs a custom fix action, unless the fix is skipped anyway
+// because of the --only option.
+//
+// The fixer function must always call Describef.
+// If printAutofix or autofix is true, the fix should be done in
+// memory as far as possible (e.g. changes to the text of the line).
+// If autofix is true, the fix should be done permanently
+// (e.g. direct changes to the file system).
+func (fix *Autofix) Custom(fixer func(printAutofix, autofix bool)) {
+ if fix.skip() {
+ return
+ }
+
+ fixer(G.opts.PrintAutofix, G.opts.Autofix)
+}
+
func (fix *Autofix) Replace(from string, to string) {
fix.ReplaceAfter("", from, to)
}
@@ -62,8 +78,10 @@
}
}
-// ReplaceRegex replaces the first or all occurrences of the `from` pattern
-// with the fixed string `toText`. Placeholders like `$1` are _not_ expanded.
+// ReplaceRegex replaces the first howOften or all occurrences (if negative)
+// of the `from` pattern with the fixed string `toText`.
+//
+// Placeholders like `$1` are _not_ expanded in the `toText`.
// (If you know how to do the expansion correctly, feel free to implement it.)
func (fix *Autofix) ReplaceRegex(from regex.Pattern, toText string, howOften int) {
if fix.skip() {
@@ -223,10 +241,10 @@
// * records the fixes in the line (--autofix)
func (fix *Autofix) Apply() {
line := fix.line
- if line.firstLine < 1 {
- return
+
+ if fix.diagFormat == "" {
+ panic("Each autofix must have a diagnostic.")
}
-
G.explainNext = shallBeLogged(fix.diagFormat)
if G.explainNext {
logDiagnostic := fix.level != nil && fix.diagFormat != "Silent-Magic-Diagnostic" &&
@@ -239,7 +257,11 @@
logRepair := len(fix.actions) > 0 && (G.opts.Autofix || G.opts.PrintAutofix)
if logRepair {
for _, action := range fix.actions {
- logs(llAutofix, line.Filename, strconv.Itoa(action.lineno), "", action.description)
+ lineno := ""
+ if action.lineno != 0 {
+ lineno = strconv.Itoa(action.lineno)
+ }
+ logs(llAutofix, line.Filename, lineno, "", action.description)
}
}
diff -r 5ddb02ab7882 -r 1cafdb25d879 pkgtools/pkglint/files/autofix_test.go
--- a/pkgtools/pkglint/files/autofix_test.go Sat Mar 24 14:29:33 2018 +0000
+++ b/pkgtools/pkglint/files/autofix_test.go Sat Mar 24 14:32:49 2018 +0000
@@ -1,6 +1,9 @@
package main
-import "gopkg.in/check.v1"
+import (
+ "gopkg.in/check.v1"
+ "strings"
+)
func (s *Suite) Test_Autofix_ReplaceRegex(c *check.C) {
t := s.Init(c)
@@ -387,3 +390,46 @@
// And therefore, no AUTOFIX action must appear in the log.
t.CheckOutputEmpty()
}
+
+func (s *Suite) Test_Autofix_CustomFix(c *check.C) {
+ t := s.Init(c)
+
+ lines := t.NewLines("Makefile",
+ "line1",
+ "line2",
+ "line3")
+
+ doFix := func(line Line) {
+ fix := line.Autofix()
+ fix.Warnf("Please write in ALL-UPPERCASE")
+ fix.Custom(func(printAutofix, autofix bool) {
+ fix.Describef(int(line.firstLine), "Converting to uppercase")
+ if printAutofix || autofix {
+ line.Text = strings.ToUpper(line.Text)
+ }
+ })
+ fix.Apply()
+ }
+
+ doFix(lines[0])
+
+ t.CheckOutputLines(
+ "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",
+ "AUTOFIX: Makefile:2: Converting to uppercase")
+ c.Check(lines[1].Text, equals, "LINE2")
+
+ t.SetupCommandLine("--autofix")
+
+ doFix(lines[2])
+
+ t.CheckOutputLines(
+ "AUTOFIX: Makefile:3: Converting to uppercase")
+ c.Check(lines[2].Text, equals, "LINE3")
+}
diff -r 5ddb02ab7882 -r 1cafdb25d879 pkgtools/pkglint/files/buildlink3_test.go
--- a/pkgtools/pkglint/files/buildlink3_test.go Sat Mar 24 14:29:33 2018 +0000
+++ b/pkgtools/pkglint/files/buildlink3_test.go Sat Mar 24 14:32:49 2018 +0000
@@ -5,7 +5,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"# XXX This file was created automatically using createbuildlink-@PKGVERSION@",
@@ -40,7 +40,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_name_mismatch(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
G.Pkg = NewPackage("x11/hs-X11")
G.Pkg.EffectivePkgbase = "X11"
G.Pkg.EffectivePkgnameLine = t.NewMkLine("Makefile", 3, "DISTNAME=\tX11-1.0")
@@ -68,7 +68,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_name_mismatch_multiple_inclusion(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -91,7 +91,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_name_mismatch_abi_api(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -116,7 +116,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_abi_api_versions(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -141,7 +141,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_no_BUILDLINK_TREE_at_beginning(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -165,7 +165,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_no_BUILDLINK_TREE_at_end(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -194,7 +194,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_multiple_inclusion_wrong(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -213,7 +213,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_missing_endif(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -231,7 +231,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_unknown_dependency_patterns(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -258,7 +258,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_PKGBASE_with_variable(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -283,7 +283,7 @@
func (s *Suite) Test_ChecklinesBuildlink3Mk_PKGBASE_with_unknown_variable(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
@@ -314,7 +314,7 @@
t := s.Init(c)
t.SetupCommandLine("-Wall")
- G.globalData.InitVartypes()
+ t.SetupVartypes()
mklines := t.NewMkLines("buildlink3.mk",
MkRcsID,
"",
diff -r 5ddb02ab7882 -r 1cafdb25d879 pkgtools/pkglint/files/category_test.go
--- a/pkgtools/pkglint/files/category_test.go Sat Mar 24 14:29:33 2018 +0000
+++ b/pkgtools/pkglint/files/category_test.go Sat Mar 24 14:32:49 2018 +0000
@@ -5,7 +5,7 @@
func (s *Suite) Test_CheckdirCategory_totally_broken(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
t.SetupFileLines("archivers/Makefile",
"# $",
"SUBDIR+=pkg1",
@@ -36,7 +36,7 @@
func (s *Suite) Test_CheckdirCategory_invalid_comment(c *check.C) {
t := s.Init(c)
- G.globalData.InitVartypes()
+ t.SetupVartypes()
t.SetupFileLines("archivers/Makefile",
MkRcsID,
"COMMENT=\t\\Make $$$$ fast\"",
diff -r 5ddb02ab7882 -r 1cafdb25d879 pkgtools/pkglint/files/check_test.go
--- a/pkgtools/pkglint/files/check_test.go Sat Mar 24 14:29:33 2018 +0000
+++ b/pkgtools/pkglint/files/check_test.go Sat Mar 24 14:32:49 2018 +0000
@@ -50,6 +50,7 @@
G.logOut = NewSeparatorWriter(&t.stdout)
G.logErr = NewSeparatorWriter(&t.stderr)
trace.Out = &t.stdout
+ G.Pkgsrc = NewPkgsrc(t.TmpDir())
t.checkC = c
t.SetupCommandLine( /* no arguments */ )
@@ -104,9 +105,15 @@
G.opts.LogVerbose = true // See SetUpTest
}
+// SetupVartypes registers a few hundred variables like MASTER_SITES,
+// WRKSRC, SUBST_SED.*, so that their data types are known to pkglint.
+func (t *Tester) SetupVartypes() {
+ G.Pkgsrc.InitVartypes()
+}
Home |
Main Index |
Thread Index |
Old Index