A TOML parser that produces output compatible with ESLint
26
stars
307
commits
TypeScript
primary language
Sep 3, 2026
updated
A TOML parser that produces output compatible with ESLint.
npm install --save-dev toml-eslint-parser
[!TIP] If you want to lint TOML files, we recommend using eslint-plugin-toml together with this parser. The plugin provides useful rules for TOML files and includes this parser as a dependency.
The following additional configuration options are available by specifying them in parserOptions in your ESLint configuration file.
Example eslint.config.js:
export default [
{
files: ["**/*.toml"],
languageOptions: {
// Additional configuration options
parserOptions: {
tomlVersion: "1.0.0",
},
},
},
];
parserOptions.tomlVersionSelect the TOML version by setting "1.0.0", "1.1.0", "1.0", "1.1", "latest", or "next". By default "1.1.0" is used.
"1.0.0" ... Parsed using TOML v1.0.0 specifications."1.0" ... Alias for "1.0.0"."1.1.0" ... Parsed using the TOML v1.1.0 specification, which is currently under development. TOML 1.1.0 has not been released yet, so "1.1.0" is still an experimental feature. Please note that this may be subject to breaking changes in minor version releases of this parser."1.1" ... Alias for "1.1.0"."latest" ... Currently an alias for "1.1.0". When a new version of TOML is released, we plan to change to that version in a minor version release of this parser."next" ... Currently an alias for "1.1.0".[!TIP] If you want to lint TOML files, we recommend using eslint-plugin-toml together with this parser. Using eslint-plugin-toml as a language plugin will include this parser as a dependency. The following example shows how to use the parser directly without the language plugin. This is not the recommended approach, but it works. Note that ESLint will perform additional internal processing (such as JavaScript scope analysis).
Use eslint.config.js (or eslint.config.mjs) file to configure parser. See also: https://eslint.org/docs/latest/use/configure/.
Example eslint.config.js:
import * as tomlParser from "toml-eslint-parser";
export default [
{
files: ["**/*.toml"],
languageOptions: {
parser: tomlParser,
},
},
];
Example:
import type { AST } from "toml-eslint-parser";
import { parseTOML, getStaticTOMLValue } from "toml-eslint-parser";
const code = `
# This is a TOML document
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
ports = [ 8001, 8001, 8002 ]
data = [ ["delta", "phi"], [3.14] ]
temp_targets = { cpu = 79.5, case = 72.0 }
[servers]
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend"
`;
const ast: AST.TOMLProgram = parseTOML(code);
console.log(ast);
// {
// type: 'Program',
// body: [
// {
// type: 'TOMLTopLevelTable',
// body: [
// {
// type: 'TOMLKeyValue',
// key: { /* ... */ },
// value: { /* ... */ },
// /* ... */
// },
// {
// type: 'TOMLTable',
// kind: 'standard',
// key: { /* ... */ },
// body: [ /* ... */ ],
// /* ... */
// },
// /* ... */
// ]
// /* ... */
// }
// ],
// tokens: [ /* ... */ ],
// comments: [
// {
// type: 'Block',
// value: ' This is a TOML document',
// // ...
// }
// ],
// }
const value = getStaticTOMLValue(ast);
console.log(value);
// {
// title: 'TOML Example',
// owner: { name: 'Tom Preston-Werner', dob: 1979-05-27T15:32:00.000Z },
// database: {
// enabled: true,
// ports: [ 8001, 8001, 8002 ],
// data: [ [ /* ... */ ], [ /* ... */ ] ],
// temp_targets: { cpu: 79.5, case: 72 }
// },
// servers: {
// alpha: { ip: '10.0.0.1', role: 'frontend' },
// beta: { ip: '10.0.0.2', role: 'backend' }
// }
// }
This project uses files from BurntSushi/toml-test and iarna/toml-spec-tests repositories for testing.
TypeScript
85.5%
Vue
7.4%
JavaScript
5.9%
A TOML parser that produces output compatible with ESLint
26
stars
307
commits
TypeScript
primary language
Sep 3, 2026
updated
A TOML parser that produces output compatible with ESLint.
npm install --save-dev toml-eslint-parser
[!TIP] If you want to lint TOML files, we recommend using eslint-plugin-toml together with this parser. The plugin provides useful rules for TOML files and includes this parser as a dependency.
The following additional configuration options are available by specifying them in parserOptions in your ESLint configuration file.
Example eslint.config.js:
export default [
{
files: ["**/*.toml"],
languageOptions: {
// Additional configuration options
parserOptions: {
tomlVersion: "1.0.0",
},
},
},
];
parserOptions.tomlVersionSelect the TOML version by setting "1.0.0", "1.1.0", "1.0", "1.1", "latest", or "next". By default "1.1.0" is used.
"1.0.0" ... Parsed using TOML v1.0.0 specifications."1.0" ... Alias for "1.0.0"."1.1.0" ... Parsed using the TOML v1.1.0 specification, which is currently under development. TOML 1.1.0 has not been released yet, so "1.1.0" is still an experimental feature. Please note that this may be subject to breaking changes in minor version releases of this parser."1.1" ... Alias for "1.1.0"."latest" ... Currently an alias for "1.1.0". When a new version of TOML is released, we plan to change to that version in a minor version release of this parser."next" ... Currently an alias for "1.1.0".[!TIP] If you want to lint TOML files, we recommend using eslint-plugin-toml together with this parser. Using eslint-plugin-toml as a language plugin will include this parser as a dependency. The following example shows how to use the parser directly without the language plugin. This is not the recommended approach, but it works. Note that ESLint will perform additional internal processing (such as JavaScript scope analysis).
Use eslint.config.js (or eslint.config.mjs) file to configure parser. See also: https://eslint.org/docs/latest/use/configure/.
Example eslint.config.js:
import * as tomlParser from "toml-eslint-parser";
export default [
{
files: ["**/*.toml"],
languageOptions: {
parser: tomlParser,
},
},
];
Example:
import type { AST } from "toml-eslint-parser";
import { parseTOML, getStaticTOMLValue } from "toml-eslint-parser";
const code = `
# This is a TOML document
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
ports = [ 8001, 8001, 8002 ]
data = [ ["delta", "phi"], [3.14] ]
temp_targets = { cpu = 79.5, case = 72.0 }
[servers]
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend"
`;
const ast: AST.TOMLProgram = parseTOML(code);
console.log(ast);
// {
// type: 'Program',
// body: [
// {
// type: 'TOMLTopLevelTable',
// body: [
// {
// type: 'TOMLKeyValue',
// key: { /* ... */ },
// value: { /* ... */ },
// /* ... */
// },
// {
// type: 'TOMLTable',
// kind: 'standard',
// key: { /* ... */ },
// body: [ /* ... */ ],
// /* ... */
// },
// /* ... */
// ]
// /* ... */
// }
// ],
// tokens: [ /* ... */ ],
// comments: [
// {
// type: 'Block',
// value: ' This is a TOML document',
// // ...
// }
// ],
// }
const value = getStaticTOMLValue(ast);
console.log(value);
// {
// title: 'TOML Example',
// owner: { name: 'Tom Preston-Werner', dob: 1979-05-27T15:32:00.000Z },
// database: {
// enabled: true,
// ports: [ 8001, 8001, 8002 ],
// data: [ [ /* ... */ ], [ /* ... */ ] ],
// temp_targets: { cpu: 79.5, case: 72 }
// },
// servers: {
// alpha: { ip: '10.0.0.1', role: 'frontend' },
// beta: { ip: '10.0.0.2', role: 'backend' }
// }
// }
This project uses files from BurntSushi/toml-test and iarna/toml-spec-tests repositories for testing.
TypeScript
85.5%
Vue
7.4%
JavaScript
5.9%