antfu/eslint-plugin-format
소개
Format various languages with formatters in ESLint
기타 프로젝트측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originaleslint-plugin-format
Format various languages with formatters in ESLint. Supports Prettier, dprint and oxfmt. 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 } }],
},
},
// use oxfmt to format JavaScript/TypeScript with TailwindCSS classnames sorting
{
files: ['**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}'],
languageOptions: {
parser: format.parserPlain,
},
plugins: {
format,
},
rules: {
'format/oxfmt': ['error', { sortTailwindcss: {} }],
},
},
// use dprint to format HTML and CSS in style tags
{
files: ['**/*.html'],
languageOptions: {
parser: format.parserPlain,
},
plugins: {
format,
},
rules: {
'format/dprint': ['error', {
plugins: [
{
plugin: 'node_modules/dprint-plugin-malva/plugin.wasm',
options: {},
},
{
plugin: 'node_modules/dprint-plugin-markup/plugin.wasm',
options: {
scriptIndent: true,
styleIndent: true,
},
},
],
useTabs: false,
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
Either:
language(required) - the language to format, or can be a filepath or URL to the WASM binary. Supported languageslanguageOptions- the options for the language- The rest options are passed as dprint's general options
Or:
plugins(required) - Array of plugins, defined as an object containingplugin(same aslanguageabove) andoptions, which is the same aslanguageOptionsabove.- The rest of the options are passed as dprint's general options
format/oxfmt
Use oxfmt to format files.
Options
- File type is inferred from the linted filename extension.
- The options are passed directly to oxfmt's
format()API.
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
관련 프로젝트 살펴보기
불러오는 중…