Jelajahi Sumber

Re-enable staticcheck, and fix issues it found.

Qi Xiao 2 tahun lalu
induk
melakukan
aa6d5a6257
5 mengubah file dengan 19 tambahan dan 22 penghapusan
  1. 1 1
      .github/workflows/ci.yml
  2. 1 4
      CONTRIBUTING.md
  3. 14 15
      pkg/eval/builtin_special_test.go
  4. 2 0
      pkg/mods/str/str.go
  5. 1 2
      tools/lint.sh

+ 1 - 1
.github/workflows/ci.yml

@@ -193,7 +193,7 @@ jobs:
       with:
         go-version: 1.18.x
     - name: Set up staticcheck
-      run: go install honnef.co/go/tools/cmd/staticcheck@master
+      run: go install honnef.co/go/tools/cmd/staticcheck@v0.3.2
     - name: Run linters
       run: ./tools/lint.sh
 

+ 1 - 4
CONTRIBUTING.md

@@ -159,7 +159,7 @@ formatted.
 Install [staticcheck](https://staticcheck.io):
 
 ```sh
-go install honnef.co/go/tools/cmd/staticcheck@master
+go install honnef.co/go/tools/cmd/staticcheck@v0.3.2
 ```
 
 The other linter Elvish uses is the standard `go vet` command. Elvish doesn't
@@ -168,9 +168,6 @@ use golint since it is
 
 Use `make lint` to run `staticcheck` and `go vet`.
 
-**Note**: As of writing, `staticcheck` doesn't support generics yet (it will
-crash when checking code using generics), so it has been temporarily disabled.
-
 ### Spell checking
 
 Install [codespell](https://github.com/codespell-project/codespell) to check

+ 14 - 15
pkg/eval/builtin_special_test.go

@@ -14,7 +14,6 @@ import (
 	"src.elv.sh/pkg/testutil"
 
 	. "src.elv.sh/pkg/eval/evaltest"
-	. "src.elv.sh/pkg/testutil"
 )
 
 func TestPragma(t *testing.T) {
@@ -184,7 +183,7 @@ func (v *badVar) Set(any) error {
 }
 
 func TestDel(t *testing.T) {
-	Setenv(t, "TEST_ENV", "test value")
+	testutil.Setenv(t, "TEST_ENV", "test value")
 
 	Test(t,
 		// Deleting variable
@@ -427,9 +426,9 @@ func TestFn(t *testing.T) {
 
 // Regression test for #1225
 func TestUse_SetsVariableCorrectlyIfModuleCallsExtendGlobal(t *testing.T) {
-	libdir := InTempDir(t)
+	libdir := testutil.InTempDir(t)
 
-	ApplyDir(Dir{"a.elv": "add-var"})
+	testutil.ApplyDir(testutil.Dir{"a.elv": "add-var"})
 	ev := NewEvaler()
 	ev.LibDirs = []string{libdir}
 	addVar := func() {
@@ -452,8 +451,8 @@ func TestUse_SetsVariableCorrectlyIfModuleCallsExtendGlobal(t *testing.T) {
 }
 
 func TestUse_SupportsCircularDependency(t *testing.T) {
-	libdir := InTempDir(t)
-	ApplyDir(Dir{
+	libdir := testutil.InTempDir(t)
+	testutil.ApplyDir(testutil.Dir{
 		"a.elv": "var pre = apre; use b; put $b:pre $b:post; var post = apost",
 		"b.elv": "var pre = bpre; use a; put $a:pre $a:post; var post = bpost",
 	})
@@ -469,21 +468,21 @@ func TestUse_SupportsCircularDependency(t *testing.T) {
 }
 
 func TestUse(t *testing.T) {
-	libdir1 := InTempDir(t)
-	ApplyDir(Dir{
+	libdir1 := testutil.InTempDir(t)
+	testutil.ApplyDir(testutil.Dir{
 		"shadow.elv": "put lib1",
 	})
 
-	libdir2 := InTempDir(t)
-	ApplyDir(Dir{
+	libdir2 := testutil.InTempDir(t)
+	testutil.ApplyDir(testutil.Dir{
 		"has-init.elv": "put has-init",
 		"put-x.elv":    "put $x",
 		"lorem.elv":    "var name = lorem; fn put-name { put $name }",
 		"d.elv":        "var name = d",
 		"shadow.elv":   "put lib2",
-		"a": Dir{
-			"b": Dir{
-				"c": Dir{
+		"a": testutil.Dir{
+			"b": testutil.Dir{
+				"c": testutil.Dir{
 					"d.elv": "var name = a/b/c/d",
 					"x.elv": "use ./d; var d = $d:name; use ../../../lorem; var lorem = $lorem:name",
 				},
@@ -546,8 +545,8 @@ func TestUse(t *testing.T) {
 // Regression test for #1072
 func TestUse_WarnsAboutDeprecatedFeatures(t *testing.T) {
 	testutil.Set(t, &prog.DeprecationLevel, 18)
-	libdir := InTempDir(t)
-	MustWriteFile("dep.elv", "a=b nop $a")
+	libdir := testutil.InTempDir(t)
+	testutil.MustWriteFile("dep.elv", "a=b nop $a")
 
 	TestWithSetup(t, func(ev *Evaler) { ev.LibDirs = []string{libdir} },
 		// Importing module triggers check for deprecated features

+ 2 - 0
pkg/mods/str/str.go

@@ -36,6 +36,8 @@ var Ns = eval.BuildNsNamed("str").
 		"replace": replace,
 		"split":   split,
 		// TODO: SplitAfter
+		//lint:ignore SA1019 Elvish builtins need to be formally deprecated
+		// before removal
 		"title":         strings.Title,
 		"to-codepoints": toCodepoints,
 		"to-lower":      strings.ToLower,

+ 1 - 2
tools/lint.sh

@@ -1,4 +1,3 @@
 #!/bin/sh -e
 go vet ./...
-# TODO: Enable staticcheck when it supports generics
-#staticcheck ./...
+staticcheck ./...