nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: zeromicro/go-zero
Pull request #3259 (2023-05-18 15:36:04)

chore: add more tests


Patch:
diff --git a/core/stat/internal/cgroup_linux.go b/core/stat/internal/cgroup_linux.go
index 5b220549..23bdda48 100644
--- a/core/stat/internal/cgroup_linux.go
+++ b/core/stat/internal/cgroup_linux.go
@@ -3,6 +3,7 @@ package internal
 import (
 	"bufio"
 	"fmt"
+	"math"
 	"os"
 	"path"
 	"strconv"
@@ -280,7 +281,7 @@ func runningInUserNS() bool {
 
 		// We assume we are in the initial user namespace if we have a full
 		// range - 4294967295 uids starting at uid 0.
-		if a == 0 && b == 0 && c == 4294967295 {
+		if a == 0 && b == 0 && c == math.MaxUint32 {
 			return
 		}
 		inUserNS = true


Test patch:
diff --git a/core/stat/internal/cgroup_linux_test.go b/core/stat/internal/cgroup_linux_test.go
new file mode 100644
index 00000000..a2faaf77
--- /dev/null
+++ b/core/stat/internal/cgroup_linux_test.go
@@ -0,0 +1,12 @@
+package internal
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestRunningInUserNS(t *testing.T) {
+	// should be false in docker
+	assert.False(t, runningInUserNS())
+}
Repository: zeromicro/go-zero
Pull request #3261 (2023-05-18 17:24:21)

chore: add more tests

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3261?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3261](https://app.codecov.io/gh/zeromicro/go-zero/pull/3261?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (4fbeca9) into [master](https://app.codecov.io/gh/zeromicro/go-zero/commit/99ce24e2ab936050c8d3135294e84cbf0840a346?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (99ce24e) will **increase** coverage by `0.08%`.
> The diff coverage is `n/a`.

> :exclamation: Current head 4fbeca9 differs from pull request most recent head d24c7a0. Consider uploading reports for the commit d24c7a0 to get more accurate results


[see 1 file with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3261/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/core/prof/runtime.go b/core/prof/runtime.go
index 17ede442..af41d051 100644
--- a/core/prof/runtime.go
+++ b/core/prof/runtime.go
@@ -2,6 +2,8 @@ package prof
 
 import (
 	"fmt"
+	"io"
+	"os"
 	"runtime"
 	"time"
 )
@@ -13,6 +15,10 @@ const (
 
 // DisplayStats prints the goroutine, memory, GC stats with given interval, default to 5 seconds.
 func DisplayStats(interval ...time.Duration) {
+	displayStatsWithWriter(os.Stdout, interval...)
+}
+
+func displayStatsWithWriter(writer io.Writer, interval ...time.Duration) {
 	duration := defaultInterval
 	for _, val := range interval {
 		duration = val
@@ -24,7 +30,7 @@ func DisplayStats(interval ...time.Duration) {
 		for range ticker.C {
 			var m runtime.MemStats
 			runtime.ReadMemStats(&m)
-			fmt.Printf("Goroutines: %d, Alloc: %vm, TotalAlloc: %vm, Sys: %vm, NumGC: %v\n",
+			fmt.Fprintf(writer, "Goroutines: %d, Alloc: %vm, TotalAlloc: %vm, Sys: %vm, NumGC: %v\n",
 				runtime.NumGoroutine(), m.Alloc/mega, m.TotalAlloc/mega, m.Sys/mega, m.NumGC)
 		}
 	}()


Test patch:
diff --git a/core/prof/runtime_test.go b/core/prof/runtime_test.go
new file mode 100644
index 00000000..208e75f5
--- /dev/null
+++ b/core/prof/runtime_test.go
@@ -0,0 +1,36 @@
+package prof
+
+import (
+	"strings"
+	"sync"
+	"testing"
+	"time"
+
+	"github.com/stretchr/testify/assert"
+)
+
+func TestDisplayStats(t *testing.T) {
+	writer := &threadSafeBuffer{
+		buf: strings.Builder{},
+	}
+	displayStatsWithWriter(writer, time.Millisecond*10)
+	time.Sleep(time.Millisecond * 50)
+	assert.Contains(t, writer.String(), "Goroutines: ")
+}
+
+type threadSafeBuffer struct {
+	buf  strings.Builder
+	lock sync.Mutex
+}
+
+func (b *threadSafeBuffer) String() string {
+	b.lock.Lock()
+	defer b.lock.Unlock()
+	return b.buf.String()
+}
+
+func (b *threadSafeBuffer) Write(p []byte) (n int, err error) {
+	b.lock.Lock()
+	defer b.lock.Unlock()
+	return b.buf.Write(p)
+}
Repository: zeromicro/go-zero
Pull request #3295 (2023-05-28 12:01:04)

chore: refactor

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3295?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3295](https://app.codecov.io/gh/zeromicro/go-zero/pull/3295?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (5a2d81a) into [master](https://app.codecov.io/gh/zeromicro/go-zero/commit/1b5946346e40a5184e53b637b0e088cce1365ee6?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (1b59463) will **decrease** coverage by `0.02%`.
> The diff coverage is `n/a`.


| [Impacted Files](https://app.codecov.io/gh/zeromicro/go-zero/pull/3295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [core/trace/agent.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS90cmFjZS9hZ2VudC5nbw==) | `94.04% <ø> (-0.08%)` | :arrow_down: |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3295/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/core/trace/agent.go b/core/trace/agent.go
index 5823a0a6..efdf1c31 100644
--- a/core/trace/agent.go
+++ b/core/trace/agent.go
@@ -33,7 +33,6 @@ var (
 
 // StartAgent starts an opentelemetry agent.
 func StartAgent(c Config) {
-
 	if c.Disabled {
 		return
 	}
diff --git a/core/trace/config.go b/core/trace/config.go
index d1b32749..5b96a5e0 100644
--- a/core/trace/config.go
+++ b/core/trace/config.go
@@ -17,7 +17,6 @@ type Config struct {
 	// For example
 	// /v1/traces
 	OtlpHttpPath string `json:",optional"`
-
-	// Disabled indicates whether StartAgent should be called when starting the server.
-	Disabled bool
+	// Disabled indicates whether StartAgent starts the agent.
+	Disabled bool `json:",optional"`
 }


Test patch:
diff --git a/core/trace/agent_test.go b/core/trace/agent_test.go
index 36edba21..6101c51d 100644
--- a/core/trace/agent_test.go
+++ b/core/trace/agent_test.go
@@ -73,6 +73,7 @@ func TestStartAgent(t *testing.T) {
 	StartAgent(c6)
 	StartAgent(c7)
 	StartAgent(c8)
+	defer StopAgent()
 
 	lock.Lock()
 	defer lock.Unlock()
Repository: zeromicro/go-zero
Pull request #3348 (2023-06-14 16:16:19)

(goctl)fix: #3328
- fix issue #3328 

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3348?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3348](https://app.codecov.io/gh/zeromicro/go-zero/pull/3348?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (2614023) into [master](https://app.codecov.io/gh/zeromicro/go-zero/commit/2fdc4dfc0fbcd4226f79269bc143448a5051edcf?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (2fdc4df) will **decrease** coverage by `0.02%`.
> The diff coverage is `n/a`.


[see 1 file with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3348/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/tools/goctl/internal/version/version.go b/tools/goctl/internal/version/version.go
index 103fe713..fe9f7afa 100644
--- a/tools/goctl/internal/version/version.go
+++ b/tools/goctl/internal/version/version.go
@@ -6,7 +6,7 @@ import (
 )
 
 // BuildVersion is the version of goctl.
-const BuildVersion = "1.5.3"
+const BuildVersion = "1.5.4"
 
 var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
 
diff --git a/tools/goctl/model/sql/example/sql/user.sql b/tools/goctl/model/sql/example/sql/user.sql
index 8fac2a3c..9b1cc67a 100644
--- a/tools/goctl/model/sql/example/sql/user.sql
+++ b/tools/goctl/model/sql/example/sql/user.sql
@@ -30,5 +30,6 @@ CREATE TABLE `student`
 ) DEFAULT NULL,
   `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
   `update_time` timestamp NULL DEFAULT NULL,
+  `delete_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
   PRIMARY KEY (`type`) USING BTREE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
\ No newline at end of file


Test patch:
diff --git a/tools/goctl/model/sql/parser/testdata/user.sql b/tools/goctl/model/sql/parser/testdata/user.sql
index 66749931..1113f7a1 100644
--- a/tools/goctl/model/sql/parser/testdata/user.sql
+++ b/tools/goctl/model/sql/parser/testdata/user.sql
@@ -7,6 +7,8 @@ CREATE TABLE `test_user`
   名',
     `create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP comment '创建\r时间',
     `update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    `delete_time` timestamp NULL DEFAULT NULL,
+    `delete_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
     PRIMARY KEY (`id`),
     UNIQUE KEY `mobile_unique` (`mobile`),
     UNIQUE KEY `class_name_unique` (`class`,`name`),
Repository: zeromicro/go-zero
Pull request #3413 (2023-07-11 16:36:27)

chore: coding style


Patch:
diff --git a/core/mapping/unmarshaler.go b/core/mapping/unmarshaler.go
index 24920338..a346469e 100644
--- a/core/mapping/unmarshaler.go
+++ b/core/mapping/unmarshaler.go
@@ -618,7 +618,7 @@ func (u *Unmarshaler) processFieldPrimitiveWithJSONNumber(fieldType reflect.Type
 
 		target.SetFloat(fValue)
 	default:
-		return newTypeMismatchErrorWithHint(fullName, value.Type().String(), typeKind.String())
+		return newTypeMismatchErrorWithHint(fullName, typeKind.String(), value.Type().String())
 	}
 
 	SetValue(fieldType, value, target)
@@ -1054,8 +1054,9 @@ func newTypeMismatchError(name string) error {
 	return fmt.Errorf("type mismatch for field %q", name)
 }
 
-func newTypeMismatchErrorWithHint(name, errorType, rightType string) error {
-	return fmt.Errorf("type mismatch for field %q, expected %q, got %q", name, rightType, errorType)
+func newTypeMismatchErrorWithHint(name, expectType, actualType string) error {
+	return fmt.Errorf("type mismatch for field %q, expect %q, actual %q",
+		name, expectType, actualType)
 }
 
 func readKeys(key string) []string {


Test patch:
diff --git a/core/mapping/unmarshaler_test.go b/core/mapping/unmarshaler_test.go
index fae6f3ef..8739d49b 100644
--- a/core/mapping/unmarshaler_test.go
+++ b/core/mapping/unmarshaler_test.go
@@ -4991,10 +4991,12 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) {
 		value := reflect.ValueOf(&realValue) // pass a pointer to the value
 		v := json.Number(expectValue)
 		m := NewUnmarshaler("field")
-		err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v, &fieldOptionsWithContext{}, "field")
+		err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v,
+			&fieldOptionsWithContext{}, "field")
 		assert.Error(t, err)
-		assert.Equal(t, "type mismatch for field \"field\", expected \"string\", got \"int\"", err.Error())
+		assert.Equal(t, `type mismatch for field "field", expect "string", actual "int"`, err.Error())
 	})
+
 	t.Run("right type", func(t *testing.T) {
 		expectValue := int64(1)
 		realValue := int64(1)
@@ -5002,10 +5004,10 @@ func TestUnmarshalerProcessFieldPrimitiveWithJSONNumber(t *testing.T) {
 		value := reflect.ValueOf(&realValue) // pass a pointer to the value
 		v := json.Number(strconv.FormatInt(expectValue, 10))
 		m := NewUnmarshaler("field")
-		err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v, &fieldOptionsWithContext{}, "field")
+		err := m.processFieldPrimitiveWithJSONNumber(fieldType, value.Elem(), v,
+			&fieldOptionsWithContext{}, "field")
 		assert.NoError(t, err)
 	})
-
 }
 
 func TestGetValueWithChainedKeys(t *testing.T) {
Repository: zeromicro/go-zero
Pull request #3573 (2023-09-16 19:59:07)

fix: avoid losing logs before closing

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3573?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3573](https://app.codecov.io/gh/zeromicro/go-zero/pull/3573?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (9596859) into [master](https://app.codecov.io/gh/zeromicro/go-zero/commit/0dcede645782184eaff390285d7204b37b0f0ed9?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (0dcede6) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.


| [Files Changed](https://app.codecov.io/gh/zeromicro/go-zero/pull/3573?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [core/logx/rotatelogger.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3573?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS9sb2d4L3JvdGF0ZWxvZ2dlci5nbw==) | `89.89% <100.00%> (+1.36%)` | :arrow_up: |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3573/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/core/logx/rotatelogger.go b/core/logx/rotatelogger.go
index c8ef43a7..58a609d1 100644
--- a/core/logx/rotatelogger.go
+++ b/core/logx/rotatelogger.go
@@ -381,7 +381,15 @@ func (l *RotateLogger) startWorker() {
 			case event := <-l.channel:
 				l.write(event)
 			case <-l.done:
-				return
+				// avoid losing logs before closing.
+				for {
+					select {
+					case event := <-l.channel:
+						l.write(event)
+					default:
+						return
+					}
+				}
 			}
 		}
 	}()


Test patch:
diff --git a/core/logx/rotatelogger_test.go b/core/logx/rotatelogger_test.go
index 68269f6e..ff0fdea1 100644
--- a/core/logx/rotatelogger_test.go
+++ b/core/logx/rotatelogger_test.go
@@ -206,6 +206,27 @@ func TestRotateLoggerClose(t *testing.T) {
 		_, err := logger.Write([]byte("foo"))
 		assert.ErrorIs(t, err, ErrLogFileClosed)
 	})
+
+	t.Run("close without losing logs", func(t *testing.T) {
+		text := "foo"
+		filename, err := fs.TempFilenameWithText(text)
+		assert.Nil(t, err)
+		if len(filename) > 0 {
+			defer os.Remove(filename)
+		}
+		logger, err := NewLogger(filename, new(DailyRotateRule), false)
+		assert.Nil(t, err)
+		msg := []byte("foo")
+		n := 100
+		for i := 0; i < n; i++ {
+			_, err = logger.Write(msg)
+			assert.Nil(t, err)
+		}
+		assert.Nil(t, logger.Close())
+		bs, err := os.ReadFile(filename)
+		assert.Nil(t, err)
+		assert.Equal(t, len(msg)*n+len(text), len(bs))
+	})
 }
 
 func TestRotateLoggerGetBackupFilename(t *testing.T) {
Repository: zeromicro/go-zero
Pull request #3587 (2023-09-24 11:04:08)

chore: add test for logging rotate size

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/zeromicro/go-zero/pull/3587?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#3587](https://app.codecov.io/gh/zeromicro/go-zero/pull/3587?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (1b47468) into [master](https://app.codecov.io/gh/zeromicro/go-zero/commit/ded2888759fd4c9d3f8c8ea324654bc494c9529e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (ded2888) will **decrease** coverage by `0.05%`.
> Report is 1 commits behind head on master.
> The diff coverage is `n/a`.

> :exclamation: Current head 1b47468 differs from pull request most recent head 9998d68. Consider uploading reports for the commit 9998d68 to get more accurate results


| [Files Changed](https://app.codecov.io/gh/zeromicro/go-zero/pull/3587?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Coverage Δ | |
|---|---|---|
| [core/logx/rotatelogger.go](https://app.codecov.io/gh/zeromicro/go-zero/pull/3587?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-Y29yZS9sb2d4L3JvdGF0ZWxvZ2dlci5nbw==) | `88.77% <ø> (-1.06%)` | :arrow_down: |

... and [1 file with indirect coverage changes](https://app.codecov.io/gh/zeromicro/go-zero/pull/3587/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None)


Patch:
diff --git a/core/logx/rotatelogger.go b/core/logx/rotatelogger.go
index 58a609d1..4b7f31e7 100644
--- a/core/logx/rotatelogger.go
+++ b/core/logx/rotatelogger.go
@@ -298,6 +298,7 @@ func (l *RotateLogger) initialize() error {
 		if l.fp, err = os.OpenFile(l.filename, os.O_APPEND|os.O_WRONLY, defaultFileMode); err != nil {
 			return err
 		}
+
 		l.currentSize = fileInfo.Size()
 	}
 


Test patch:
diff --git a/core/logx/rotatelogger_test.go b/core/logx/rotatelogger_test.go
index ff0fdea1..f370aa8c 100644
--- a/core/logx/rotatelogger_test.go
+++ b/core/logx/rotatelogger_test.go
@@ -517,6 +517,21 @@ func TestGzipFile(t *testing.T) {
 	})
 }
 
+func TestRotateLogger_WithExistingFile(t *testing.T) {
+	const body = "foo"
+	filename, err := fs.TempFilenameWithText(body)
+	assert.Nil(t, err)
+	if len(filename) > 0 {
+		defer os.Remove(filename)
+	}
+
+	rule := NewSizeLimitRotateRule(filename, "-", 1, 100, 3, false)
+	logger, err := NewLogger(filename, rule, false)
+	assert.Nil(t, err)
+	assert.Equal(t, int64(len(body)), logger.currentSize)
+	assert.Nil(t, logger.Close())
+}
+
 func BenchmarkRotateLogger(b *testing.B) {
 	filename := "./test.log"
 	filename2 := "./test2.log"
Repository: un-ts/eslint-plugin-import-x
Pull request #204 (2024-12-12 09:43:42)

fix(`no-duplicates`): merge type import `as` with value import
There was a bug when merging a type-import with a value-import, when the type import uses `import-as` syntax.

This handles the `import-as` case.

changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: ebdbab403a200ecc520dabf75345095c047ee093

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/privatenumber/eslint-plugin-import-x/new/no-duplicate-fix-bug?filename=.changeset/good-houses-approve.md&value=---%0A%22eslint-plugin-import-x%22%3A%20patch%0A---%0A%0Afailing%20test%3A%20%60no-duplicates%60%20auto-fix%20bug%0A)



Patch:
diff --git a/.changeset/tasty-llamas-deny.md b/.changeset/tasty-llamas-deny.md
new file mode 100644
index 00000000..6bd620af
--- /dev/null
+++ b/.changeset/tasty-llamas-deny.md
@@ -0,0 +1,5 @@
+---
+"eslint-plugin-import-x": patch
+---
+
+fix type-import and value-import merging when import-as is used
diff --git a/src/rules/no-duplicates.ts b/src/rules/no-duplicates.ts
index 93813609..b4732f75 100644
--- a/src/rules/no-duplicates.ts
+++ b/src/rules/no-duplicates.ts
@@ -152,7 +152,7 @@ function getFix(
           sourceCode.text
             .slice(openBrace.range[1], closeBrace.range[0])
             .split(',')
-            .map(x => x.trim()),
+            .map(x => x.split(' as ')[0].trim()),
         )
 
     const [specifiersText] = specifiers.reduce(


Test patch:
diff --git a/test/rules/no-duplicates.spec.ts b/test/rules/no-duplicates.spec.ts
index b941d1ec..f71a0d54 100644
--- a/test/rules/no-duplicates.spec.ts
+++ b/test/rules/no-duplicates.spec.ts
@@ -818,6 +818,24 @@ describe('TypeScript', () => {
               },
             ],
           }),
+          tInvalid({
+            code: "import type { AType as BType } from './foo'; import { CValue } from './foo'",
+            ...parserConfig,
+            options: [{ 'prefer-inline': true }],
+            output: `import { type AType as BType , CValue } from './foo'; `,
+            errors: [
+              {
+                ...createDuplicatedError('./foo'),
+                line: 1,
+                column: 37,
+              },
+              {
+                ...createDuplicatedError('./foo'),
+                line: 1,
+                column: 69,
+              },
+            ],
+          }),
         ]),
   ]
Repository: elm-tooling/elm-language-server
Pull request #896 (2023-02-25 23:05:54)

Fix extract function including type constructors as variables


Patch:
diff --git a/src/providers/codeAction/extractFunctionCodeAction.ts b/src/providers/codeAction/extractFunctionCodeAction.ts
index d69f1de..8f083f0 100644
--- a/src/providers/codeAction/extractFunctionCodeAction.ts
+++ b/src/providers/codeAction/extractFunctionCodeAction.ts
@@ -145,6 +145,11 @@ CodeActionProvider.registerRefactorAction(refactorName, {
           return;
         }
 
+        // Types are always visible
+        if (val.firstNamedChild?.type === "upper_case_qid") {
+          return;
+        }
+
         // If we find it in the scope we are extracting, it should not be a arg
         let scope: SyntaxNode | null = val;
         while (scope && scope.id !== nodeParent?.id) {


Test patch:
diff --git a/test/codeActionTests/extractFunctionCodeAction.test.ts b/test/codeActionTests/extractFunctionCodeAction.test.ts
index 89297d7..de8fdba 100644
--- a/test/codeActionTests/extractFunctionCodeAction.test.ts
+++ b/test/codeActionTests/extractFunctionCodeAction.test.ts
@@ -342,4 +342,61 @@ foo val str =
       expectedSource,
     );
   });
+
+  it("should extract function and compute parameters - union constructors are not parameters", async () => {
+    const source = `
+--@ Test.elm
+module Test exposing (..)
+
+val2 = 
+    0
+
+foo val str =
+    case val of
+        Just { field1, field2, field3 } ->
+            case field1 of
+          --^
+                Just { prop1, prop2 } ->
+                    Just (prop1 + prop2 + val + field2)
+
+                Nothing ->
+                    field2 + val2
+                               --^
+
+        Nothing ->
+            str + val2
+`;
+
+    const expectedSource = `
+--@ Test.elm
+module Test exposing (..)
+
+val2 = 
+    0
+
+foo val str =
+    case val of
+        Just { field1, field2, field3 } ->
+            newFunction field1 val field2
+
+        Nothing ->
+            str + val2
+
+
+newFunction : Maybe { a | prop1 : number, prop2 : number } -> Maybe { b | field1 : Maybe { a | prop1 : number, prop2 : number }, field2 : unknown, field3 : c } -> unknown -> Maybe unknown
+newFunction field1 val field2 =
+    case field1 of
+        Just { prop1, prop2 } ->
+            Just (prop1 + prop2 + val + field2)
+
+        Nothing ->
+            field2 + val2
+`;
+
+    await testCodeAction(
+      source,
+      [{ title: "Extract function to top level" }],
+      expectedSource,
+    );
+  });
 });