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

Added pre-commit integration. #556

Merged
merged 2 commits into from Apr 1, 2024
Merged

Conversation

slyapustin
Copy link
Contributor

This PR introduces direct pre-commit compatibility.

Here is an example of how it can be integrated after it will be integrated:

repos:
-   repo: https://github.com/sql-formatter-org/sql-formatter
    rev: ''
    hooks:
    -   id: sql-formatter

Right now you need to create a separate repository in order to be able to integrate with sql-formatter.
Like this one: https://github.com/slyapustin/pre-commit-sql-formatter

@nene
Copy link
Collaborator

nene commented Jan 27, 2023

Thanks for the PR, but I don't quite understand why this pre-commit configuration file should be part of this repository.

There can be many tools which might want to use this library. The library itself should not need to include code to cater for each of these tools. Specifically this library provides two well-established API-s:

  • calling the sql-formatter tool from command line.
  • calling the formatting function through JavaScript API.

So far these have been enough for all kinds of tools to integrate with it.

@slyapustin
Copy link
Contributor Author

It just simplifies sql-formatter integration with pre-commit hooks.

And it will not require everyone to have a separate repository for that (like I created).

There are more than 200+ popular projects that added integration with the pre-commit hooks already.

@nene
Copy link
Collaborator

nene commented Jan 27, 2023

Sorry, but I don't buy it. To me it looks like a shortcoming of this pre-commit tool.

Also, me being completely unfamiliar with this tool makes me a bad maintainer of that integration. I'd rather not take that responsibility upon me.

@nene
Copy link
Collaborator

nene commented Jan 27, 2023

Also, clicking through this list of hooks it seems to me that most of the repositories linked from there are either:

  • python-based tools
  • shallow wrappers for a non-python tools

Found a few rare exceptions. So it looks like adding of this config file might be a standard practice in the world of Python, but a pretty rare thing outside of Python realm.

@caffeinatedgaze
Copy link

It would really be nice to have it integrated with pre-commit. I am sadly not able to use this tool otherwise. sqlfluff could become a nice alternative for me - but it seems to be very unstable in the way it parses grammar, which renders it useless.

@caffeinatedgaze
Copy link

This thread has good points pro adding this single config file. This may even encourage @nene to reconsider 😄

To make it easier for the readers, @asottile mentions eslint and ruboco as examples of off-Python world projects where pre-commit is very well welcomed.

@nene
Copy link
Collaborator

nene commented Mar 31, 2024

Why not simply use pre-commit-sql-formatter?

I guess the problem is that these small wrapper-projects become easily out of date with the original library as they need to reference a specific version of the library, unlike when the configuration file is part of the original library repo (at least it seems that a version number is required in the former case, but not in the latter case).

@nene nene reopened this Mar 31, 2024
@caffeinatedgaze
Copy link

as they need to reference a specific version

This indeed looks valid. In addition, one needs to maintain an irrelevant version tag to fetch a hook from a third-party repo.

@nene
Copy link
Collaborator

nene commented Apr 1, 2024

OK. I'll merge this in, as there are at least two people interested in this and it doesn't seem to require any additional maintenance from my side.

@nene nene merged commit 243a5cb into sql-formatter-org:master Apr 1, 2024
1 check passed
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.

None yet

3 participants