diff --git a/README.md b/README.md index 1ecc7334d4..ced4bd112d 100644 --- a/README.md +++ b/README.md @@ -680,6 +680,20 @@ Meanwhile, we do have dprint integrations for formatting other files such as `.m You can opt-in to the [`formatters`](#formatters) feature to format your CSS. Note that it's only doing formatting, but not linting. If you want proper linting support, give [`stylelint`](https://stylelint.io/) a try. +### Top-level Function Style, etc. + +I am a very opinionated person, so as this config. I prefer the top-level functions always using the function declaration over arrow functions; I prefer one-line if statements without braces and always wraps, and so on. I even wrote some custom rules to enforce them. + +I know they are not necessarily the popular opinions. If you really want to get rid of them, you can disable them with: + +```ts +import antfu from '@antfu/eslint-config' + +export default antfu({ + lessOpinionated: true +}) +``` + ### I prefer XXX... Sure, you can configure and override rules locally in your project to fit your needs. If that still does not work for you, you can always fork this repo and maintain your own. diff --git a/src/configs/stylistic.ts b/src/configs/stylistic.ts index a8329d531f..85716ce0a6 100644 --- a/src/configs/stylistic.ts +++ b/src/configs/stylistic.ts @@ -9,12 +9,17 @@ export const StylisticConfigDefaults: StylisticConfig = { semi: false, } +export interface StylisticOptions extends StylisticConfig, OptionsOverrides { + lessOpinionated?: boolean +} + export async function stylistic( - options: StylisticConfig & OptionsOverrides = {}, + options: StylisticOptions = {}, ): Promise { const { indent, jsx, + lessOpinionated = false, overrides = {}, quotes, semi, @@ -45,10 +50,17 @@ export async function stylistic( ...config.rules, 'antfu/consistent-list-newline': 'error', - 'antfu/if-newline': 'error', - 'antfu/top-level-function': 'error', - 'curly': ['error', 'multi-or-nest', 'consistent'], + ...(lessOpinionated + ? { + curly: ['error', 'all'], + } + : { + 'antfu/if-newline': 'error', + 'antfu/top-level-function': 'error', + 'curly': ['error', 'multi-or-nest', 'consistent'], + } + ), ...overrides, }, diff --git a/src/factory.ts b/src/factory.ts index a229546c92..b76d2b10eb 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -144,6 +144,7 @@ export function antfu( if (stylisticOptions) { configs.push(stylistic({ ...stylisticOptions, + lessOpinionated: options.lessOpinionated, overrides: getOverrides(options, 'stylistic'), })) } diff --git a/src/types.ts b/src/types.ts index c457f946cc..80ede24871 100644 --- a/src/types.ts +++ b/src/types.ts @@ -184,6 +184,17 @@ export interface OptionsConfig extends OptionsComponentExts { */ gitignore?: boolean | FlatGitignoreOptions + /** + * Disable some opinionated rules to Anthony's preference. + * + * Including: + * - `antfu/top-level-function` + * - `antfu/if-newline` + * + * @default false + */ + lessOpinionated?: boolean + /** * Core rules. Can't be disabled. */