Skip to content

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

Closed
@mikeschinkel

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

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