Integrations

IDE

Rattle can lint as you type and can also be used to format files.

To enable this, install the lsp extras, for example:

$ pip install "rattle-lint[lsp]"

Then configure an LSP client to launch and connect to the Rattle LSP server. See the lsp command reference for usage details.

Examples of client setup:

require("lspconfig.configs").rattle = {
  default_config = {
    cmd = { "rattle", "lsp" },
    filetypes = { "python" },
    root_dir = require("lspconfig").util.root_pattern(
      "pyproject.toml", "setup.py", "requirements.txt", ".git",
    ),
    single_file_support = true,
  },
}

lspconfig.rattle.setup({})

pre-commit

Rattle can be included as a hook for pre-commit.

Once you have installed pre-commit, add one of Rattle’s hooks to .pre-commit-config.yaml.

To run lint rules on commit:

repos:
  - repo: https://github.com/zigai/rattle
    rev: 0.0.0  # replace with the Rattle version to use
    hooks:
      - id: rattle-lint

To run lint rules and apply autofixes:

repos:
  - repo: https://github.com/zigai/rattle
    rev: 0.0.0  # replace with the Rattle version to use
    hooks:
      - id: rattle-fix

To read more about how you can customize your pre-commit configuration, see the pre-commit hooks documentation.

VS Code

For better integration with Visual Studio Code, set output-format = "vscode". That allows VS Code to open the editor at the right position when clicking code locations in Rattle’s terminal output.