Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(linters): implement sqlfmt #37

Merged
merged 8 commits into from
Oct 19, 2022
Merged

feat(linters): implement sqlfmt #37

merged 8 commits into from
Oct 19, 2022

Conversation

sxlijin
Copy link
Contributor

@sxlijin sxlijin commented Oct 17, 2022

This is a black-style formatter that is an alternative to sql-formatter for people.

Nancy checks the Go dependency graph against the Sonatype OSS index.

Nancy comes in two flavors, sleuth and IQ, but only sleuth advertises a
JSON output format, so we leave IQ alone for now.

Also, sleuth can run into rate limits that require authz tokens to
bypass; see
https://github.com/sonatype-nexus-community/nancy#oss-index-options.
This is a black-style formatter that is an alternative to sql-formatter
for people.
@sxlijin sxlijin changed the base branch from main to sam/security October 18, 2022 23:22
Base automatically changed from sam/security to main October 19, 2022 19:09
@sxlijin sxlijin merged commit afee600 into main Oct 19, 2022
@sxlijin sxlijin deleted the sam/sqlfmt branch October 19, 2022 19:40
@tconbeer
Copy link
Contributor

tconbeer commented Nov 3, 2022

Hi @sxlijin, I'm the creator of sqlfmt. Thanks so much for creating this integration!

I don't know anything about Trunk, but I have a couple of suggestions:

  1. sqlfmt works best when installed with the jinjafmt extra, e.g., pip install shandy-sqlfmt[jinjafmt]. Is it possible to use this extra from Trunk? Would packages: shandy-sqlfmt[jinjafmt] do the trick?
  2. sqlfmt logs most of its output to stderr. We only use stdout if formatting code passed through stdin, e.g., echo "select 1" > sqlfmt -. So I think read_output_from: stderr would be better?

Finally, I'd love to mention this integration in our documentation. Is this how someone would enable sqlfmt?

# in trunk.yaml
lint:
  enabled:
    - [email protected]

or it seems like the command trunk check enable sqlfmt would do it?

@sxlijin
Copy link
Contributor Author

sxlijin commented Nov 3, 2022

Hi @tconbeer - glad to hear from you! (If you want to chat more synchronously, you can also pop into our community slack 😃 )

sqlfmt works best when installed with the jinjafmt extra, e.g., pip install shandy-sqlfmt[jinjafmt]. Is it possible to use this extra from Trunk? Would packages: shandy-sqlfmt[jinjafmt] do the trick?

extra_packages: shandy-sqlfmt[jinjafmt] will be the field - if you want to put up a PR, I can review it later today

sqlfmt logs most of its output to stderr. We only use stdout if formatting code passed through stdin, e.g., echo "select 1" > sqlfmt -. So I think read_output_from: stderr would be better?

This actually feels like a mistake on my side - we treat sqlfmt as an in-place formatter, so I don't think we actually do anything with read_output_from. But if there are diagnostics that sqlfmt produces about its input, then we should definitely do this.

(In the case where a linter/formatter errors out, we create a log file that contains all the details of the exec invocation we do on our side - cwd, argv, stdout, stderr, exit code.)

or it seems like the command trunk check enable sqlfmt would do it?

Yep - this will be the best way to do it. Under the hood, it'll query https://api.github.com/repos/.../.../releases/latest so this also allows you to not have to update another copy of your release number in your docs.

@tconbeer
Copy link
Contributor

tconbeer commented Nov 3, 2022

PR is here: #45

Thanks again for your help with this!

EliSchleifer pushed a commit that referenced this pull request Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants