diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index abc98164..cacba2d4 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -73,3 +73,23 @@ jobs: working-directory: frontend run: npm run test + backend-lint: + name: Backend Lint + runs-on: ubuntu-latest + strategy: + matrix: + modules: + - backend + - search/pg-indexer + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup go + uses: actions/setup-go@v5 + with: + go-version-file: 'backend/go.mod' + - name: Backend Linting + uses: golangci/golangci-lint-action@v6 + with: + version: v1.62 + working-directory: ${{ matrix.modules }} diff --git a/backend/internal/backend.go b/backend/internal/backend.go index c3887ad7..ec8464fd 100644 --- a/backend/internal/backend.go +++ b/backend/internal/backend.go @@ -177,7 +177,7 @@ func (f ForceRegenerateEntry) MustRegenerateProvider(_ context.Context, addr pro }) } -func (g GenerateConfig) validate() error { +func (g GenerateConfig) validate() error { //nolint:unused if g.Name != "" && g.Namespace == "" { return fmt.Errorf("cannot use name filtering without namespace filtering") } diff --git a/backend/internal/blocklist/blocklist.go b/backend/internal/blocklist/blocklist.go index 362cd4c3..2c3f860c 100644 --- a/backend/internal/blocklist/blocklist.go +++ b/backend/internal/blocklist/blocklist.go @@ -65,6 +65,7 @@ func (b *blockListType[T]) UnmarshalJSON(data []byte) error { func (b *blockList) LoadFile(file string) error { blockListContents, err := os.ReadFile(file) if err != nil { + return err } if err := json.Unmarshal(blockListContents, &b); err != nil { diff --git a/backend/internal/indexstorage/bufferedstorage/index.go b/backend/internal/indexstorage/bufferedstorage/index.go index 2c76eb72..d47f570e 100644 --- a/backend/internal/indexstorage/bufferedstorage/index.go +++ b/backend/internal/indexstorage/bufferedstorage/index.go @@ -202,7 +202,7 @@ func (l *localIndex) Close() error { } func (l *localIndex) trySave(ctx context.Context) error { - if time.Now().Sub(l.lastCommitted) < 30*time.Second { + if time.Since(l.lastCommitted) < 30*time.Second { return nil } diff --git a/backend/internal/providerindex/generator.go b/backend/internal/providerindex/generator.go index ab7fb159..802540c9 100644 --- a/backend/internal/providerindex/generator.go +++ b/backend/internal/providerindex/generator.go @@ -128,6 +128,9 @@ func (d *documentationGenerator) Generate(ctx context.Context, opts ...Opts) err func (d *documentationGenerator) GenerateNamespace(ctx context.Context, namespace string, opts ...Opts) error { d.log.Info(ctx, "Listing all providers in namespace %s...", namespace) providerList, err := d.metadataAPI.ListProvidersByNamespace(ctx, namespace, true) + if err != nil { + return err + } d.log.Info(ctx, "Loaded %d providers", len(providerList)) diff --git a/backend/internal/providerindex/providerdocsource/scrape_test.go b/backend/internal/providerindex/providerdocsource/scrape_test.go index 5a96efa9..df989ecd 100644 --- a/backend/internal/providerindex/providerdocsource/scrape_test.go +++ b/backend/internal/providerindex/providerdocsource/scrape_test.go @@ -148,7 +148,9 @@ Manages projects. } t.Run(tt.name, func(t *testing.T) { doc := &docItem{} - s.ExtractFrontmatterPermissively(context.Background(), []byte(tt.input), doc) + if err := s.ExtractFrontmatterPermissively(context.Background(), []byte(tt.input), doc); err != nil { + t.Errorf("Failed to extract frontmatter: (%v)", err) + } if doc.Name != tt.expected.Name { t.Errorf("expected %q, got %q", tt.expected.Name, doc.Name) diff --git a/backend/internal/providerindex/search.go b/backend/internal/providerindex/search.go index 9f7a1b6e..f0b11a37 100644 --- a/backend/internal/providerindex/search.go +++ b/backend/internal/providerindex/search.go @@ -25,7 +25,7 @@ func (p providerSearch) indexProviderVersion(ctx context.Context, providerAddr p popularity = providerDetails.UpstreamPopularity } providerItem := searchtypes.IndexItem{ - ID: searchtypes.IndexID("providers/" + providerAddr.String()), + ID: searchtypes.IndexID(indexPrefix + "/" + providerAddr.String()), Type: searchtypes.IndexTypeProvider, Addr: providerAddr.String(), Version: string(version), @@ -69,7 +69,7 @@ func (p providerSearch) indexProviderVersion(ctx context.Context, providerAddr p for _, docItem := range item.items { title := docItem.Title if err := p.searchAPI.AddItem(ctx, searchtypes.IndexItem{ - ID: searchtypes.IndexID("providers/" + providerAddr.String() + "/" + item.typeName + "s/" + string(docItem.Name)), + ID: searchtypes.IndexID(indexPrefix + "/" + providerAddr.String() + "/" + item.typeName + "s/" + string(docItem.Name)), Type: item.indexType, Addr: providerAddr.String(), Version: string(version), @@ -92,7 +92,7 @@ func (p providerSearch) indexProviderVersion(ctx context.Context, providerAddr p return nil } -func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context, addr provider.Addr, version provider.VersionNumber) error { +func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context, addr provider.Addr, version provider.VersionNumber) error { //nolint:unused for _, t := range []searchtypes.IndexType{ searchtypes.IndexTypeProvider, searchtypes.IndexTypeProviderResource, @@ -105,6 +105,6 @@ func (p providerSearch) removeProviderVersionFromSearchIndex(ctx context.Context return nil } -func (p providerSearch) removeModuleFromSearchIndex(ctx context.Context, addr module.Addr) error { +func (p providerSearch) removeModuleFromSearchIndex(ctx context.Context, addr module.Addr) error { //nolint:unused return p.searchAPI.RemoveItem(ctx, searchtypes.IndexID(indexPrefix+"/"+addr.String())) } diff --git a/backend/internal/registrycloner/git.go b/backend/internal/registrycloner/git.go index 1f9408a5..2567add1 100644 --- a/backend/internal/registrycloner/git.go +++ b/backend/internal/registrycloner/git.go @@ -30,7 +30,7 @@ func (c cloner) cloneGitRepo(ctx context.Context) error { } // FetchTags fetches the tags for the repository in the specified directory. -func (c cloner) fetchTags(ctx context.Context) error { +func (c cloner) fetchTags(ctx context.Context) error { //nolint:unused return c.runGitCommand(ctx, []string{"git", "fetch", "--tags", "--force"}, c.cfg.Directory) }