Skip to content

Commit

Permalink
feat(eslint): enable perfectionist
Browse files Browse the repository at this point in the history
  • Loading branch information
thecuvii committed Jul 22, 2024
1 parent 2b3e07e commit a462fc6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
43 changes: 33 additions & 10 deletions packages/eslint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import eslintConfigPrettier from 'eslint-config-prettier'
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended'
import type { EslintConfigOptions } from './types'

import antfu, { perfectionist } from '@antfu/eslint-config'
import antfu from '@antfu/eslint-config'
import { FlatCompat } from '@eslint/eslintrc'
// @ts-expect-error no types
import nextPlugin from '@next/eslint-plugin-next'
Expand All @@ -14,26 +14,49 @@ import tailwindPlugin from 'eslint-plugin-tailwindcss'

const compat = new FlatCompat()

export const factory = ({ prettier, tailwind, next, reactQuery }: EslintConfigOptions = {}) => {
export const factory = ({ next, prettier, reactQuery, tailwind }: EslintConfigOptions = {}) => {
const base = antfu({
stylistic: false,
react: true,
plugins: {
perfectionist,
},
}).overrideRules({ 'import/order': 'off', 'ts/no-unused-expressions': 'off' })
stylistic: false,
}).overrideRules({
'@next/next/no-img-element': 'off',
'import/order': 'off',
'no-irregular-whitespace': 'off',
'node/prefer-global/process': 'warn',
'react/prefer-destructuring-assignment': 'off',
'sort-imports': 'off',
'ts/no-unused-expressions': 'off',
'ts/no-use-before-define': 'off',
'unused-imports/no-unused-vars': 'warn',
})

base.append([
...compat.config({
plugins: ['svg-jsx'],
rules: {
'svg-jsx/camel-case-dash': 'error',
'svg-jsx/camel-case-colon': 'error',
'svg-jsx/camel-case-dash': 'error',
'svg-jsx/no-style-string': 'error',
},
}),
])

// 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',
},
})

!!prettier && base.append([eslintPluginPrettierRecommended, eslintConfigPrettier])

!!tailwind &&
Expand All @@ -53,8 +76,8 @@ export const factory = ({ prettier, tailwind, next, reactQuery }: EslintConfigOp
rules: {
...nextPlugin.configs.recommended.rules,
...nextPlugin.configs['core-web-vitals'].rules,
'@next/next/no-img-element': 'error',
'@next/next/no-duplicate-head': 'off',
'@next/next/no-img-element': 'error',
'@next/next/no-page-custom-font': 'off',
},
},
Expand All @@ -65,7 +88,7 @@ export const factory = ({ prettier, tailwind, next, reactQuery }: EslintConfigOp
return base
}

const defaultConfig = factory({ prettier: true, tailwind: true, next: true, reactQuery: true })
const defaultConfig = factory({ next: true, prettier: true, reactQuery: true, tailwind: true })
export default defaultConfig

// Fix `error TS2742: The inferred type of 'factory' cannot be named without a reference to '.pnpm/[email protected]/node_modules/eslint-flat-config-utils'. This is likely not portable. A type annotation is necessary.`
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export interface EslintConfigOptions {
prettier?: boolean
tailwind?: boolean
next?: boolean
prettier?: boolean
reactQuery?: boolean
tailwind?: boolean
}
22 changes: 11 additions & 11 deletions packages/prettier/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@ import pluginAutoCorrect from 'prettier-plugin-autocorrect'
import pluginSh from 'prettier-plugin-sh'

export const baseConfig = {
tabWidth: 2,
printWidth: 120,
semi: false,
singleQuote: true,
trailingComma: 'all',
arrowParens: 'always',
attributeGroups: ['^className$', '^(key|id|name|ref)$', '$DEFAULT', '^aria-', '^data-', '^on'],
endOfLine: 'lf',
jsxSingleQuote: true,
useTabs: false,

plugins: [pluginAutoCorrect, pluginSh],

importOrder: [
'react',
'<THIRD_PARTY_MODULES>',
Expand All @@ -32,6 +23,15 @@ export const baseConfig = {
'^(?!.*[.]css$)[./].*$',
'.css$',
],
jsxSingleQuote: true,
plugins: [pluginAutoCorrect, pluginSh],
printWidth: 120,
semi: false,
singleQuote: true,

attributeGroups: ['^className$', '^(key|id|name|ref)$', '$DEFAULT', '^aria-', '^data-', '^on'],
tabWidth: 2,

trailingComma: 'all',

useTabs: false,
}
4 changes: 2 additions & 2 deletions packages/prettier/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import pluginSortImports from '@ianvs/prettier-plugin-sort-imports'
import { baseConfig } from './base'

export const factory = (options: ConfigOption = {}) => {
const { importSort = true, attributesSort = true } = options
const { attributesSort = true, importSort = true } = options

const plugins = [...baseConfig.plugins]

Expand All @@ -24,6 +24,6 @@ export const factory = (options: ConfigOption = {}) => {
}
}
export default factory({
importSort: true,
attributesSort: true,
importSort: true,
})

0 comments on commit a462fc6

Please sign in to comment.