Skip to content

Commit

Permalink
fix(eslint): custom perfectionist groups
Browse files Browse the repository at this point in the history
  • Loading branch information
thecuvii committed Jul 22, 2024
1 parent 779b374 commit b5d99bb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
45 changes: 35 additions & 10 deletions packages/eslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import antfu from '@antfu/eslint-config'
import { FlatCompat } from '@eslint/eslintrc'
// @ts-expect-error no types
import nextPlugin from '@next/eslint-plugin-next'
import stylistic from '@stylistic/eslint-plugin'
import stylisticJsx from '@stylistic/eslint-plugin-jsx'
import queryPlugin from '@tanstack/eslint-plugin-query'

// @ts-expect-error no types
Expand Down Expand Up @@ -41,19 +43,42 @@ export const factory = ({ next, prettier, reactQuery, tailwind }: EslintConfigOp
}),
])

const customGroups = {
callback: 'on*',
data: '{data-*,aria-*}',
links: '{link,href,to,src,url}',
preserve: '{key,ref,id,className,*ClassName,children}',
}

const groups = ['preserve', 'links', 'data', 'shorthand', 'unknown', 'multiline', 'callback']

// perfectionist
base.append({
rules: {
'perfectionist/sort-array-includes': 'error',
'perfectionist/sort-enums': 'error',
'perfectionist/sort-exports': 'error',
'perfectionist/sort-interfaces': 'error',
'perfectionist/sort-intersection-types': 'error',
'perfectionist/sort-jsx-props': 'error',
'perfectionist/sort-named-exports': 'error',
'perfectionist/sort-object-types': 'error',
'perfectionist/sort-objects': 'error',
'perfectionist/sort-union-types': 'error',
'perfectionist/sort-array-includes': ['error', { type: 'natural' }],
'perfectionist/sort-enums': ['error', { type: 'natural' }],
'perfectionist/sort-exports': ['error', { type: 'natural' }],
'perfectionist/sort-interfaces': [
'error',
{
'custom-groups': customGroups,
groups,
'optionality-order': 'required-first',
type: 'natural',
},
],
'perfectionist/sort-intersection-types': ['error', { type: 'natural' }],
'perfectionist/sort-jsx-props': [
'error',
{
'custom-groups': customGroups,
groups,
},
],
'perfectionist/sort-named-exports': ['error', { 'group-kind': 'types-first', type: 'natural' }],
'perfectionist/sort-object-types': ['error', { 'custom-groups': customGroups, groups, type: 'natural' }],
'perfectionist/sort-objects': ['error', { 'custom-groups': customGroups, groups, type: 'natural' }],
'perfectionist/sort-union-types': ['error', { 'nullable-last': true, type: 'natural' }],
},
})

Expand Down
2 changes: 1 addition & 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 b5d99bb

Please sign in to comment.