Skip to main content

sqlfmt is an opinionated CLI tool that formats your sql files

Project description

sqlfmt

Code style: black Imports: isort Checked with mypy

sqlfmt is an opinionated CLI tool that formats your dbt sql files. It is similar in nature to black, gofmt, and rustfmt.

sqlfmt is not configurable, except for line length. It enforces a single style. sqlfmt maintains comments and some extra newlines, but largely ignores all indentation and line breaks in the input file.

sqlfmt is not a linter. It does not parse your code; it just tokenizes it and tracks a small subset of tokens that impact formatting. This lets us "do one thing and do it well:" sqlfmt is very fast, and easier to extend than linters that need a full sql grammar.

sqlfmt is designed to work with sql files that contain jinja tags and blocks. It formats the code that users look at, and therefore doesn't need to know anything about what happens after the templates are rendered.

Contributing

Setting up Your Dev Environment and Running Tests

  1. Install Poetry if you don't have it already. You may also need or want pyenv, make, and gcc. A complete setup from a fresh install of Ubuntu can be found here
  2. Clone this repo into a directory (let's call it sqlfmt), then cd sqlfmt
  3. Use poetry install to install the project (editable) and its dependencies into a new virtual env
  4. Use poetry shell to spawn a subshell
  5. Type make to run all tests and linters, or run pytest, black, flake8, isort, and mypy individually.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shandy-sqlfmt-0.1.0a8.tar.gz (21.9 kB view hashes)

Uploaded Source

Built Distribution

shandy_sqlfmt-0.1.0a8-py3-none-any.whl (25.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page