Skip to content

Commit

Permalink
feat: support lessOpinionated option
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Apr 15, 2024
1 parent f819499 commit 4b87cbf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
14 changes: 14 additions & 0 deletions README.md
Expand Up @@ -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.
Expand Down
20 changes: 16 additions & 4 deletions src/configs/stylistic.ts
Expand Up @@ -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<TypedFlatConfigItem[]> {
const {
indent,
jsx,
lessOpinionated = false,
overrides = {},
quotes,
semi,
Expand Down Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions src/factory.ts
Expand Up @@ -144,6 +144,7 @@ export function antfu(
if (stylisticOptions) {
configs.push(stylistic({
...stylisticOptions,
lessOpinionated: options.lessOpinionated,
overrides: getOverrides(options, 'stylistic'),
}))
}
Expand Down
11 changes: 11 additions & 0 deletions src/types.ts
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 4b87cbf

Please sign in to comment.