nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: threefoldtech/zos
Pull request #1703 (2022-05-16 14:08:08)

Polka seems only signs the hex dump of the hash


Patch:
diff --git a/pkg/gridtypes/deployment.go b/pkg/gridtypes/deployment.go
index e4978067..70cc6558 100644
--- a/pkg/gridtypes/deployment.go
+++ b/pkg/gridtypes/deployment.go
@@ -395,7 +395,7 @@ func (d *Deployment) Verify(getter KeyGetter) error {
 		if _, err := buf.WriteString("<Bytes>"); err != nil {
 			return err
 		}
-		if _, err := buf.Write(message); err != nil {
+		if _, err := buf.WriteString(hex.EncodeToString(message)); err != nil {
 			return err
 		}
 		if _, err := buf.WriteString("</Bytes>"); err != nil {


Test patch:
diff --git a/pkg/gridtypes/sign_test.go b/pkg/gridtypes/sign_test.go
index 01c3cf70..461f1b16 100644
--- a/pkg/gridtypes/sign_test.go
+++ b/pkg/gridtypes/sign_test.go
@@ -4,6 +4,7 @@ import (
 	"bytes"
 	"crypto/ed25519"
 	"crypto/rand"
+	"encoding/hex"
 	"fmt"
 	"testing"
 
@@ -21,7 +22,7 @@ func (s *polkaSigner) Sign(msg []byte) ([]byte, error) {
 		return nil, err
 	}
 
-	if _, err := buf.Write(msg); err != nil {
+	if _, err := buf.WriteString(hex.EncodeToString(msg)); err != nil {
 		return nil, err
 	}
Repository: threefoldtech/zos
Pull request #1714 (2022-05-27 08:03:10)

disable over-provision.
Also use fallocate instead of truncate


Patch:
diff --git a/pkg/storage/disk.go b/pkg/storage/disk.go
index 6ef3618a..b527b966 100644
--- a/pkg/storage/disk.go
+++ b/pkg/storage/disk.go
@@ -191,7 +191,7 @@ func (s *Module) DiskCreate(name string, size gridtypes.Unit) (disk pkg.VDisk, e
 		return disk, err
 	}
 
-	if err := file.Truncate(int64(size)); err != nil {
+	if err = syscall.Fallocate(int(file.Fd()), 0, 0, int64(size)); err != nil {
 		return disk, errors.Wrap(err, "failed to truncate disk to size")
 	}
 
@@ -212,7 +212,7 @@ func (s *Module) DiskResize(name string, size gridtypes.Unit) (disk pkg.VDisk, e
 
 	defer file.Close()
 
-	if err := file.Truncate(int64(size)); err != nil {
+	if err = syscall.Fallocate(int(file.Fd()), 0, 0, int64(size)); err != nil {
 		return disk, errors.Wrap(err, "failed to truncate disk to size")
 	}
 
diff --git a/pkg/storage/storage.go b/pkg/storage/storage.go
index bbf666c5..0ac53e60 100644
--- a/pkg/storage/storage.go
+++ b/pkg/storage/storage.go
@@ -27,7 +27,7 @@ import (
 
 const (
 	// SSDOverProvisionFactor over provision factor for SSDs
-	SSDOverProvisionFactor = 2
+	SSDOverProvisionFactor = 1
 	// CacheTarget is the path where the cache disk is mounted
 	CacheTarget = "/var/cache"
 	// cacheLabel is the name of the cache


Test patch:
diff --git a/pkg/storage/storage_test.go b/pkg/storage/storage_test.go
index 3a2b075f..18ff9a0b 100644
--- a/pkg/storage/storage_test.go
+++ b/pkg/storage/storage_test.go
@@ -392,10 +392,10 @@ func TestVDiskFindCandidatesOverProvision(t *testing.T) {
 
 	pool1.On("Volumes").Return([]filesystem.Volume{sub}, nil)
 
-	_, err := mod.diskFindCandidate(8000)
+	_, err := mod.diskFindCandidate(4000)
 	require.NoError(err)
 
-	_, err = mod.diskFindCandidate(10000)
+	_, err = mod.diskFindCandidate(5000)
 	require.Error(err)
 
 }
Repository: threefoldtech/zos
Pull request #1541 (2022-01-05 10:59:10)

latest calculations for min rootfs size


Patch:
diff --git a/pkg/gridtypes/zos/zmachine.go b/pkg/gridtypes/zos/zmachine.go
index 65c6fd7f..1d5aaf94 100644
--- a/pkg/gridtypes/zos/zmachine.go
+++ b/pkg/gridtypes/zos/zmachine.go
@@ -130,8 +130,13 @@ type ZMachine struct {
 func (m *ZMachine) MinRootSize() gridtypes.Unit {
 	// sru = (cpu * mem_in_gb) / 8
 	// each 1 SRU is 50GB of storage
-	su := gridtypes.Unit(m.ComputeCapacity.CPU) * m.ComputeCapacity.Memory / 8
-	return gridtypes.Unit(su * sizeInGBPerCU)
+	cu := gridtypes.Unit(m.ComputeCapacity.CPU) * m.ComputeCapacity.Memory / (8 * gridtypes.Gigabyte)
+
+	if cu == 0 {
+		return 500 * gridtypes.Megabyte
+	}
+
+	return 2 * gridtypes.Gigabyte
 }
 
 func (m *ZMachine) RootSize() gridtypes.Unit {


Test patch:
diff --git a/pkg/gridtypes/zos/zmachine_test.go b/pkg/gridtypes/zos/zmachine_test.go
index dfce5e19..888728e8 100644
--- a/pkg/gridtypes/zos/zmachine_test.go
+++ b/pkg/gridtypes/zos/zmachine_test.go
@@ -15,7 +15,7 @@ func TestZMachineSRU(t *testing.T) {
 	}
 	cases := []Case{
 		{
-			Expected: 50 * gridtypes.Gigabyte,
+			Expected: 2 * gridtypes.Gigabyte,
 			VM: ZMachine{
 
 				ComputeCapacity: MachineCapacity{
@@ -25,7 +25,7 @@ func TestZMachineSRU(t *testing.T) {
 			},
 		},
 		{
-			Expected: 25 * gridtypes.Gigabyte,
+			Expected: 500 * gridtypes.Megabyte,
 			VM: ZMachine{
 
 				ComputeCapacity: MachineCapacity{
@@ -35,7 +35,7 @@ func TestZMachineSRU(t *testing.T) {
 			},
 		},
 		{
-			Expected: 50 * gridtypes.Gigabyte,
+			Expected: 2 * gridtypes.Gigabyte,
 			VM: ZMachine{
 
 				ComputeCapacity: MachineCapacity{
@@ -45,7 +45,7 @@ func TestZMachineSRU(t *testing.T) {
 			},
 		},
 		{
-			Expected: 75 * gridtypes.Gigabyte,
+			Expected: 2 * gridtypes.Gigabyte,
 			VM: ZMachine{
 
 				ComputeCapacity: MachineCapacity{
@@ -55,7 +55,7 @@ func TestZMachineSRU(t *testing.T) {
 			},
 		},
 		{
-			Expected: 125 * gridtypes.Gigabyte,
+			Expected: 2 * gridtypes.Gigabyte,
 			VM: ZMachine{
 
 				ComputeCapacity: MachineCapacity{
@@ -65,7 +65,7 @@ func TestZMachineSRU(t *testing.T) {
 			},
 		},
 		{
-			Expected: 6400 * gridtypes.Megabyte,
+			Expected: 500 * gridtypes.Megabyte,
 			VM: ZMachine{
 
 				ComputeCapacity: MachineCapacity{
@@ -75,7 +75,7 @@ func TestZMachineSRU(t *testing.T) {
 			},
 		},
 		{
-			Expected: 1600000 * gridtypes.Kilobyte, // ~= 1562.5 Megabytes
+			Expected: 500 * gridtypes.Megabyte,
 			VM: ZMachine{
 
 				ComputeCapacity: MachineCapacity{
Repository: bazelbuild/buildtools
Pull request #419 (2018-11-09 19:32:00)

Fix the type inference with the % operator
The `%` operator can be applied to expressions of different types. If the left side is a string, the right side
can be anything and the binary expression itself will be a string.

Therefore we can't assume that the result of `unknown % type_x` is of type X, unless it is a string, e.g. compare `10 % 3` and `"template %s" % 3`.

Likewise, the `%=` operator can also be applied to a string and a non-string.


Patch:
diff --git a/warn/types.go b/warn/types.go
index 2f7d484..77b8246 100644
--- a/warn/types.go
+++ b/warn/types.go
@@ -92,6 +92,10 @@ func detectTypes(f *build.File) map[build.Expr]Type {
 				if !ok {
 					return
 				}
+				if node.Op == "%=" && t != String {
+					// If the right hand side is not a string, the left hand side can still be a string
+					return
+				}
 				ident, ok := (node.X).(*build.Ident)
 				if !ok {
 					return
@@ -112,7 +116,12 @@ func detectTypes(f *build.File) map[build.Expr]Type {
 				if t, ok := result[node.X]; ok {
 					nodeType = t
 				} else if t, ok := result[node.Y]; ok {
-					nodeType = t
+					if node.Op != "%" || t == String {
+						// The percent operator is special because it can be applied to to arguments of
+						// different types (`"%s\n" % foo`), and we can't assume that the expression has
+						// type X if the right-hand side has the type X.
+						nodeType = t
+					}
 				}
 			}
 		}


Test patch:
diff --git a/warn/types_test.go b/warn/types_test.go
index 8236c4b..387cfb8 100644
--- a/warn/types_test.go
+++ b/warn/types_test.go
@@ -142,5 +142,49 @@ dict:<bar + dict:<d>>
 
 depset:<depset:
 | baz>
 depset:<baz | depset:
>
+`)
+
+	checkTypes(t, `
+n = 3
+s = "foo"
+
+foo % n
+foo % s
+foo % bar
+
+n % foo
+s % foo
+
+s %= foo
+n %= foo
+
+baz = unknown
+baz %= s
+baz
+
+boq = unknown
+boq %= n
+boq
+`, `
+n = int:<3>
+s = string:<"foo">
+
+foo % int:<n>
+string:<foo % string:
>
+foo % bar
+
+int:<int:<n> % foo>
+string:<string:
 % foo>
+
+string:
 %= foo
+int:<n> %= foo
+
+baz = unknown
+baz %= string:

+string:<baz>
+
+boq = unknown
+boq %= int:<n>
+boq
 `)
 }
Repository: bazelbuild/buildtools
Pull request #435 (2018-11-16 13:02:12)

Make the 'load_on_top' warning work only for .bzl files


Patch:
diff --git a/warn/warn.go b/warn/warn.go
index 3bc90d7..5d42831 100644
--- a/warn/warn.go
+++ b/warn/warn.go
@@ -290,6 +290,12 @@ func packageOnTopWarning(f *build.File, fix bool) []*Finding {
 
 func loadOnTopWarning(f *build.File, fix bool) []*Finding {
 	findings := []*Finding{}
+
+	if f.Build {
+		// Not applicable for BUILD or WORKSPACE files
+		return findings
+	}
+
 	firstStmtIndex := -1 // index of the first seen non-load statement
 	for i := 0; i < len(f.Stmt); i++ {
 		stmt := f.Stmt[i]


Test patch:
diff --git a/warn/warn_test.go b/warn/warn_test.go
index 1e8b793..d962259 100644
--- a/warn/warn_test.go
+++ b/warn/warn_test.go
@@ -86,7 +86,8 @@ func checkFix(t *testing.T, category, input, expected string, scope testScope, i
 		if isBuildFile {
 			fileType = "BUILD"
 		}
-		t.Errorf("fixed %s (type %s) incorrectly: diff shows -expected, +ours", input, fileType)
+		t.Errorf("fixed a test (type %s) incorrectly:\ninput:\n%s\ndiff (-expected, +ours)\n",
+			fileType, input)
 		testutils.Tdiff(t, want, have)
 	}
 }
@@ -394,8 +395,7 @@ load(":f.bzl", "x")
 foo()
 
 x()`,
-		[]string{":2: Load statements should be at the top of the file."},
-		scopeEverywhere)
+		[]string{":2: Load statements should be at the top of the file."}, scopeBzl)
 
 	checkFindingsAndFix(t, "load-on-top", `
 """Docstring"""
@@ -431,7 +431,7 @@ bar()`,
 		[]string{
 			":9: Load statements should be at the top of the file.",
 			":15: Load statements should be at the top of the file.",
-		}, scopeEverywhere)
+		}, scopeBzl)
 }
 
 func TestPositionalArguments(t *testing.T) {
Repository: bazelbuild/buildtools
Pull request #444 (2018-11-21 18:30:38)

Only print lint fixes with verbose mode
Previously every file that was processed by the buildifier -lint=fix
command would produce output, even if there weren't any fixes. To make
this more like the buildifier fix formatting mode, this wraps that print
in the `-v` flag.

keith: Updated!
vladmos: Thanks!

Patch:
diff --git a/buildifier/buildifier.go b/buildifier/buildifier.go
index 91ecc3a..b28dce8 100644
--- a/buildifier/buildifier.go
+++ b/buildifier/buildifier.go
@@ -311,7 +311,7 @@ func processFile(filename string, data []byte, inputType, lint string, warningsL
 	case "warn":
 		warn.PrintWarnings(f, pkg, warningsList, false)
 	case "fix":
-		warn.FixWarnings(f, pkg, warningsList)
+		warn.FixWarnings(f, pkg, warningsList, *vflag)
 	}
 
 	if *filePath != "" {
diff --git a/warn/warn.go b/warn/warn.go
index 287fed1..26e1679 100644
--- a/warn/warn.go
+++ b/warn/warn.go
@@ -992,11 +992,13 @@ func PrintWarnings(f *build.File, pkg string, enabledWarnings []string, showRepl
 }
 
 // FixWarnings fixes all warnings that can be fixed automatically.
-func FixWarnings(f *build.File, pkg string, enabledWarnings []string) {
+func FixWarnings(f *build.File, pkg string, enabledWarnings []string, verbose bool) {
 	warnings := FileWarnings(f, pkg, enabledWarnings, true)
-	fmt.Fprintf(os.Stderr, "%s: applied fixes, %d warnings left\n",
-		f.Path,
-		len(warnings))
+	if verbose {
+		fmt.Fprintf(os.Stderr, "%s: applied fixes, %d warnings left\n",
+			f.Path,
+			len(warnings))
+	}
 }
 
 func collectAllWarnings() []string {


Test patch:
diff --git a/buildifier/integration_test.sh b/buildifier/integration_test.sh
index 6841ce9..39e97b1 100755
--- a/buildifier/integration_test.sh
+++ b/buildifier/integration_test.sh
@@ -51,11 +51,12 @@ EOF
 
 cat > test/fix_report_golden <<EOF
 test/to_fix.bzl: applied fixes, 0 warnings left
+fixed test/to_fix.bzl
 EOF
 
 $1 --lint=warn test/to_fix.bzl 2> test/error
 diff test/error test/error_golden
 
-$1 --lint=fix test/to_fix.bzl 2> test/fix_report
+$1 --lint=fix -v test/to_fix.bzl 2> test/fix_report
 diff test/to_fix.bzl test/fixed_golden.bzl
 diff test/fix_report test/fix_report_golden
diff --git a/warn/warn_test.go b/warn/warn_test.go
index 8f1654b..3c85302 100644
--- a/warn/warn_test.go
+++ b/warn/warn_test.go
@@ -81,7 +81,7 @@ func checkFix(t *testing.T, category, input, expected string, scope, fileType bu
 		panic(fmt.Sprintf("%v", err))
 	}
 
-	FixWarnings(buildFile, "the_package", []string{category})
+	FixWarnings(buildFile, "the_package", []string{category}, false)
 	have := build.Format(buildFile)
 	want := build.Format(goldenFile)
 	if !bytes.Equal(have, want) {
Repository: bazelbuild/buildtools
Pull request #466 (2018-11-28 18:29:59)

[buildifier] Fix load order comparison warning.
Currently the warning would be printed in case two identical labels
are compared, which cannot be fixed, since reordering the same load
would not change the comparison result.

This change makes the warning flag only instances where `i`th label
is "less than" the `i-1`th label.

ttsugriy: cc @vladmos 
vladmos: Thanks!

Patch:
diff --git a/warn/warn.go b/warn/warn.go
index 517a895..9e3be9e 100644
--- a/warn/warn.go
+++ b/warn/warn.go
@@ -382,7 +382,7 @@ func outOfOrderLoadWarning(f *build.File, fix bool) []*Finding {
 	}
 
 	for i := 1; i < len(sortedLoads); i++ {
-		if !compareLoadLabels(sortedLoads[i-1].Module.Value, sortedLoads[i].Module.Value) {
+		if compareLoadLabels(sortedLoads[i].Module.Value, sortedLoads[i-1].Module.Value) {
 			start, end := sortedLoads[i].Span()
 			findings = append(findings, makeFinding(f, start, end, "out-of-order-load",
 				"Load statement is out of its lexicographical order.", true, nil))


Test patch:
diff --git a/warn/warn_test.go b/warn/warn_test.go
index f4f61a4..9972a09 100644
--- a/warn/warn_test.go
+++ b/warn/warn_test.go
@@ -508,6 +508,14 @@ load(":b.bzl", "b")
 			":3: Load statement is out of its lexicographical order.",
 			":6: Load statement is out of its lexicographical order.",
 		}, scopeBuild|scopeBzl)
+
+	checkFindingsAndFix(t, "out-of-order-load", `
+load(":a.bzl", "a")
+load(":a.bzl", "a")
+`, `
+load(":a.bzl", "a")
+load(":a.bzl", "a")`,
+		[]string{}, scopeBuild|scopeBzl)
 }
 
 func TestPositionalArguments(t *testing.T) {
Repository: bazelbuild/buildtools
Pull request #469 (2018-12-04 01:00:45)

[buildifier] Take name priority into account when ordering dictionary items.
Since it's common to use dictionaries for passing `**kwargs` to rules, their
ordering should match the ordering used rule attributes in build files.

Build files rely on `NamePriority` `tables` dictionary to adjust priorities
according to common or project-specific guidelines and now the same rules
apply to ordering dictionary items.


Patch:
diff --git a/WARNINGS.md b/WARNINGS.md
index 56934c8..e537011 100644
--- a/WARNINGS.md
+++ b/WARNINGS.md
@@ -430,6 +430,9 @@ Dictionary items should be sorted lexicagraphically by their keys. This makes
 it easier to find the item of interest and reduces chances of conflicts when
 performing large-scale automated refactoring.
 
+The order is affected by `NamePriority` dictionary passed using `-tables` or
+`-add_tables` flags.
+
 If you want to preserve the original dictionary items order, you can disable
 the warning by adding a comment `# @unsorted-dict-items` to the dictionary
 expression or any of its enclosing expressins (binary, if etc). For example,
diff --git a/warn/BUILD.bazel b/warn/BUILD.bazel
index a30a0e4..8f0ab50 100644
--- a/warn/BUILD.bazel
+++ b/warn/BUILD.bazel
@@ -13,6 +13,7 @@ go_library(
         "//build:go_default_library",
         "//bzlenv:go_default_library",
         "//edit:go_default_library",
+        "//tables:go_default_library",
     ],
 )
 
diff --git a/warn/warn.go b/warn/warn.go
index 7598110..c43b71a 100644
--- a/warn/warn.go
+++ b/warn/warn.go
@@ -10,6 +10,7 @@ import (
 
 	"github.com/bazelbuild/buildtools/build"
 	"github.com/bazelbuild/buildtools/edit"
+	"github.com/bazelbuild/buildtools/tables"
 )
 
 // A Finding is a warning reported by the analyzer. It may contain an optional suggested fix.
@@ -417,9 +418,14 @@ func unsortedDictItemsWarning(f *build.File, fix bool) []*Finding {
 	findings := []*Finding{}
 
 	compareItems := func(item1, item2 *build.KeyValueExpr) bool {
-		key1 := item1.Key.(*build.StringExpr)
-		key2 := item2.Key.(*build.StringExpr)
-		return key1.Value < key2.Value
+		key1 := item1.Key.(*build.StringExpr).Value
+		key2 := item2.Key.(*build.StringExpr).Value
+		key1Priority := tables.NamePriority[key1]
+		key2Priority := tables.NamePriority[key2]
+		if key1Priority != key2Priority {
+			return key1Priority < key2Priority
+		}
+		return key1 < key2
 	}
 
 	build.Walk(f, func(expr build.Expr, stack []build.Expr) {


Test patch:
diff --git a/warn/warn_test.go b/warn/warn_test.go
index 9c533ca..0fd6f20 100644
--- a/warn/warn_test.go
+++ b/warn/warn_test.go
@@ -601,6 +601,18 @@ d = {
 		[]string{"4: Dictionary items are out of their lexicographical order."},
 		scopeEverywhere)
 
+	checkFindingsAndFix(t, "unsorted-dict-items", `
+d = {
+	"deps": [],
+	"srcs": ["foo.go"],
+}`, `
+d = {
+	"srcs": ["foo.go"],
+	"deps": [],
+}`,
+		[]string{"3: Dictionary items are out of their lexicographical order."},
+		scopeEverywhere)
+
 	checkFindings(t, "unsorted-dict-items", `
 # @unsorted-dict-items
 d = {
Repository: bazelbuild/buildtools
Pull request #472 (2018-12-06 16:22:23)

[buildifier] Sort private symbols after public.
Symbols that start with `_` are private and should follow public
symbols to make user experience better.


Patch:
diff --git a/warn/warn.go b/warn/warn.go
index c43b71a..4c66a4d 100644
--- a/warn/warn.go
+++ b/warn/warn.go
@@ -420,6 +420,13 @@ func unsortedDictItemsWarning(f *build.File, fix bool) []*Finding {
 	compareItems := func(item1, item2 *build.KeyValueExpr) bool {
 		key1 := item1.Key.(*build.StringExpr).Value
 		key2 := item2.Key.(*build.StringExpr).Value
+		// regular keys should preceed private ones (start with "_")
+		if strings.HasPrefix(key1, "_") {
+			return strings.HasPrefix(key2, "_") && key1 < key2
+		}
+		if strings.HasPrefix(key2, "_") {
+			return true
+		}
 		key1Priority := tables.NamePriority[key1]
 		key2Priority := tables.NamePriority[key2]
 		if key1Priority != key2Priority {


Test patch:
diff --git a/warn/warn_test.go b/warn/warn_test.go
index 0fd6f20..85500a5 100644
--- a/warn/warn_test.go
+++ b/warn/warn_test.go
@@ -613,6 +613,32 @@ d = {
 		[]string{"3: Dictionary items are out of their lexicographical order."},
 		scopeEverywhere)
 
+	checkFindingsAndFix(t, "unsorted-dict-items", `
+foo_binary = rule(
+	implementation = _foo_binary_impl,
+	attrs = {
+		"_foocc": attr.label(
+			default = Label("//depsets:foocc"),
+		),
+		"srcs": attr.label_list(allow_files = True),
+		"deps": attr.label_list(),
+	},
+	outputs = {"out": "%{name}.out"},
+)`, `
+foo_binary = rule(
+	implementation = _foo_binary_impl,
+	attrs = {
+		"srcs": attr.label_list(allow_files = True),
+		"deps": attr.label_list(),
+		"_foocc": attr.label(
+			default = Label("//depsets:foocc"),
+		),
+	},
+	outputs = {"out": "%{name}.out"},
+)`,
+		[]string{"7: Dictionary items are out of their lexicographical order."},
+		scopeEverywhere)
+
 	checkFindings(t, "unsorted-dict-items", `
 # @unsorted-dict-items
 d = {
Repository: bazelbuild/buildtools
Pull request #481 (2018-12-14 00:12:55)

[buildifier] Make sure default select condition is the last one.

thomasvl: Thanks for doing this.

@laurentlb can this make the next release?
vladmos: Thanks!

Patch:
diff --git a/tables/tables.go b/tables/tables.go
index 0ec308f..81f8a0f 100644
--- a/tables/tables.go
+++ b/tables/tables.go
@@ -199,6 +199,9 @@ var NamePriority = map[string]int{
 	"implementation": 5,
 	"implements":     6,
 	"alwayslink":     7,
+	// default condition in a dictionary literal passed to select should be
+	// the last one by convention.
+	"//conditions:default": 50,
 }
 
 var StripLabelLeadingSlashes = false


Test patch:
diff --git a/warn/warn_test.go b/warn/warn_test.go
index 85500a5..237e857 100644
--- a/warn/warn_test.go
+++ b/warn/warn_test.go
@@ -613,6 +613,18 @@ d = {
 		[]string{"3: Dictionary items are out of their lexicographical order."},
 		scopeEverywhere)
 
+	checkFindingsAndFix(t, "unsorted-dict-items", `
+d = select({
+	"//conditions:zzz": ["myrule_b.sh"],
+	"//conditions:default": ["myrule_default.sh"],
+})`, `
+d = select({
+	"//conditions:zzz": ["myrule_b.sh"],
+	"//conditions:default": ["myrule_default.sh"],
+})`,
+		[]string{},
+		scopeEverywhere)
+
 	checkFindingsAndFix(t, "unsorted-dict-items", `
 foo_binary = rule(
 	implementation = _foo_binary_impl,
Repository: bazelbuild/buildtools
Pull request #498 (2019-01-04 13:46:36)

Disable load-on-top warnings for BUILD files
Check for load statements being not on the top is essential for .bzl files because it's going to be an error in Bazel to do so.

However despite it's also consistent to have load statements on top for BUILD files as well, that doesn't work well with existing BUILD files generators that often put load statements right before they are needed.


Patch:
diff --git a/warn/warn.go b/warn/warn.go
index 7613b1f..83fd545 100644
--- a/warn/warn.go
+++ b/warn/warn.go
@@ -295,8 +295,8 @@ func packageOnTopWarning(f *build.File, fix bool) []*Finding {
 func loadOnTopWarning(f *build.File, fix bool) []*Finding {
 	findings := []*Finding{}
 
-	if f.Type == build.TypeWorkspace {
-		// Not applicable for WORKSPACE files
+	if f.Type != build.TypeDefault {
+		// Only applicable to .bzl files
 		return findings
 	}
 


Test patch:
diff --git a/warn/warn_test.go b/warn/warn_test.go
index 237e857..e7ae8a3 100644
--- a/warn/warn_test.go
+++ b/warn/warn_test.go
@@ -415,7 +415,7 @@ load(":f.bzl", "x")
 foo()
 
 x()`,
-		[]string{":2: Load statements should be at the top of the file."}, scopeBuild|scopeBzl)
+		[]string{":2: Load statements should be at the top of the file."}, scopeBzl)
 
 	checkFindingsAndFix(t, "load-on-top", `
 """Docstring"""
@@ -451,7 +451,7 @@ bar()`,
 		[]string{
 			":9: Load statements should be at the top of the file.",
 			":15: Load statements should be at the top of the file.",
-		}, scopeBuild|scopeBzl)
+		}, scopeBzl)
 }
 
 func TestOutOfOrderLoad(t *testing.T) {
Repository: bazelbuild/buildtools
Pull request #544 (2019-02-13 12:45:48)

Compress multiple 'not documented' warnings into one warning
It's common that a function has many arguments and a docstring that doesn't document them.

In this case instead of generating multiple warnings (one for missing documentation) buildifier should generate one cumulative warning to reduce the warning noise.


Patch:
diff --git a/warn/warn_docstring.go b/warn/warn_docstring.go
index 4e12c90..9396ec8 100644
--- a/warn/warn_docstring.go
+++ b/warn/warn_docstring.go
@@ -2,9 +2,10 @@ package warn
 
 import (
 	"fmt"
-	"github.com/bazelbuild/buildtools/build"
 	"regexp"
 	"strings"
+
+	"github.com/bazelbuild/buildtools/build"
 )
 
 // FunctionLengthDocstringThreshold is a limit for a function size (in statements), above which
@@ -244,13 +245,25 @@ func functionDocstringWarning(f *build.File, fix bool) []*Finding {
 		if isDocstringRequired || len(info.args) > 0 {
 
 			// Check whether all arguments are documented.
+			notDocumentedArguments := []string{}
 			paramNames := make(map[string]bool)
 			for _, param := range def.Params {
 				name := getParamName(param)
 				paramNames[name] = true
 				if _, ok := info.args[name]; !ok {
+					notDocumentedArguments = append(notDocumentedArguments, name)
+				}
+			}
+			if len(notDocumentedArguments) > 0 {
+				if len(notDocumentedArguments) == 1 {
+					findings = append(findings, makeFinding(f, start, end, "function-docstring",
+						fmt.Sprintf(`Argument "%s" is not documented.`, notDocumentedArguments[0]), true, nil))
+				} else {
 					findings = append(findings, makeFinding(f, start, end, "function-docstring",
-						fmt.Sprintf(`Argument "%s" is not documented.`, name), true, nil))
+						fmt.Sprintf(
+							`Arguments "%s" are not documented.`,
+							strings.Join(notDocumentedArguments, `", "`),
+						), true, nil))
 				}
 			}
 


Test patch:
diff --git a/warn/warn_docstring_test.go b/warn/warn_docstring_test.go
index f0b2d90..0a8afa7 100644
--- a/warn/warn_docstring_test.go
+++ b/warn/warn_docstring_test.go
@@ -259,11 +259,7 @@ def f(x, y, z = None, *args, **kwargs):
    pass
 `,
 		[]string{
-			`2: Argument "x" is not documented.`,
-			`2: Argument "y" is not documented.`,
-			`2: Argument "z" is not documented.`,
-			`2: Argument "*args" is not documented.`,
-			`2: Argument "**kwargs" is not documented.`,
+			`2: Arguments "x", "y", "z", "*args", "**kwargs" are not documented.`,
 		},
 		scopeEverywhere)