UNPKG

@sankeyangshu/eslint-config

Version:
157 lines (152 loc) 5.98 kB
import { FlatGitignoreOptions } from 'eslint-config-flat-gitignore'; import { RequiredOptions, LiteralUnion, BuiltInParserName } from 'prettier'; import { FlatESLintConfigItem, RuleConfig, MergeIntersection, EslintRules, ImportRules, NRules, UnicornRules, TypeScriptRules, VueRules, ReactRules, ReactHooksRules } from '@antfu/eslint-define-config'; /** Wrap rule config(包裹所有规则配置) */ type WrapRuleConfigType<T extends { [key: string]: any; }> = { [K in keyof T]: T[K] extends RuleConfig ? T[K] : RuleConfig<T[K]>; }; /** Eslint flat rules (Eslint 扁平化规则类型) */ type EslintFlatRulesType = WrapRuleConfigType<MergeIntersection<EslintRules & ImportRules & NRules & UnicornRules & TypeScriptRules & VueRules & ReactRules & ReactHooksRules>>; /** Flat config item Type (扁平化配置项类型) */ type FlatConfigItemType = Omit<FlatESLintConfigItem<EslintFlatRulesType, false>, 'plugins'> & { plugins?: Record<string, any>; }; /** A type that can be awaited (可以被等待的类型) */ type Awaitable<T> = T | Promise<T>; /** The base options (基础配置选项类型) */ interface BaseOptionsType { /** * The current working directory (项目根目录) * * @default process.cwd() */ cwd: string; /** The globs to ignore lint (被忽略的 glob) */ ignores: string[]; /** * Enable gitignore support (启用 gitignore 支持) Passing an object to configure the options (配置选项) * * @default true * @see https://github.com/antfu/eslint-config-flat-gitignore */ gitignore?: boolean | FlatGitignoreOptions; /** The override rules (覆盖的规则) */ overrides: Record<string, string>; /** * Default prettier rules (默认的 Prettier 配置选项) * * @default * ```json * { * "useTabs": false, * "tabWidth": 2, * "printWidth": 100, * "singleQuote": true, * "trailingComma": "es5", * "bracketSpacing": true, * "semi": true * } * ``` */ prettierRules: PartialPrettierExtendedOptionsType; /** * Whether to use prettierrc (是否使用 prettierrc) * * If true, the rules in prettierrc will override the default rules * * @default true */ usePrettierrc: boolean; /** * formatter (格式化器) * * @default 默认支持的格式化器 * { * "html": true, * "css": true, * } */ formatter: { html?: boolean; css?: boolean; markdown?: boolean; yaml?: boolean; toml?: boolean; }; } /** Rule base options (规则基础选项类型) */ type RuleBaseOptionsType<T = NonNullable<unknown>> = T & { /** The glob patterns to lint */ files?: string[]; }; /** Required rule base options (必要的规则基础选项类型) */ type RequiredRuleBaseOptionsType = Required<RuleBaseOptionsType>; /** Vue options (Vue 配置选项类型) */ type VueOptionsType = RuleBaseOptionsType<{ /** * The vue version * * @default 3 */ version?: 2 | 3; }>; /** Options has typescript (是否有 typescript 的选项类型) */ interface OptionsHasTypeScript { /** * Whether to use typescript * * @default true */ typescript?: boolean; } /** Required vue options (必要的 Vue 配置选项类型) */ type RequiredVueOptionsType = Required<VueOptionsType>; /** Prettier custom parser (自定义 prettier 解析器类型) */ type PrettierCustomParser = 'astro' | 'svelte' | 'toml'; type PrettierParser = BuiltInParserName | PrettierCustomParser; /** Prettier options (Prettier 配置选项类型) */ interface PrettierOptionsType extends RequiredOptions { parser: LiteralUnion<PrettierParser>; } /** Prettier options (Prettier 配置选项类型) */ type PrettierExtendedOptionsType = PrettierOptionsType; /** Partial prettier options (部分 Prettier 配置选项类型) */ type PartialPrettierExtendedOptionsType = Partial<PrettierOptionsType>; interface OptionsUnicornType { /** * Include all rules recommended by `eslint-plugin-unicorn`, instead of only ones picked by * Anthony. * * @default false */ allRecommended?: boolean; } /** On demand rule options (框架按需配置类型) */ type OnDemandRuleKey = 'vue' | 'react' | 'react-native' | 'solid' | 'svelte' | 'astro'; /** On demand rule options (框架按需配置类型) */ type OnDemandRuleOptionsType = Partial<Record<Exclude<OnDemandRuleKey, 'vue'>, RuleBaseOptionsType | boolean>>; /** Required on demand rule options (必填的框架按需配置类型) */ type RequiredOnDemandRuleOptionsType = Record<Exclude<OnDemandRuleKey, 'vue'>, RequiredRuleBaseOptionsType>; /** Options (选项类型) */ type OptionsType = Partial<BaseOptionsType> & { vue?: VueOptionsType | boolean; } & OnDemandRuleOptionsType & { unocss?: boolean; }; /** Parsed options (解析后的选项类型) */ type ParsedOptionsType = BaseOptionsType & { vue?: RequiredVueOptionsType; } & Partial<RequiredOnDemandRuleOptionsType> & { unocss?: boolean; }; /** * Create a configuration for ESLint. * * @param options - Optional options for the config. * @param userConfigs - Optional user configurations. * @returns A list of flat config items. */ declare function defineConfig(options?: Partial<OptionsType>, ...userConfigs: Awaitable<FlatConfigItemType>[]): Promise<FlatConfigItemType[]>; export { type Awaitable, type BaseOptionsType, type FlatConfigItemType, type OnDemandRuleKey, type OnDemandRuleOptionsType, type OptionsHasTypeScript, type OptionsType, type OptionsUnicornType, type ParsedOptionsType, type PartialPrettierExtendedOptionsType, type PrettierCustomParser, type PrettierExtendedOptionsType, type PrettierOptionsType, type PrettierParser, type RequiredOnDemandRuleOptionsType, type RequiredRuleBaseOptionsType, type RequiredVueOptionsType, type RuleBaseOptionsType, type VueOptionsType, defineConfig };