Skip to content

sqlc generates empty imports statement, e.g. "import ()" #3134

Closed

Description

@mikeschinkel

Version

1.25.0

What happened?

When there are no imports to generate, sqlc generates two (2) unnecessary lines:

import ()
<blank line>

This is a problem when running this command in CI as gotfmt will remove that empty import and the blank line that follows:

gofmt -s -w . && git diff --exit-code

This is a simple fix; add a hasImports method for use by the template and then wrap every place in templates that generate imports with {{ if hasImports .SourceName }}. After submitting this issue I will submit a PR to fix this issue.

See db/models.go in playground.

Relevant log output

n/a

Database schema

n/a

SQL queries

n/a

Configuration

n/a

Playground URL

https://play.sqlc.dev/p/d03273b7d19072abdcb608fc72f577628aad25c2e478f7709a07221438da2832

What operating system are you using?

macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Jan 14, 2024
  2. added a commit that references this issue on Jan 14, 2024
    ac0d9a1
  3. added a commit that references this issue on Feb 14, 2024
    46a31e6
  4. added a commit that references this issue on Jun 21, 2024
    ab033b6
  5. added a commit that references this issue on Oct 13, 2025
    3335a69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNew issues that hasn't been reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions