Skip to content

Commit 2f35dae

Browse files
committed
feat: support reading .gitignore by default, close #254
1 parent 5cf471b commit 2f35dae

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
- Single quotes, no semi
66
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
77
- Designed to work with TypeScript, Vue out-of-box
8-
- Lint also for json, yaml, markdown
8+
- Lints also for json, yaml, markdown
99
- Sorted imports, dangling commas
1010
- Reasonable defaults, best practices, only one-line of config
11+
- Respects `.gitignore` by default
1112
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
1213
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
13-
- **Style principle**: Minimal for reading, stable for diff
14+
- **Style principle**: Minimal for reading, stable for diff, consistent
1415

1516
> [!IMPORTANT]
1617
> The main branch is for v1.0-beta, which rewrites to ESLint Flat config, check [#250](https://github.com/antfu/eslint-config/pull/250) for more details.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@stylistic/eslint-plugin-ts": "0.0.4",
4242
"@typescript-eslint/eslint-plugin": "^6.7.2",
4343
"@typescript-eslint/parser": "^6.7.2",
44+
"eslint-config-flat-gitignore": "^0.1.0",
4445
"eslint-define-config": "^1.23.0",
4546
"eslint-plugin-antfu": "^1.0.0-beta.6",
4647
"eslint-plugin-eslint-comments": "^3.2.0",

pnpm-lock.yaml

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/factory.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import process from 'node:process'
2+
import fs from 'node:fs'
23
import type { FlatESLintConfigItem } from 'eslint-define-config'
34
import { isPackageExists } from 'local-pkg'
5+
import gitignore from 'eslint-config-flat-gitignore'
46
import {
57
comments,
68
ignores,
@@ -43,19 +45,34 @@ export function antfu(options: OptionsConfig & FlatESLintConfigItem = {}, ...use
4345
const enableVue = options.vue ?? (isPackageExists('vue') || isPackageExists('nuxt') || isPackageExists('vitepress') || isPackageExists('@slidev/cli'))
4446
const enableTypeScript = options.typescript ?? (isPackageExists('typescript'))
4547
const enableStylistic = options.stylistic ?? true
48+
const enableGitignore = options.gitignore ?? true
4649

47-
const configs = [
50+
const configs: FlatESLintConfigItem[][] = []
51+
52+
if (enableGitignore) {
53+
if (typeof enableGitignore !== 'boolean') {
54+
configs.push([gitignore(enableGitignore)])
55+
}
56+
else {
57+
if (fs.existsSync('.gitignore'))
58+
configs.push([gitignore()])
59+
}
60+
}
61+
62+
// Base configs
63+
configs.push(
4864
ignores,
4965
javascript({ isInEditor }),
5066
comments,
5167
node,
5268
jsdoc,
5369
imports,
5470
unicorn,
55-
]
71+
)
5672

5773
// In the future we may support more component extensions like Svelte or so
5874
const componentExts: string[] = []
75+
5976
if (enableVue)
6077
componentExts.push('vue')
6178

src/types.ts

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { FlatGitignoreOptions } from 'eslint-config-flat-gitignore'
2+
13
export interface OptionsComponentExts {
24
/**
35
* Additional extensions for components.
@@ -22,6 +24,16 @@ export interface OptionsIsInEditor {
2224
}
2325

2426
export interface OptionsConfig {
27+
/**
28+
* Enable gitignore support.
29+
*
30+
* Passing an object to configure the options.
31+
*
32+
* @see https://github.com/antfu/eslint-config-flat-gitignore
33+
* @default true
34+
*/
35+
gitignore?: boolean | FlatGitignoreOptions
36+
2537
/**
2638
* Enable TypeScript support.
2739
*

0 commit comments

Comments
 (0)