nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: tomarrell/lbadd
Pull request #54 (2020-02-24 13:52:06)

Nopanic


Patch:
diff --git a/internal/tool/analysis/analysis.go b/internal/tool/analysis/analysis.go
index 56f07c8..16a186f 100644
--- a/internal/tool/analysis/analysis.go
+++ b/internal/tool/analysis/analysis.go
@@ -1,9 +1,14 @@
 package main
 
-import "golang.org/x/tools/go/analysis/multichecker"
+import (
+	"github.com/tomarrell/lbadd/internal/tool/analysis/nopanic"
+	"golang.org/x/tools/go/analysis/multichecker"
+)
 
 func main() {
 	// write an analyzer in a sub-package of this package and add it here as an
 	// argument in multichecker.Main(...).
-	multichecker.Main()
+	multichecker.Main(
+		nopanic.Analyzer,
+	)
 }
diff --git a/internal/tool/analysis/nopanic/nopanic.go b/internal/tool/analysis/nopanic/nopanic.go
new file mode 100644
index 0000000..3fbc704
--- /dev/null
+++ b/internal/tool/analysis/nopanic/nopanic.go
@@ -0,0 +1,46 @@
+// Package nopanic implements an analyzer that checks if somewhere in the
+// source, there is a panic.
+package nopanic
+
+import (
+	"go/ast"
+
+	"golang.org/x/tools/go/analysis"
+	"golang.org/x/tools/go/analysis/passes/inspect"
+	"golang.org/x/tools/go/ast/inspector"
+)
+
+// Analyzer implements the analyzer that checks for panics.
+var Analyzer = &analysis.Analyzer{
+	Name: "nopanic",
+	Doc:  Doc,
+	Run:  run,
+	Requires: []*analysis.Analyzer{
+		inspect.Analyzer,
+	},
+}
+
+// Doc is the documentation string that is shown on the command line if help is
+// requested.
+const Doc = "check if there is any panic in the code"
+
+func run(pass *analysis.Pass) (interface{}, error) {
+	inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
+	inspect.Preorder([]ast.Node{
+		(*ast.CallExpr)(nil),
+	}, func(n ast.Node) {
+		call := n.(*ast.CallExpr)
+		if callExprIsPanic(call) {
+			pass.Reportf(call.Pos(), "panic is disallowed in this location")
+		}
+	})
+	return nil, nil
+}
+
+func callExprIsPanic(call *ast.CallExpr) bool {
+	ident, ok := call.Fun.(*ast.Ident)
+	if !ok {
+		return false
+	}
+	return ident.Name == "panic"
+}


Test patch:
diff --git a/internal/tool/analysis/nopanic/nopanic_test.go b/internal/tool/analysis/nopanic/nopanic_test.go
new file mode 100644
index 0000000..aac4406
--- /dev/null
+++ b/internal/tool/analysis/nopanic/nopanic_test.go
@@ -0,0 +1,17 @@
+package nopanic_test
+
+import (
+	"path/filepath"
+	"testing"
+
+	"github.com/tomarrell/lbadd/internal/tool/analysis/nopanic"
+	"golang.org/x/tools/go/analysis/analysistest"
+)
+
+func TestAnalyzer(t *testing.T) {
+	dir, err := filepath.Abs("./testdata")
+	if err != nil {
+		t.Error(err)
+	}
+	analysistest.Run(t, dir, nopanic.Analyzer, "./...")
+}
diff --git a/internal/tool/analysis/nopanic/testdata/test1.go b/internal/tool/analysis/nopanic/testdata/test1.go
new file mode 100644
index 0000000..f160aa6
--- /dev/null
+++ b/internal/tool/analysis/nopanic/testdata/test1.go
@@ -0,0 +1,5 @@
+package main
+
+func main() {
+	panic(nil) // want `panic is disallowed in this location`
+}
Repository: tomarrell/lbadd
Pull request #73 (2020-03-09 11:37:28)

implement DETACH statement
This PR implements the DETACH statement (https://sqlite.org/lang_detach.html) and completes a part of #66 


Patch:
diff --git a/internal/parser/simple_parser_rules.go b/internal/parser/simple_parser_rules.go
index 3559db3..8147cf7 100644
--- a/internal/parser/simple_parser_rules.go
+++ b/internal/parser/simple_parser_rules.go
@@ -44,6 +44,8 @@ func (p *simpleParser) parseSQLStatement(r reporter) (stmt *ast.SQLStmt) {
 		stmt.AlterTableStmt = p.parseAlterTableStmt(r)
 	case token.KeywordAttach:
 		stmt.AttachStmt = p.parseAttachDatabaseStmt(r)
+	case token.KeywordDetach:
+		stmt.DetachStmt = p.parseDetachDatabaseStmt(r)
 	case token.StatementSeparator:
 		r.incompleteStatement()
 		p.consumeToken()
@@ -676,3 +678,39 @@ func (p *simpleParser) parseAttachDatabaseStmt(r reporter) (stmt *ast.AttachStmt
 	p.consumeToken()
 	return
 }
+
+// parseDetachDatabaseStmt parses statements of the form :
+// DETACH DATABASE schema-name
+// DETACH schema-name
+func (p *simpleParser) parseDetachDatabaseStmt(r reporter) (stmt *ast.DetachStmt) {
+	stmt = &ast.DetachStmt{}
+	p.searchNext(r, token.KeywordDetach)
+	next, ok := p.lookahead(r)
+	if !ok {
+		return
+	}
+	stmt.Detach = next
+	p.consumeToken()
+
+	next, ok = p.lookahead(r)
+	if !ok {
+		return
+	}
+
+	if next.Type() == token.KeywordDatabase {
+		stmt.Database = next
+		p.consumeToken()
+	}
+
+	schemaName, ok := p.lookahead(r)
+	if !ok {
+		return
+	}
+	if schemaName.Type() != token.Literal {
+		r.unexpectedToken(token.Literal)
+		return
+	}
+	stmt.SchemaName = schemaName
+	p.consumeToken()
+	return
+}


Test patch:
diff --git a/internal/parser/parser_test.go b/internal/parser/parser_test.go
index 799ea57..43a3f9a 100644
--- a/internal/parser/parser_test.go
+++ b/internal/parser/parser_test.go
@@ -162,6 +162,25 @@ func TestSingleStatementParse(t *testing.T) {
 				},
 			},
 		},
+		{
+			"DETACH DATABASE newDb",
+			&ast.SQLStmt{
+				DetachStmt: &ast.DetachStmt{
+					Detach:     token.New(1, 1, 0, 6, token.KeywordDetach, "DETACH"),
+					Database:   token.New(1, 8, 7, 8, token.KeywordDatabase, "DATABASE"),
+					SchemaName: token.New(1, 17, 16, 5, token.Literal, "newDb"),
+				},
+			},
+		},
+		{
+			"DETACH newSchema",
+			&ast.SQLStmt{
+				DetachStmt: &ast.DetachStmt{
+					Detach:     token.New(1, 1, 0, 6, token.KeywordDetach, "DETACH"),
+					SchemaName: token.New(1, 8, 7, 9, token.Literal, "newSchema"),
+				},
+			},
+		},
 	}
 	for _, input := range inputs {
 		t.Run(input.Query[0:11], func(t *testing.T) {
Repository: exadel-inc/esl
Pull request #2184 (2024-01-18 16:26:56)

feat(attr): add provider to default value in attr


Patch:
diff --git a/src/modules/esl-utils/decorators/attr.ts b/src/modules/esl-utils/decorators/attr.ts
index 5e1ff998f..683fb5a1a 100644
--- a/src/modules/esl-utils/decorators/attr.ts
+++ b/src/modules/esl-utils/decorators/attr.ts
@@ -1,7 +1,8 @@
-import {identity} from '../misc/functions';
+import {identity, resolveProperty} from '../misc/functions';
 import {parseString, toKebabCase} from '../misc/format';
 import {getAttr, setAttr} from '../dom/attr';
 
+import type {PropertyProvider} from '../misc/functions';
 import type {ESLAttributeDecorator} from '../dom/attr';
 import type {ESLDomElementTarget} from '../abstract/dom-target';
 
@@ -16,8 +17,8 @@ type AttrDescriptor<T = string> = {
   readonly?: boolean;
   /** Use data-* attribute */
   dataAttr?: boolean;
-  /** Default property value. Used if no attribute is present on the element. Empty string by default. */
-  defaultValue?: T;
+  /** Default property value. Used if no attribute is present on the element. Empty string by default. Supports provider function. */
+  defaultValue?: T | PropertyProvider<T>;
   /** Parser from attribute value */
   parser?: AttrParser<T>;
   /** Serializer to transform passed value to attribute value */
@@ -38,7 +39,9 @@ export const attr = <T = string>(config: AttrDescriptor<T> = {}): ESLAttributeDe
 
     function get(): T | null {
       const val = getAttr(this, attrName);
-      if (val === null && 'defaultValue' in config) return config.defaultValue as T;
+      if (val === null && 'defaultValue' in config) {
+        return resolveProperty(config.defaultValue, this) as T;
+      }
       return (config.parser || parseString as AttrParser<any>)(val);
     }
     function set(value: T): void {


Test patch:
diff --git a/src/modules/esl-utils/decorators/test/attr.test.ts b/src/modules/esl-utils/decorators/test/attr.test.ts
index f44f2f865..da959c6bf 100644
--- a/src/modules/esl-utils/decorators/test/attr.test.ts
+++ b/src/modules/esl-utils/decorators/test/attr.test.ts
@@ -18,6 +18,8 @@ describe('Decorator: attr', () => {
     public readonlyField: string | null;
     @attr({defaultValue: 'def'})
     public defField: string | boolean;
+    @attr({defaultValue: () => 'test-provider'})
+    public defProvider: string;
   }
   customElements.define('test-el-attr', TestElement);
   const el = new TestElement();
@@ -99,6 +101,9 @@ describe('Decorator: attr', () => {
     el.defField = false;
     expect(el.defField).toBe('def');
     expect(el.hasAttribute('def-field')).toBe(false);
+    expect(el.defProvider).toBe('test-provider');
+    el.defProvider = '';
+    expect(el.defProvider).toBe('');
   });
 
   afterAll(() => {
Repository: exadel-inc/esl
Pull request #2195 (2024-01-25 14:46:39)

fix(microtask): fix argument list on next fn call
<!--- Provide a general summary of your changes in the Title above -->
<!--- Describe your changes in detail: purpose, special notes -->

Closes: <!--- #123 -->

Relates to: <!--- #123 -->

<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps to reproduce -->
<!--- Please link to the issue here: -->
<!---  or -->

<!--- Checklist -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

<!--- - My change requires a change to the documentation. -->
<!--- - I have updated the documentation accordingly. -->
<!--- - I have added tests to cover my changes. (Unit tests are strongly advisable for changes under `esl-utils` scope -->


<!--- If you like ESL, please support it with a star on GitHub. Thank you! -->



Patch:
diff --git a/src/modules/esl-utils/async/microtask.ts b/src/modules/esl-utils/async/microtask.ts
index 440529814..1f502e2c2 100644
--- a/src/modules/esl-utils/async/microtask.ts
+++ b/src/modules/esl-utils/async/microtask.ts
@@ -3,13 +3,14 @@
  * (as a microtask produced with Promise)
  */
 export function microtask<T>(fn: (...arg: [T?]) => void, thisArg?: object): (arg?: T) => void {
-  const args: T[] = [];
+  let args: T[] = [];
   return function microtaskFn(arg: T): void {
     args.push(arg);
     if ((microtaskFn as any).request) return;
     (microtaskFn as any).request = Promise.resolve().then(() => {
       delete (microtaskFn as any).request;
       fn.call(thisArg || this, args);
+      args = [];
     });
   };
 }


Test patch:
diff --git a/src/modules/esl-utils/async/test/microtask.test.ts b/src/modules/esl-utils/async/test/microtask.test.ts
index 52ba082b1..18dbca4f1 100644
--- a/src/modules/esl-utils/async/test/microtask.test.ts
+++ b/src/modules/esl-utils/async/test/microtask.test.ts
@@ -23,4 +23,16 @@ describe('sync/microtask', () => {
     await Promise.resolve();
     expect(fn).toBeCalledWith(expect.arrayContaining(params));
   });
+  test('Decorated as microtask callback refreshes after decorated method call (leak protected)', async () => {
+    const fn = jest.fn();
+    const decorated = microtask(fn);
+    const params1 = [Symbol('Arg 1'), Symbol('Arg 2')];
+    for (const param of params1) decorated(param);
+    await Promise.resolve();
+
+    const params2 = [Symbol('Arg 3'), Symbol('Arg 4')];
+    for (const param of params2) decorated(param);
+    await Promise.resolve();
+    expect(fn).lastCalledWith(params2);
+  });
 });