Skip to main content

A simple TOML linter.

Project description

tomllint

A TOML Linter. Checks for basic syntactic errors in any TOML file.

Installation

$ pip install tomllint

Usage

Usage is self explanatory, simply name the files to lint, or use - to indicate that it should read from stdin.

usage: tomllint [-h] [--verbose] toml_file [toml_file ...]

positional arguments:
  toml_file      TOML filenames or "-" for stdin

options:
  -h, --help     show this help message and exit
  --verbose, -v  emit an info diagnostic for each file that lints successfully

By default tomllint is silent on success and only reports errors. Pass --verbose/-v to also emit a compiler-style filename:1:1: info: linted successfully line (on stderr) for each file that lints cleanly.

Neovim Integration

To register tomllint with nvim-lint, you'd add something like this to your ~/.config/nvim/init.lua or other imported file.

require("lint").linters_by_ft.toml = { "tomllint" }
local function parse_tomllint_output(output, bufnr, _linter_cwd)
	local diagnostics = {}
	for line in output:gmatch("[^\r\n]+") do
		local _, lnum, col, description = line:match("(.+):(%d+):(%d+): error: (.+)")
		if lnum and description then
			table.insert(diagnostics, {
				bufnr = bufnr,
				lnum = tonumber(lnum) - 1,
				col = tonumber(col) - 1,
				end_lnum = tonumber(lnum) - 1,
				end_col = tonumber(col),
				severity = vim.diagnostic.severity.ERROR,
				message = description,
			})
		end
	end
	return diagnostics
end
require("lint").linters.tomllint = {
	cmd = "tomllint",
	stdin = true,
	append_fname = false,
	args = { "-" },
	stream = "stderr",
	ignore_exitcode = false,
	env = nil,
	parser = parse_tomllint_output,
}

Pickls Integration

Pickls is a unified LSP that integrates command-line linters and formatters with editors like Neovim and Zed. Add the following to your ~/.config/pickls/pickls.yaml:

languages:
  toml:
    linters:
      - program: tomllint
        args: ["-"]
        pattern: '(.*):(\d+):(\d+): error: (.*)'
        line_match: 2
        start_col_match: 3
        description_match: 4
        use_stderr: true
        use_stdin: true

pre-commit Integration

pre-commit is a framework for managing and maintaining multi-language pre-commit hooks. To use tomllint to check your files when doing a git commit, add this to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/wbbradley/tomllint
    rev: v0.3.3
    hooks:
      - id: tomllint

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

tomllint-0.3.3.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tomllint-0.3.3-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file tomllint-0.3.3.tar.gz.

File metadata

  • Download URL: tomllint-0.3.3.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tomllint-0.3.3.tar.gz
Algorithm Hash digest
SHA256 b9b53d4c9824f47c24fbd12cc693cf4c66a48c2c77bcccc6f1e1766773966e51
MD5 b63898e9d60abdc30ce93f1ce7856ec4
BLAKE2b-256 7c58c230b4591dcb53eb7bd2e0678ed6742ffbc9fcf5a269146838d4362fcbf8

See more details on using hashes here.

File details

Details for the file tomllint-0.3.3-py3-none-any.whl.

File metadata

  • Download URL: tomllint-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tomllint-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4ebbd09ba6185c9bfd637f66697ede181979fc4abd3857a2367d76034f476f32
MD5 818c037ba8f5a88e1b5f82699854f13f
BLAKE2b-256 9e29376d3f36e310faf249edde29dc84c7a914b2cbd644dcf24988a450355b97

See more details on using hashes here.

Supported by

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