nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: jeremydaly/dynamodb-toolbox
Pull request #740 (2024-05-05 14:47:35)

Don't throw for undefined dependsOn attributes in Index key fields
Proposed solution for : https://github.com/jeremydaly/dynamodb-toolbox/issues/739

Isolate key check to table Partition Key and Sort Keys only


naorpeled: Hey @whahoo,
thanks for this! looks good to me.
Will merge and publish a release.

Patch:
diff --git a/src/lib/normalizeData.ts b/src/lib/normalizeData.ts
index 7f50f46a..127fa3de 100644
--- a/src/lib/normalizeData.ts
+++ b/src/lib/normalizeData.ts
@@ -85,7 +85,9 @@ export default () => (
         const map = dependsOn(defaultMap, attr)
         defaultMap = map
       } catch (e) {
-        if (throwOnMissingNonPartitionRequiredProperties && e instanceof DependsOnUndefined && (schema[attr].partitionKey || schema[attr].sortKey || schema[attr].required)) {
+        if (throwOnMissingNonPartitionRequiredProperties 
+          && e instanceof DependsOnUndefined 
+          && (schema[attr].partitionKey === true || schema[attr].sortKey === true || schema[attr].required)) {
           throw new Error(`Required field '${attr}' depends on attribute(s), one or more of which can't be resolved (${schema[attr].dependsOn})`)
         }
         delete defaultMap[attr]


Test patch:
diff --git a/src/__tests__/normalizeData.unit.test.ts b/src/__tests__/normalizeData.unit.test.ts
index d3eee91a..6e53d030 100644
--- a/src/__tests__/normalizeData.unit.test.ts
+++ b/src/__tests__/normalizeData.unit.test.ts
@@ -79,7 +79,7 @@ describe('normalizeData', () => {
     }).toThrow(`Field 'notAField' does not have a mapping or alias`)
   })
 
-  it('fails when partion, sortkey or other required fields have depend attributes not provided', () => {
+  it('fails when partition, sort key or other required fields have depend attributes not provided', () => {
     const ent = new Entity({
       name: 'Test',
       attributes: {
@@ -96,4 +96,33 @@ describe('normalizeData', () => {
       `Required field 'sk' depends on attribute(s), one or more of which can't be resolved (parent)`
     )
   })
+
+  it('should not fail for GSI keys', () => {
+
+    const indexedStatus = ['AVAILABLE', 'PENDING']
+
+    const ent = new Entity({
+      name: 'Test',
+      attributes: {
+        pk: { type: 'string', partitionKey: true },
+        sk: { type: 'string', sortKey: true },
+        GSI1PK: { 
+          type: 'string', 
+          partitionKey: 'GSI1', 
+          dependsOn: ['status'],
+          default: (data: { status: string }) => data.status in indexedStatus ? `SHOW` : undefined,
+        },
+        GSI1SK: {
+          type: 'string',
+          sortKey: 'GSI1',
+          dependsOn: ['status', 'modified'],
+          default: (data: { status: string, modified: string }) => `${data.status}#${data.modified}`,
+        },
+        status: { type: 'string' },
+      },
+      table: DefaultTable,
+    } as const)
+
+    expect(() => ent.updateParams({ pk: 'pk', sk: 'sk' })).not.toThrow()
+  })
 })
Repository: stretchr/testify
Pull request #873 (2020-01-25 15:47:07)

fix: error diff was not being show for large values
If you were comparing values which when formatted were longer than about 64k then the actual, expected and diff messages were not printed to the console.

boyan-soubachov: Note, the builds are failing since you may have forgotten to run `gofmt` (or some other compatible formatting tool) on your source:

https://travis-ci.org/stretchr/testify/jobs/643376551?utm_medium=notification&utm_source=github_status
chirino: Now using Equal and used gofmt 
chirino: fixed text

Patch:
diff --git a/assert/assertions.go b/assert/assertions.go
index b73b2d5..e0ea9b6 100644
--- a/assert/assertions.go
+++ b/assert/assertions.go
@@ -429,14 +429,27 @@ func samePointers(first, second interface{}) bool {
 // to a type conversion in the Go grammar.
 func formatUnequalValues(expected, actual interface{}) (e string, a string) {
 	if reflect.TypeOf(expected) != reflect.TypeOf(actual) {
-		return fmt.Sprintf("%T(%#v)", expected, expected),
-			fmt.Sprintf("%T(%#v)", actual, actual)
+		return fmt.Sprintf("%T(%s)", expected, truncatingFormat(expected)),
+			fmt.Sprintf("%T(%s)", actual, truncatingFormat(actual))
 	}
 	switch expected.(type) {
 	case time.Duration:
 		return fmt.Sprintf("%v", expected), fmt.Sprintf("%v", actual)
 	}
-	return fmt.Sprintf("%#v", expected), fmt.Sprintf("%#v", actual)
+	return truncatingFormat(expected), truncatingFormat(actual)
+}
+
+// truncatingFormat formats the data and truncates it if it's too long.
+//
+// This helps keep formatted error messages lines from exceeding the
+// bufio.MaxScanTokenSize max line length that the go testing framework imposes.
+func truncatingFormat(data interface{}) string {
+	value := fmt.Sprintf("%#v", data)
+	max := bufio.MaxScanTokenSize - 100 // Give us some space the type info too if needed.
+	if len(value) > max {
+		value = value[0:max] + "<... truncated>"
+	}
+	return value
 }
 
 // EqualValues asserts that two objects are equal or convertable to the same types


Test patch:
diff --git a/assert/assertions_test.go b/assert/assertions_test.go
index ebcb8c3..29f89da 100644
--- a/assert/assertions_test.go
+++ b/assert/assertions_test.go
@@ -1,6 +1,7 @@
 package assert
 
 import (
+	"bufio"
 	"bytes"
 	"encoding/json"
 	"errors"
@@ -2255,3 +2256,18 @@ func Test_validateEqualArgs(t *testing.T) {
 		t.Error("nil functions are equal")
 	}
 }
+
+func Test_truncatingFormat(t *testing.T) {
+
+	original := strings.Repeat("a", bufio.MaxScanTokenSize-102)
+	result := truncatingFormat(original)
+	Equal(t, fmt.Sprintf("%#v", original), result, "string should not be truncated")
+
+	original = original + "x"
+	result = truncatingFormat(original)
+	NotEqual(t, fmt.Sprintf("%#v", original), result, "string should have been truncated.")
+
+	if !strings.HasSuffix(result, "<... truncated>") {
+		t.Error("truncated string should have <... truncated> suffix")
+	}
+}
Repository: stretchr/testify
Pull request #1319 (2022-12-20 05:42:10)

fix: fix bug for check unsafe.Pointer isNil
## Summary
fix bug for checking unsafe.Pointer object isNil.




Patch:
diff --git a/assert/assertions.go b/assert/assertions.go
index fa1245b..361d0bd 100644
--- a/assert/assertions.go
+++ b/assert/assertions.go
@@ -530,7 +530,7 @@ func isNil(object interface{}) bool {
 		[]reflect.Kind{
 			reflect.Chan, reflect.Func,
 			reflect.Interface, reflect.Map,
-			reflect.Ptr, reflect.Slice},
+			reflect.Ptr, reflect.Slice, reflect.UnsafePointer},
 		kind)
 
 	if isNilableKind && value.IsNil() {


Test patch:
diff --git a/assert/assertions_test.go b/assert/assertions_test.go
index bdab184..b5193a5 100644
--- a/assert/assertions_test.go
+++ b/assert/assertions_test.go
@@ -15,6 +15,7 @@ import (
 	"strings"
 	"testing"
 	"time"
+	"unsafe"
 )
 
 var (
@@ -2558,3 +2559,10 @@ func TestErrorAs(t *testing.T) {
 		})
 	}
 }
+
+func TestIsNil(t *testing.T) {
+	var n unsafe.Pointer = nil
+	if !isNil(n) {
+		t.Fatal("fail")
+	}
+}
Repository: stretchr/testify
Pull request #1517 (2023-12-08 11:47:13)

Support Pointer to Struct in EqualExportedValues
This PR allows to use `EqualExportedValues` with pointers to structs.


Patch:
diff --git a/assert/assertions.go b/assert/assertions.go
index bc15101..5122634 100644
--- a/assert/assertions.go
+++ b/assert/assertions.go
@@ -578,12 +578,19 @@ func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ..
 		return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
 	}
 
+	if aType.Kind() == reflect.Ptr {
+		aType = aType.Elem()
+	}
+	if bType.Kind() == reflect.Ptr {
+		bType = bType.Elem()
+	}
+
 	if aType.Kind() != reflect.Struct {
-		return Fail(t, fmt.Sprintf("Types expected to both be struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...)
+		return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...)
 	}
 
 	if bType.Kind() != reflect.Struct {
-		return Fail(t, fmt.Sprintf("Types expected to both be struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...)
+		return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...)
 	}
 
 	expected = copyExportedFields(expected)


Test patch:
diff --git a/assert/assertions_test.go b/assert/assertions_test.go
index d2a25c2..4757d2e 100644
--- a/assert/assertions_test.go
+++ b/assert/assertions_test.go
@@ -413,6 +413,25 @@ func TestEqualExportedValues(t *testing.T) {
 			value2:        S{[2]int{1, 2}, Nested{2, nil}, nil, Nested{}},
 			expectedEqual: true,
 		},
+		{
+			value1:        &S{1, Nested{2, 3}, 4, Nested{5, 6}},
+			value2:        &S{1, Nested{2, nil}, nil, Nested{}},
+			expectedEqual: true,
+		},
+		{
+			value1:        &S{1, Nested{2, 3}, 4, Nested{5, 6}},
+			value2:        &S{1, Nested{1, nil}, nil, Nested{}},
+			expectedEqual: false,
+			expectedFail: `
+	            	Diff:
+	            	--- Expected
+	            	+++ Actual
+	            	@@ -3,3 +3,3 @@
+	            	  Exported2: (assert.Nested) {
+	            	-  Exported: (int) 2,
+	            	+  Exported: (int) 1,
+	            	   notExported: (interface {}) <nil>`,
+		},
 	}
 
 	for _, c := range cases {
Repository: stretchr/testify
Pull request #1565 (2024-03-05 09:42:22)

.gitignore: ignore "go test -c" binaries
## Summary
Ignore binaries produced by `go test -c`.

## Changes
* Add `assert/assert.test`, `require/require.test`... to `.gitignore`.

## Motivation
Ease maintenance as there is no risk of committing those files by mistake.

## Related issues
N/A


Patch:
diff --git a/.gitignore b/.gitignore
index 5aacdb7..6e1bb22 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,9 @@ _testmain.go
 *.exe
 
 .DS_Store
+
+# Output of "go test -c"
+/assert/assert.test
+/require/require.test
+/suite/suite.test
+/mock/mock.test
diff --git a/assert/assertions.go b/assert/assertions.go
index ccbd525..0b7570f 100644
--- a/assert/assertions.go
+++ b/assert/assertions.go
@@ -45,10 +45,6 @@ type BoolAssertionFunc func(TestingT, bool, ...interface{}) bool
 // for table driven tests.
 type ErrorAssertionFunc func(TestingT, error, ...interface{}) bool
 
-// PanicAssertionFunc is a common function prototype when validating a panic value.  Can be useful
-// for table driven tests.
-type PanicAssertionFunc = func(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool
-
 // Comparison is a custom function that returns true on success and false on failure
 type Comparison func() (success bool)
 


Test patch:
diff --git a/assert/assertions_test.go b/assert/assertions_test.go
index 0ae36cd..2a6e472 100644
--- a/assert/assertions_test.go
+++ b/assert/assertions_test.go
@@ -2789,42 +2789,6 @@ func TestErrorAssertionFunc(t *testing.T) {
 	}
 }
 
-func ExamplePanicAssertionFunc() {
-	t := &testing.T{} // provided by test
-
-	tests := []struct {
-		name      string
-		panicFn   PanicTestFunc
-		assertion PanicAssertionFunc
-	}{
-		{"with panic", func() { panic(nil) }, Panics},
-		{"without panic", func() {}, NotPanics},
-	}
-
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			tt.assertion(t, tt.panicFn)
-		})
-	}
-}
-
-func TestPanicAssertionFunc(t *testing.T) {
-	tests := []struct {
-		name      string
-		panicFn   PanicTestFunc
-		assertion PanicAssertionFunc
-	}{
-		{"not panic", func() {}, NotPanics},
-		{"panic", func() { panic(nil) }, Panics},
-	}
-
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			tt.assertion(t, tt.panicFn)
-		})
-	}
-}
-
 func TestEventuallyFalse(t *testing.T) {
 	mockT := new(testing.T)
Repository: stretchr/testify
Pull request #1586 (2024-04-11 20:54:50)

assert.EqualExportedValues: accepts everything
Remove type validation in EqualExportedValues

See #1584.


Patch:
diff --git a/assert/assertions.go b/assert/assertions.go
index 44b854d..b9a2b44 100644
--- a/assert/assertions.go
+++ b/assert/assertions.go
@@ -621,21 +621,6 @@ func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ..
 		return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
 	}
 
-	if aType.Kind() == reflect.Ptr {
-		aType = aType.Elem()
-	}
-	if bType.Kind() == reflect.Ptr {
-		bType = bType.Elem()
-	}
-
-	if aType.Kind() != reflect.Struct {
-		return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...)
-	}
-
-	if bType.Kind() != reflect.Struct {
-		return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...)
-	}
-
 	expected = copyExportedFields(expected)
 	actual = copyExportedFields(actual)
 


Test patch:
diff --git a/assert/assertions_test.go b/assert/assertions_test.go
index e158688..ad5c1be 100644
--- a/assert/assertions_test.go
+++ b/assert/assertions_test.go
@@ -449,6 +449,56 @@ func TestEqualExportedValues(t *testing.T) {
 	            	+  Exported: (int) 1,
 	            	   notExported: (interface {}) <nil>`,
 		},
+		{
+			value1:        []int{1, 2},
+			value2:        []int{1, 2},
+			expectedEqual: true,
+		},
+		{
+			value1:        []int{1, 2},
+			value2:        []int{1, 3},
+			expectedEqual: false,
+			expectedFail: `
+	            	Diff:
+	            	--- Expected
+	            	+++ Actual
+	            	@@ -2,3 +2,3 @@
+	            	  (int) 1,
+	            	- (int) 2
+	            	+ (int) 3
+	            	 }`,
+		},
+		{
+			value1: []*Nested{
+				{1, 2},
+				{3, 4},
+			},
+			value2: []*Nested{
+				{1, "a"},
+				{3, "b"},
+			},
+			expectedEqual: true,
+		},
+		{
+			value1: []*Nested{
+				{1, 2},
+				{3, 4},
+			},
+			value2: []*Nested{
+				{1, "a"},
+				{2, "b"},
+			},
+			expectedEqual: false,
+			expectedFail: `
+	            	Diff:
+	            	--- Expected
+	            	+++ Actual
+	            	@@ -6,3 +6,3 @@
+	            	  (*assert.Nested)({
+	            	-  Exported: (int) 3,
+	            	+  Exported: (int) 2,
+	            	   notExported: (interface {}) <nil>`,
+		},
 	}
 
 	for _, c := range cases {
Repository: stretchr/testify
Pull request #1587 (2024-04-11 21:39:52)

assert.Regexp: handle []byte array properly


## Summary

The regexp package works more efficiently on bytes; if you have bytes, it is easier to pass these directly to assert.Regexp than to convert them to a string first.

In addition, FindIndex/FindStringIndex are unnecessary here because we immediately throw away the result - let's just call Match() instead.

## Motivation

More efficient test calls, fewer casts in test code. 

## Related issues

Updates #1585.



Patch:
diff --git a/assert/assertions.go b/assert/assertions.go
index a291b1f..eb800c1 100644
--- a/assert/assertions.go
+++ b/assert/assertions.go
@@ -1615,7 +1615,6 @@ func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...in
 
 // matchRegexp return true if a specified regexp matches a string.
 func matchRegexp(rx interface{}, str interface{}) bool {
-
 	var r *regexp.Regexp
 	if rr, ok := rx.(*regexp.Regexp); ok {
 		r = rr
@@ -1623,7 +1622,14 @@ func matchRegexp(rx interface{}, str interface{}) bool {
 		r = regexp.MustCompile(fmt.Sprint(rx))
 	}
 
-	return (r.FindStringIndex(fmt.Sprint(str)) != nil)
+	switch v := str.(type) {
+	case []byte:
+		return r.Match(v)
+	case string:
+		return r.MatchString(v)
+	default:
+		return r.MatchString(fmt.Sprint(v))
+	}
 
 }
 


Test patch:
diff --git a/assert/assertions_test.go b/assert/assertions_test.go
index 0ae36cd..fa68fe2 100644
--- a/assert/assertions_test.go
+++ b/assert/assertions_test.go
@@ -1972,13 +1972,16 @@ func TestRegexp(t *testing.T) {
 	}{
 		{"^start", "start of the line"},
 		{"end$", "in the end"},
+		{"end$", "in the end"},
 		{"[0-9]{3}[.-]?[0-9]{2}[.-]?[0-9]{2}", "My phone number is 650.12.34"},
 	}
 
 	for _, tc := range cases {
 		True(t, Regexp(mockT, tc.rx, tc.str))
 		True(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str))
+		True(t, Regexp(mockT, regexp.MustCompile(tc.rx), []byte(tc.str)))
 		False(t, NotRegexp(mockT, tc.rx, tc.str))
+		False(t, NotRegexp(mockT, tc.rx, []byte(tc.str)))
 		False(t, NotRegexp(mockT, regexp.MustCompile(tc.rx), tc.str))
 	}
 
@@ -1993,7 +1996,9 @@ func TestRegexp(t *testing.T) {
 	for _, tc := range cases {
 		False(t, Regexp(mockT, tc.rx, tc.str), "Expected \"%s\" to not match \"%s\"", tc.rx, tc.str)
 		False(t, Regexp(mockT, regexp.MustCompile(tc.rx), tc.str))
+		False(t, Regexp(mockT, regexp.MustCompile(tc.rx), []byte(tc.str)))
 		True(t, NotRegexp(mockT, tc.rx, tc.str))
+		True(t, NotRegexp(mockT, tc.rx, []byte(tc.str)))
 		True(t, NotRegexp(mockT, regexp.MustCompile(tc.rx), tc.str))
 	}
 }
Repository: stretchr/testify
Pull request #1681 (2024-11-18 12:14:27)

Improve ErrorIs message when error is nil but an error was expected
## Summary
This improves the UX of users of `ErrorIs()` in case the value `nil` is passed for `err` while an error was expected.

## Changes
- added check if `err == nil && target != nil` -> return a special error-string 
- updated relevant test case

## Motivation
The error message when an error is expected but `err` is `nil` (a common occurence in the world of testing) could be more helpful, e.g.:
```
(before)
some_test.go:20:
                Error Trace:    /[...]/some_test.go:20
                Error:          Target error should be in err chain:
                                expected: "sample error message"
                                in chain:
```
vs
```
(after)
some_test.go:20:
                Error Trace:    /[...]/some_test.go:20
                Error:          Expected error with "sample error message" in chain but got nil.
```




Patch:
diff --git a/assert/assertions.go b/assert/assertions.go
index 4e91332..c0f1f68 100644
--- a/assert/assertions.go
+++ b/assert/assertions.go
@@ -2100,6 +2100,9 @@ func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool {
 	var expectedText string
 	if target != nil {
 		expectedText = target.Error()
+		if err == nil {
+			return Fail(t, fmt.Sprintf("Expected error with %q in chain but got nil.", expectedText), msgAndArgs...)
+		}
 	}
 
 	chain := buildErrorChainString(err)


Test patch:
diff --git a/assert/assertions_test.go b/assert/assertions_test.go
index 9f859fa..a5e54b1 100644
--- a/assert/assertions_test.go
+++ b/assert/assertions_test.go
@@ -3237,13 +3237,10 @@ func TestErrorIs(t *testing.T) {
 				"in chain: \"EOF\"\n",
 		},
 		{
-			err:    nil,
-			target: io.EOF,
-			result: false,
-			resultErrMsg: "" +
-				"Target error should be in err chain:\n" +
-				"expected: \"EOF\"\n" +
-				"in chain: \n",
+			err:          nil,
+			target:       io.EOF,
+			result:       false,
+			resultErrMsg: "Expected error with \"EOF\" in chain but got nil.\n",
 		},
 		{
 			err:    io.EOF,
Repository: stretchr/testify
Pull request #1684 (2024-12-10 12:22:28)

Replace deprecated io/ioutil with io and os
## Summary

This PR replaces function usages from `io/ioutil` with the same functions from `io` and `os`. 

## Changes

- replace `ioutil.ReadFile` with `os.ReadFile`
- replace `ioutil.ReadAll` with `io.ReadAll`

## Motivation

[io/ioutil](https://pkg.go.dev/io/ioutil) is deprecated:

> Deprecated: As of Go 1.16, the same functionality is now provided by package [io](https://pkg.go.dev/io) or package [os](https://pkg.go.dev/os), and those implementations should be preferred in new code. See the specific function documentation for details.


## Related issues

#1305 #1386 #1407 #1469


Patch:
diff --git a/_codegen/main.go b/_codegen/main.go
index 7158afc..e193a74 100644
--- a/_codegen/main.go
+++ b/_codegen/main.go
@@ -16,7 +16,6 @@ import (
 	"go/token"
 	"go/types"
 	"io"
-	"io/ioutil"
 	"log"
 	"os"
 	"path"
@@ -101,7 +100,7 @@ func parseTemplates() (*template.Template, *template.Template, error) {
 		return nil, nil, err
 	}
 	if *tmplFile != "" {
-		f, err := ioutil.ReadFile(*tmplFile)
+		f, err := os.ReadFile(*tmplFile)
 		if err != nil {
 			return nil, nil, err
 		}
@@ -183,7 +182,7 @@ func parsePackageSource(pkg string) (*types.Scope, *doc.Package, error) {
 	files := make(map[string]*ast.File)
 	fileList := make([]*ast.File, len(pd.GoFiles))
 	for i, fname := range pd.GoFiles {
-		src, err := ioutil.ReadFile(path.Join(pd.Dir, fname))
+		src, err := os.ReadFile(path.Join(pd.Dir, fname))
 		if err != nil {
 			return nil, nil, err
 		}


Test patch:
diff --git a/suite/suite_test.go b/suite/suite_test.go
index b97eb43..eceecb6 100644
--- a/suite/suite_test.go
+++ b/suite/suite_test.go
@@ -4,7 +4,7 @@ import (
 	"bytes"
 	"errors"
 	"flag"
-	"io/ioutil"
+	"io"
 	"math/rand"
 	"os"
 	"os/exec"
@@ -440,7 +440,7 @@ func (sc *StdoutCapture) StopCapture() (string, error) {
 	}
 	os.Stdout.Close()
 	os.Stdout = sc.oldStdout
-	bytes, err := ioutil.ReadAll(sc.readPipe)
+	bytes, err := io.ReadAll(sc.readPipe)
 	if err != nil {
 		return "", err
 	}
Repository: jshint/jshint
Pull request #2200 (2015-02-27 04:20:12)

[[FIX]] Prevent beginning array from being confused for JSON
src/jshint.js was reading an array at the beginning of a file as JSON instead
of a code block. The parser read the '(begin)' token and then looped 15 times
looking for an end to the block, didn't find it, and considered itself to be
parsing JSON. JSON must use *only* double quotes to be valid, so single quotes
caused warnings.

[JSON spec](http://www.ietf.org/rfc/rfc4627.txt)



Patch:
diff --git a/src/jshint.js b/src/jshint.js
index ee302c54..bd4c6879 100644
--- a/src/jshint.js
+++ b/src/jshint.js
@@ -4609,7 +4609,7 @@ var JSHINT = (function() {
         ret.isBlock = true;
         ret.notJson = true;
       }
-    } while (bracketStack > 0 && pn.id !== "(end)" && i < 15);
+    } while (bracketStack > 0 && pn.id !== "(end)");
     return ret;
   };
 


Test patch:
diff --git a/tests/unit/core.js b/tests/unit/core.js
index 83b8fc2b..e7866f37 100644
--- a/tests/unit/core.js
+++ b/tests/unit/core.js
@@ -1170,3 +1170,14 @@ exports.testPermitEvalAsKey = function (test) {
   test.done();
 
 };
+
+// gh-2194 jshint confusing arrays at beginning of file with JSON
+exports.beginningArraysAreNotJSON = function (test) {
+  var src = fs.readFileSync(__dirname + "/fixtures/gh-2194.js", "utf8");
+
+  TestRun(test)
+  .test(src);
+
+  test.done();
+
+};
diff --git a/tests/unit/fixtures/gh-2194.js b/tests/unit/fixtures/gh-2194.js
new file mode 100644
index 00000000..cbd7e269
--- /dev/null
+++ b/tests/unit/fixtures/gh-2194.js
@@ -0,0 +1,3 @@
+[ 'w','a','f','f','l','e','s','a','r','e','a','w','e','s','o','m','e' ].map(function(letter) {
+  return letter;
+});