GithubHelp home page GithubHelp logo

ota-meshi / eslint-plugin-toml Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 2.0 543 KB

This ESLint plugin provides linting rules for TOML.

Home Page: https://ota-meshi.github.io/eslint-plugin-toml/

License: MIT License

JavaScript 1.90% TypeScript 98.10%
toml eslint-plugin eslintplugin toml-validation toml-format

eslint-plugin-toml's Introduction

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

๐Ÿ“› Features

This ESLint plugin provides linting rules for TOML.

  • You can use ESLint to lint TOML.
  • You can find out the problem with your TOML files.
  • You can apply consistent code styles to your TOML files.
  • Supports Vue SFC custom blocks such as <custom-block lang="toml">.
    Requirements vue-eslint-parser v7.3.0 and above.
  • Supports ESLint directives. e.g. # eslint-disable-next-line
  • You can check your code in real-time using the ESLint editor integrations.

You can check on the Online DEMO.

๐Ÿ“– Documentation

See documents.

๐Ÿ’ฟ Installation

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

Requirements

  • ESLint v6.0.0 and above
  • Node.js v12.22.x, v14.17.x, v16.x and above

๐Ÿ“– Usage

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:

  • *.configs['flat/base'] ... Configuration to enable correct TOML parsing.
  • *.configs['flat/recommended'] ... Above, plus rules to prevent errors or unintended behavior.
  • *.configs['flat/standard'] ... Above, plus rules to enforce the common stylistic conventions.

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:

  • plugin:toml/base ... Configuration to enable correct TOML parsing.
  • plugin:toml/recommended ... Above, plus rules to prevent errors or unintended behavior.
  • plugin:toml/standard ... Above, plus rules to enforce the common stylistic conventions.

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}"

๐Ÿ’ป 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"
    ]
}

โœ… Rules

The --fix option on the command line automatically fixes problems reported by rules which have a wrench ๐Ÿ”ง below.
The rules with the following star โญ are included in the configs.

TOML Rules

Rule ID Description Fixable RECOMMENDED STANDARD
toml/indent enforce consistent indentation ๐Ÿ”ง โญ
toml/keys-order disallow defining pair keys out-of-order ๐Ÿ”ง โญ
toml/no-mixed-type-in-array disallow mixed data types in array
toml/no-non-decimal-integer disallow hexadecimal, octal and binary integer ๐Ÿ”ง
toml/no-space-dots disallow spacing around infix operators ๐Ÿ”ง โญ
toml/no-unreadable-number-separator disallow number separators that to not enhance readability. โญ โญ
toml/padding-line-between-pairs require or disallow padding lines between pairs ๐Ÿ”ง โญ
toml/padding-line-between-tables require or disallow padding lines between tables ๐Ÿ”ง โญ
toml/precision-of-fractional-seconds disallow precision of fractional seconds greater than the specified value. โญ โญ
toml/precision-of-integer disallow precision of integer greater than the specified value. โญ โญ
toml/quoted-keys require or disallow quotes around keys ๐Ÿ”ง โญ
toml/tables-order disallow defining tables out-of-order ๐Ÿ”ง โญ
toml/vue-custom-block/no-parsing-error disallow parsing errors in Vue custom blocks โญ โญ

Extension Rules

Rule ID Description Fixable RECOMMENDED STANDARD
toml/array-bracket-newline enforce linebreaks after opening and before closing array brackets ๐Ÿ”ง โญ
toml/array-bracket-spacing enforce consistent spacing inside array brackets ๐Ÿ”ง โญ
toml/array-element-newline enforce line breaks between array elements ๐Ÿ”ง โญ
toml/comma-style enforce consistent comma style in array ๐Ÿ”ง โญ
toml/inline-table-curly-spacing enforce consistent spacing inside braces ๐Ÿ”ง โญ
toml/key-spacing enforce consistent spacing between keys and values in key/value pairs ๐Ÿ”ง โญ
toml/spaced-comment enforce consistent spacing after the # in a comment ๐Ÿ”ง โญ
toml/table-bracket-spacing enforce consistent spacing inside table brackets ๐Ÿ”ง โญ

Deprecated

  • โš ๏ธ We're going to remove deprecated rules in the next major release. Please migrate to successor/new rules.
  • ๐Ÿ˜‡ We don't fix bugs which are in deprecated rules since we don't have enough resources.
Rule ID Replaced by
toml/space-eq-sign toml/key-spacing

๐Ÿป Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

Development Tools

  • npm test runs tests and measures coverage.
  • npm run update runs in order to update readme and recommended configuration.

Working With Rules

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

๐Ÿ‘ซ Related Packages

๐Ÿ”’ License

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

eslint-plugin-toml's People

Contributors

cldxiang avatar github-actions[bot] avatar logicer16 avatar ota-meshi avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

eslint-plugin-toml's Issues

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

This repository currently has no open or pending branches.


  • Check this box to trigger a request for Renovate to run again on this repository

Add sort-keys rule

I'd like to have a rule that ensures that tables and keys are in alphabetical order. Similar to e.g jsonc/sort-keys.

# โœ“ GOOD
[alpha]
y = 2
z = 3

[beta]
x = 1

# โœ— BAD
[beta]
x = 1

[alpha]
z = 3
y = 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.