Skip to content

Commit ca92dcf

Browse files
Fix linter issues and move example workflow
Lint fixes: - Remove unused jsMethodPattern variable in javascript.go - Simplify nil checks in patterns_test.go and remediation_test.go Configuration: - Add .golangci.yml with test file exclusions for errcheck - Move example workflow to examples/ to prevent it running on this repo
1 parent 496a4da commit ca92dcf

5 files changed

Lines changed: 41 additions & 5 deletions

File tree

.golangci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# golangci-lint configuration
2+
# https://golangci-lint.run/usage/configuration/
3+
4+
run:
5+
timeout: 5m
6+
tests: true
7+
8+
linters:
9+
enable:
10+
- errcheck
11+
- gosimple
12+
- govet
13+
- ineffassign
14+
- staticcheck
15+
- unused
16+
17+
linters-settings:
18+
errcheck:
19+
# Don't check for unchecked errors in test files for setup code
20+
exclude-functions:
21+
- os.MkdirAll
22+
- os.WriteFile
23+
- os.RemoveAll
24+
- (io.Closer).Close
25+
- (*os.File).Close
26+
- (net/http.ResponseWriter).Write
27+
- (*encoding/json.Encoder).Encode
28+
29+
issues:
30+
# Exclude some linters from running on tests files
31+
exclude-rules:
32+
- path: _test\.go
33+
linters:
34+
- errcheck
35+
- path: testdata/
36+
linters:
37+
- errcheck

internal/analyzer/ast/javascript.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ var (
3131
importDynPattern = regexp.MustCompile(`import\s*\(\s*['"]([^'"]+)['"]\s*\)`)
3232

3333
// Function detection patterns
34-
jsFuncDeclPattern = regexp.MustCompile(`(?:async\s+)?function\s+(\w+)\s*\(`)
35-
jsMethodPattern = regexp.MustCompile(`(\w+)\s*\([^)]*\)\s*{`)
36-
jsArrowFuncPattern = regexp.MustCompile(`(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\([^)]*\)\s*=>`)
34+
jsFuncDeclPattern = regexp.MustCompile(`(?:async\s+)?function\s+(\w+)\s*\(`)
35+
jsArrowFuncPattern = regexp.MustCompile(`(?:const|let|var)\s+(\w+)\s*=\s*(?:async\s*)?\([^)]*\)\s*=>`)
3736
jsClassMethodPattern = regexp.MustCompile(`(?:async\s+)?(\w+)\s*\([^)]*\)\s*{`)
3837
jsExportPattern = regexp.MustCompile(`^(?:export\s+(?:default\s+)?(?:async\s+)?(?:function|class|const|let|var)\s+(\w+)|module\.exports\s*[.=]|exports\.(\w+))`)
3938
jsClassPattern = regexp.MustCompile(`class\s+(\w+)`)

pkg/crypto/patterns_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestGetPatternsForEcosystem(t *testing.T) {
4242

4343
func TestGetPatternsForUnknownEcosystem(t *testing.T) {
4444
patterns := GetPatternsForEcosystem("unknown")
45-
if patterns != nil && len(patterns) > 0 {
45+
if len(patterns) > 0 {
4646
t.Errorf("GetPatternsForEcosystem(unknown) = %v, want empty/nil", patterns)
4747
}
4848
}

pkg/crypto/remediation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestGetLibraryRecommendations(t *testing.T) {
219219
func TestGetLibraryRecommendationsUnknown(t *testing.T) {
220220
libs := GetLibraryRecommendations("UNKNOWN_ALGO", types.EcosystemGo)
221221
// Should return nil or empty for unknown algorithms
222-
if libs != nil && len(libs) > 0 {
222+
if len(libs) > 0 {
223223
t.Errorf("GetLibraryRecommendations(unknown) = %v, want nil/empty", libs)
224224
}
225225
}

0 commit comments

Comments
 (0)