Home

Awesome

Introduction

eslint-plugin-toml is ESLint plugin provides linting rules for TOML.

NPM license NPM version NPM downloads NPM downloads NPM downloads NPM downloads NPM downloads Build Status

:name_badge: Features

This ESLint plugin provides linting rules for TOML.

You can check on the Online DEMO.

<!--DOCS_IGNORE_START-->

:book: Documentation

See documents.

:cd: Installation

npm install --save-dev eslint eslint-plugin-toml

Requirements

<!--DOCS_IGNORE_END-->

:book: Usage

<!--USAGE_SECTION_START--> <!--USAGE_GUIDE_START-->

Configuration

New Config (eslint.config.js)

Use eslint.config.js file to configure rules. See also: https://eslint.org/docs/latest/use/configure/configuration-files-new.

Example eslint.config.js:

import eslintPluginToml from 'eslint-plugin-toml';
export default [
  // add more generic rule sets here, such as:
  // js.configs.recommended,
  ...eslintPluginToml.configs['flat/recommended'],
  {
    rules: {
      // override/add rules settings here, such as:
    // 'toml/rule-name': 'error'
    }
  }
];

This plugin provides configs:

See the rule list to get the rules that this plugin provides.

Legacy Config (.eslintrc)

Use .eslintrc.* file to configure rules. See also: https://eslint.org/docs/latest/use/configure/.

Example .eslintrc.js:

module.exports = {
  extends: [
    // add more generic rulesets here, such as:
    // 'eslint:recommended',
    'plugin:toml/standard'
  ],
  rules: {
    // override/add rules settings here, such as:
    // 'toml/rule-name': 'error'
  }
}

This plugin provides configs:

Note that these configurations do not enable ESLint's core rules. For example, the following style rules can also be used in TOML.

{
    "rules": {
        "comma-spacing": "error",
        "no-multi-spaces": ["error", { "exceptions": { "TOMLKeyValue": true } }],
        "no-multiple-empty-lines": "error",
        "no-trailing-spaces": "error"
    }
}

See the rule list to get the rules that this plugin provides.

Parser Configuration

If you have specified a parser, you need to configure a parser for .toml.

For example, if you are using the "@babel/eslint-parser", configure it as follows:

module.exports = {
  // ...
  extends: ["plugin:toml/standard"],
  // ...
  parser: "@babel/eslint-parser",
  // Add an `overrides` section to add a parser configuration for TOML.
  overrides: [
    {
      files: ["*.toml"],
      parser: "toml-eslint-parser",
    },
  ],
  // ...
};

Running ESLint from the command line

If you want to run eslint from the command line, make sure you include the .toml extension using the --ext option or a glob pattern, because ESLint targets only .js files by default.

Examples:

eslint --ext .js,.toml src
eslint "src/**/*.{js,toml}"

:computer: Editor Integrations

Visual Studio Code

Use the dbaeumer.vscode-eslint extension that Microsoft provides officially.

You have to configure the eslint.validate option of the extension to check .toml files, because the extension targets only *.js or *.jsx files by default.

Example .vscode/settings.json:

{
    "eslint.validate": [
        "javascript",
        "javascriptreact",
        "toml"
    ]
}
<!--USAGE_GUIDE_END--> <!--USAGE_SECTION_END-->

:white_check_mark: Rules

<!--RULES_SECTION_START-->

The --fix option on the command line automatically fixes problems reported by rules which have a wrench :wrench: below.
The rules with the following star :star: are included in the configs.

<!--RULES_TABLE_START-->

TOML Rules

Rule IDDescriptionFixableRECOMMENDEDSTANDARD
toml/indentenforce consistent indentation:wrench::star:
toml/keys-orderdisallow defining pair keys out-of-order:wrench::star:
toml/no-mixed-type-in-arraydisallow mixed data types in array
toml/no-non-decimal-integerdisallow hexadecimal, octal and binary integer:wrench:
toml/no-space-dotsdisallow spacing around infix operators:wrench::star:
toml/no-unreadable-number-separatordisallow number separators that to not enhance readability.:star::star:
toml/padding-line-between-pairsrequire or disallow padding lines between pairs:wrench::star:
toml/padding-line-between-tablesrequire or disallow padding lines between tables:wrench::star:
toml/precision-of-fractional-secondsdisallow precision of fractional seconds greater than the specified value.:star::star:
toml/precision-of-integerdisallow precision of integer greater than the specified value.:star::star:
toml/quoted-keysrequire or disallow quotes around keys:wrench::star:
toml/tables-orderdisallow defining tables out-of-order:wrench::star:
toml/vue-custom-block/no-parsing-errordisallow parsing errors in Vue custom blocks:star::star:

Extension Rules

Rule IDDescriptionFixableRECOMMENDEDSTANDARD
toml/array-bracket-newlineenforce linebreaks after opening and before closing array brackets:wrench::star:
toml/array-bracket-spacingenforce consistent spacing inside array brackets:wrench::star:
toml/array-element-newlineenforce line breaks between array elements:wrench::star:
toml/comma-styleenforce consistent comma style in array:wrench::star:
toml/inline-table-curly-spacingenforce consistent spacing inside braces:wrench::star:
toml/key-spacingenforce consistent spacing between keys and values in key/value pairs:wrench::star:
toml/spaced-commentenforce consistent spacing after the # in a comment:wrench::star:
toml/table-bracket-spacingenforce consistent spacing inside table brackets:wrench::star:

Deprecated

Rule IDReplaced by
toml/space-eq-signtoml/key-spacing
<!--RULES_TABLE_END--> <!--RULES_SECTION_END--> <!--DOCS_IGNORE_START-->

:beers: Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

Development Tools

Working With Rules

This plugin uses toml-eslint-parser for the parser. Check here to find out about AST.

<!--DOCS_IGNORE_END-->

:couple: Related Packages

:lock: License

See the LICENSE file for license rights and limitations (MIT).