Home

Awesome

eslint-plugin-format

npm version npm downloads bundle JSDocs License

Format various languages with formatters in ESLint. Supports Prettier and dprint. Side-effects-free and fully configurable.

Usages

Install

npm i -D eslint-plugin-format

Configure

This plugin does not do language detection or reading configure files, you need to specify the language for each file type you want to format along with other formatting options. We recommend using ESLint's Flat Config format.

// eslint.config.js
import format from 'eslint-plugin-format'

export default [
  // ...other flat configs

  // use Prettier to format CSS
  {
    files: ['**/*.css'],
    languageOptions: {
      parser: format.parserPlain,
    },
    plugins: {
      format,
    },
    rules: {
      'format/prettier': ['error', { parser: 'css', tabWidth: 2 }],
    },
  },

  // use dprint to format TOML
  {
    files: ['**/*.toml'],
    languageOptions: {
      parser: format.parserPlain,
    },
    plugins: {
      format,
    },
    rules: {
      'format/dprint': ['error', { language: 'toml', languageOptions: { indentWidth: 2 } }],
    },
  },
]

Rules

format/prettier

Use Prettier to format files.

Options

format/dprint

Use dprint to format files.

Options

Sponsors

<p align="center"> <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg"> <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/> </a> </p>

FAQ

What's the difference between this and eslint-plugin-prettier?

While this plugin provides Prettier as one of the formatters, the main difference is that eslint-plugin-prettier is much more opinionated toward the Prettier CLI ecosystem. While this plugin only treats Prettier as the side-effects-free formatter and gives you full control in ESLint.

Credits

Thanks to the existing works for references and inspiration.

License

MIT License © 2023-PRESENT Anthony Fu

<!-- Badges -->