Skip to content

Commit

Permalink
feat: Disable Incomplete Checkers (#107)
Browse files Browse the repository at this point in the history
# Description

Disable some lints
  • Loading branch information
notJoon authored Dec 11, 2024
2 parents 5c1bee2 + e4346eb commit 4808a9b
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 641 deletions.
3 changes: 0 additions & 3 deletions internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,15 @@ type ruleMap map[string]ruleConstructor
// Create a map to hold the mappings of rule names to their constructors
var allRuleConstructors = ruleMap{
"golangci-lint": NewGolangciLintRule,
"deprecated-function": NewDeprecateFuncRule,
"early-return-opportunity": NewEarlyReturnOpportunityRule,
"simplify-slice-range": NewSimplifySliceExprRule,
"unnecessary-type-conversion": NewUnnecessaryConversionRule,
"loop-allocation": NewLoopAllocationRule,
"emit-format": NewEmitFormatRule,
"cycle-detection": NewDetectCycleRule,
"unused-package": NewGnoSpecificRule,
"repeated-regex-compilation": NewRepeatedRegexCompilationRule,
"useless-break": NewUselessBreakRule,
"defer-issues": NewDeferRule,
"slice-bounds-check": NewSliceBoundCheckRule,
"const-error-declaration": NewConstErrorDeclarationRule,
}

Expand Down
200 changes: 0 additions & 200 deletions internal/lints/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,107 +218,6 @@ func example() {
}
}

func TestDetectLoopAllocation(t *testing.T) {
t.Parallel()
tests := []struct {
name string
code string
expected int
}{
{
name: "Allocation in for loop",
code: `
package main
func main() {
for i := 0; i < 10; i++ {
_ = make([]int, 10)
}
}`,
expected: 1,
},
{
name: "Allocation in range loop",
code: `
package main
func main() {
slice := []int{1, 2, 3}
for _, v := range slice {
_ = new(int)
_ = v
}
}`,
expected: 1,
},
{
name: "Multiple allocations in loop",
code: `
package main
func main() {
for i := 0; i < 10; i++ {
_ = make([]int, 10)
_ = new(string)
}
}`,
expected: 2,
},
{
name: "No allocation in loop",
code: `
package main
func main() {
slice := make([]int, 10)
for i := 0; i < 10; i++ {
slice[i] = i
}
}`,
expected: 0,
},
{
name: "Allocation outside loop",
code: `
package main
func main() {
_ = make([]int, 10)
for i := 0; i < 10; i++ {
// Do something
}
}`,
expected: 0,
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
tmpDir, err := os.MkdirTemp("", "test")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)

tmpfile := filepath.Join(tmpDir, "test.go")
err = os.WriteFile(tmpfile, []byte(tt.code), 0o644)
require.NoError(t, err)

node, fset, err := ParseFile(tmpfile, nil)
require.NoError(t, err)

issues, err := DetectLoopAllocation(tmpfile, node, fset, types.SeverityError)
require.NoError(t, err)

assert.Equal(t, tt.expected, len(issues), "Number of issues does not match expected")

for _, issue := range issues {
assert.Contains(t, issue.Message, "potential unnecessary allocation inside loop")
}
})
}
}

func TestDetectEmitFormat(t *testing.T) {
t.Parallel()
_, current, _, ok := runtime.Caller(0)
Expand Down Expand Up @@ -441,105 +340,6 @@ func TestFormatEmitCall(t *testing.T) {
}
}

func TestDetectSliceBoundCheck(t *testing.T) {
t.Parallel()
tests := []struct {
name string
code string
expected int
}{
{
name: "simple bound check",
code: `
package main
func main() {
arr := []int{1, 2, 3}
if i < len(arr) {
_ = arr[i]
}
}
`,
expected: 0,
},
{
name: "missing bound check",
code: `
package main
func main() {
arr := []int{1, 2, 3}
_ = arr[i]
}
`,
expected: 1,
},
{
name: "complex condition 2",
code: `
package main
type Item struct {
Name string
Value int
}
func main() {
sourceItems := []*Item{
{"item1", 10},
{"item2", 20},
{"item3", 30},
}
destinationItems := make([]*Item, 0, len(sourceItems))
i := 0
for _, item := range sourceItems {
destinationItems[i] = item
i++
}
}
`,
expected: 1,
},
{
name: "accessing in range loop",
code: `
package main
func removeStringFromStringArr(arr []string, str string) []string {
for i, a := range arr {
if a == str {
return append(arr[:i], arr[i+1:]...)
}
}
return arr
}
`,
},
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
fset := token.NewFileSet()
node, err := parser.ParseFile(fset, "", tt.code, 0)
if err != nil {
t.Fatalf("Failed to parse code: %v", err)
}

issues, err := DetectSliceBoundCheck("test.go", node, fset, types.SeverityError)
for i, issue := range issues {
t.Logf("Issue %d: %v", i, issue)
}
assert.NoError(t, err)
assert.Equal(
t, tt.expected, len(issues),
"Number of detected slice bound check issues doesn't match expected",
)
})
}
}

func TestDetectUselessBreak(t *testing.T) {
tests := []struct {
name string
Expand Down
50 changes: 0 additions & 50 deletions internal/lints/loop_allocation.go

This file was deleted.

1 change: 0 additions & 1 deletion internal/lints/simplify_slice_expr.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:goconst
package lints

import (
Expand Down
Loading

0 comments on commit 4808a9b

Please sign in to comment.