Giter Club home page Giter Club logo

eslint-plugin-format's Introduction

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

  • parser (required) - the language to format, Supported languages
  • The rest options are passed as Prettier options

format/dprint

Use dprint to format files.

Options

  • language (required) - the language to format, or can be a filepath or URL to the WASM binary. Supported languages
  • languageOptions - the options for the language
  • The rest options are passed as dprint's general options

Sponsors

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

eslint-plugin-format's People

Contributors

antfu avatar rebeccastevens avatar

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.