Skip to content

Commit

Permalink
feat: support reading .gitignore by default, close #254
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 24, 2023
1 parent 5cf471b commit 2f35dae
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -5,12 +5,13 @@
- Single quotes, no semi
- Auto fix for formatting (aimed to be used standalone **without** Prettier)
- Designed to work with TypeScript, Vue out-of-box
- Lint also for json, yaml, markdown
- Lints also for json, yaml, markdown
- Sorted imports, dangling commas
- Reasonable defaults, best practices, only one-line of config
- Respects `.gitignore` by default
- [ESLint Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), compose easily!
- Using [ESLint Stylistic](https://github.com/eslint-stylistic/eslint-stylistic)
- **Style principle**: Minimal for reading, stable for diff
- **Style principle**: Minimal for reading, stable for diff, consistent

> [!IMPORTANT]
> 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.
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -41,6 +41,7 @@
"@stylistic/eslint-plugin-ts": "0.0.4",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint-config-flat-gitignore": "^0.1.0",
"eslint-define-config": "^1.23.0",
"eslint-plugin-antfu": "^1.0.0-beta.6",
"eslint-plugin-eslint-comments": "^3.2.0",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions src/factory.ts
@@ -1,6 +1,8 @@
import process from 'node:process'
import fs from 'node:fs'
import type { FlatESLintConfigItem } from 'eslint-define-config'
import { isPackageExists } from 'local-pkg'
import gitignore from 'eslint-config-flat-gitignore'
import {
comments,
ignores,
Expand Down Expand Up @@ -43,19 +45,34 @@ export function antfu(options: OptionsConfig & FlatESLintConfigItem = {}, ...use
const enableVue = options.vue ?? (isPackageExists('vue') || isPackageExists('nuxt') || isPackageExists('vitepress') || isPackageExists('@slidev/cli'))
const enableTypeScript = options.typescript ?? (isPackageExists('typescript'))
const enableStylistic = options.stylistic ?? true
const enableGitignore = options.gitignore ?? true

const configs = [
const configs: FlatESLintConfigItem[][] = []

if (enableGitignore) {
if (typeof enableGitignore !== 'boolean') {
configs.push([gitignore(enableGitignore)])
}
else {
if (fs.existsSync('.gitignore'))
configs.push([gitignore()])
}
}

// Base configs
configs.push(
ignores,
javascript({ isInEditor }),
comments,
node,
jsdoc,
imports,
unicorn,
]
)

// In the future we may support more component extensions like Svelte or so
const componentExts: string[] = []

if (enableVue)
componentExts.push('vue')

Expand Down
12 changes: 12 additions & 0 deletions src/types.ts
@@ -1,3 +1,5 @@
import type { FlatGitignoreOptions } from 'eslint-config-flat-gitignore'

export interface OptionsComponentExts {
/**
* Additional extensions for components.
Expand All @@ -22,6 +24,16 @@ export interface OptionsIsInEditor {
}

export interface OptionsConfig {
/**
* Enable gitignore support.
*
* Passing an object to configure the options.
*
* @see https://github.com/antfu/eslint-config-flat-gitignore
* @default true
*/
gitignore?: boolean | FlatGitignoreOptions

/**
* Enable TypeScript support.
*
Expand Down

0 comments on commit 2f35dae

Please sign in to comment.