diff --git a/packages/eslint/index.ts b/packages/eslint/index.ts index 3c474f7..bbfc8fd 100644 --- a/packages/eslint/index.ts +++ b/packages/eslint/index.ts @@ -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' @@ -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 && @@ -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', }, }, @@ -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/eslint-flat-config-utils@0.2.5/node_modules/eslint-flat-config-utils'. This is likely not portable. A type annotation is necessary.` diff --git a/packages/eslint/types.ts b/packages/eslint/types.ts index b1f2c46..93c9191 100644 --- a/packages/eslint/types.ts +++ b/packages/eslint/types.ts @@ -1,6 +1,6 @@ export interface EslintConfigOptions { - prettier?: boolean - tailwind?: boolean next?: boolean + prettier?: boolean reactQuery?: boolean + tailwind?: boolean } diff --git a/packages/prettier/base.ts b/packages/prettier/base.ts index 349ae0f..5005b23 100644 --- a/packages/prettier/base.ts +++ b/packages/prettier/base.ts @@ -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>', @@ -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, } diff --git a/packages/prettier/index.ts b/packages/prettier/index.ts index 777a3be..b522066 100644 --- a/packages/prettier/index.ts +++ b/packages/prettier/index.ts @@ -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] @@ -24,6 +24,6 @@ export const factory = (options: ConfigOption = {}) => { } } export default factory({ - importSort: true, attributesSort: true, + importSort: true, })