Skip to content

feat: add --sort flag to order output by filename and line number - #48

Merged
houqp merged 1 commit into
houqp:masterfrom
by22Jy:feature/sort-output-flag
Feb 16, 2026
Merged

houqp merged 1 commit into
houqp:masterfrom
by22Jy:feature/sort-output-flag

Conversation

@by22Jy

@by22Jy by22Jy commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

Description

This PR addresses issue #25 by adding a --sort (-s) flag that sorts the output by filename and line number.

Motivation

When comparing output between different runs (e.g., using diff), the non-deterministic order of results can make comparisons noisy. Sorting the output makes it more deterministic and easier to work with.

Changes

  • Added flagSortOutput global variable
  • Added SortOutput field to SQLVet struct
  • Updated NewSQLVet to accept sortOutput parameter
  • Added sorting logic in Vet() method using sort.Slice
  • Added --sort (-s) flag definition in rootCmd

Usage

# Sort output by filename and line number
sqlvet --sort /path/to/project

# Short form
sqlvet -s /path/to/project

Testing

The changes are minimal and non-breaking:

  • Default behavior unchanged (no sorting)
  • Sorting only applied when --sort flag is used
  • Uses standard Go sort.Slice for stability

Closes #25

Add a new `--sort` (`-s`) flag that sorts the output by filename
and line number. This makes the output more deterministic and
easier to compare between runs, especially useful when integrating
with diff tools.

Changes:
- Add `flagSortOutput` global variable
- Add `SortOutput` field to SQLVet struct
- Update `NewSQLVet` to accept sortOutput parameter
- Add sorting logic in `Vet()` method using sort.Slice
- Add `--sort` flag definition in rootCmd

Closes houqp#25
@houqp
houqp merged commit 8fb4272 into houqp:master Feb 16, 2026
2 checks passed
@samiam2013

Copy link
Copy Markdown
Collaborator

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a flag to order output by filename, line number?

3 participants