Skip to content

Commit

Permalink
fix(eslint-config): update perfectionist
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Dec 28, 2024
1 parent 461cb3f commit 05293e9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 53 deletions.
3 changes: 2 additions & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"dependencies": {
"defu": "^6.1.4",
"eslint-flat-config-utils": "^0.4.0",
"eslint-plugin-functional": "^7.2.0"
"eslint-plugin-functional": "^7.2.0",
"eslint-plugin-perfectionist": "^4.4.0"
},
"devDependencies": {
"@antfu/eslint-config": "^3.12.1",
Expand Down
59 changes: 8 additions & 51 deletions packages/eslint-config/src/configs/perfectionist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,11 @@ import type { Linter } from 'eslint'

import type { Options } from '../options'

type Option = Exclude<Options['perfectionist'], false>

/** @see {@link https://github.com/azat-io/eslint-plugin-perfectionist/blob/bf730c4343275878814b7f48757c06f4adc69ca5/index.ts#L26C1-L29C2} */
interface PerfectionistOptions {
order: 'asc' | 'desc'
type: 'alphabetical' | 'line-length' | 'natural'
}

/** @see {@link https://github.com/azat-io/eslint-plugin-perfectionist/blob/bf730c4343275878814b7f48757c06f4adc69ca5/index.ts#L38-L58} */
const rules = [
'sort-variable-declarations',
'sort-intersection-types',
'sort-svelte-attributes',
'sort-astro-attributes',
'sort-vue-attributes',
'sort-array-includes',
'sort-named-imports',
'sort-named-exports',
'sort-object-types',
'sort-union-types',
'sort-switch-case',
'sort-interfaces',
'sort-jsx-props',
'sort-classes',
'sort-imports',
'sort-exports',
'sort-objects',
'sort-enums',
'sort-maps',
] as const

/** @see {@link https://github.com/azat-io/eslint-plugin-perfectionist/blob/bf730c4343275878814b7f48757c06f4adc69ca5/index.ts#L62-L68} */
const getRules = (options: PerfectionistOptions): Linter.RulesRecord =>
Object.fromEntries(
rules.map(rule => [
`perfectionist/${rule}`,
['error', options],
]),
)

export const perfectionist = (type: Option): Linter.FlatConfig => ({
name: 'importantimport/perfectionist/rules',
rules: {
'import/order': 'off',
'sort-imports': 'off',
...getRules({
order: type === 'line-length' ? 'desc' : 'asc',
type,
}),
},
})
import perfectionistPlugin from 'eslint-plugin-perfectionist'

export const perfectionist = (option: Exclude<Options['perfectionist'], false>): Linter.Config[] => [
{
name: 'importantimport/perfectionist/rules',
rules: perfectionistPlugin.configs[`recommended-${option}`].rules,
}
]
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 05293e9

Please sign in to comment.