Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: antfu/eslint-config
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.13.4
Choose a base ref
...
head repository: antfu/eslint-config
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.14.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Apr 15, 2024

  1. feat: support lessOpinionated option

    antfu committed Apr 15, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4b87cbf View commit details
  2. chore: release v2.14.0

    antfu committed Apr 15, 2024
    Copy the full SHA
    2ffa95a View commit details
Showing with 43 additions and 5 deletions.
  1. +14 −0 README.md
  2. +1 −1 package.json
  3. +16 −4 src/configs/stylistic.ts
  4. +1 −0 src/factory.ts
  5. +11 −0 src/types.ts
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@antfu/eslint-config",
"type": "module",
"version": "2.13.4",
"version": "2.14.0",
"packageManager": "pnpm@8.15.7",
"description": "Anthony's ESLint config",
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
20 changes: 16 additions & 4 deletions src/configs/stylistic.ts
Original file line number Diff line number Diff line change
@@ -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,
@@ -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,
},
1 change: 1 addition & 0 deletions src/factory.ts
Original file line number Diff line number Diff line change
@@ -144,6 +144,7 @@ export function antfu(
if (stylisticOptions) {
configs.push(stylistic({
...stylisticOptions,
lessOpinionated: options.lessOpinionated,
overrides: getOverrides(options, 'stylistic'),
}))
}
11 changes: 11 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -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.
*/