Skip to content

Commit d1f1779

Browse files
committed
feat: support reading .gitignore by default
1 parent 126e9f9 commit d1f1779

File tree

9 files changed

+61
-18
lines changed

9 files changed

+61
-18
lines changed

eslint.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require('sucrase/register')
1111
export default coderwyd(
1212
undefined,
1313
{
14-
files: ['**/eslint-config/src/**/*.ts'],
14+
files: ['src/**/*.ts'],
1515
plugins: {
1616
'@stylistic/migrate': stylisticMigrate,
1717
'sort-keys': sortKeys,

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
"eslint-config"
1111
],
1212
"exports": {
13-
"import": "./dist/index.js",
14-
"require": "./dist/index.cjs"
13+
".": {
14+
"import": "./dist/index.js",
15+
"require": "./dist/index.cjs"
16+
}
1517
},
1618
"main": "./dist/index.js",
1719
"module": "./dist/index.js",
@@ -26,11 +28,11 @@
2628
"node": ">=16.14.0"
2729
},
2830
"scripts": {
29-
"build": "tsup src/index.ts --format esm --clean --dts",
31+
"build": "tsup src/index.ts --format esm,cjs --clean --dts",
3032
"stub": "tsup src/index.ts --format esm",
3133
"lint": "pnpm run stub && eslint .",
32-
"prepublishOnly": "nr build",
33-
"release": "bumpp && npm publish",
34+
"prepack": "nr build",
35+
"release": "bumpp && pnpm publish",
3436
"test": "vitest",
3537
"typecheck": "tsc --noEmit",
3638
"prepare": "simple-git-hooks"
@@ -45,6 +47,7 @@
4547
"@typescript-eslint/eslint-plugin": "^6.7.2",
4648
"@typescript-eslint/parser": "^6.7.2",
4749
"astro-eslint-parser": "^0.15.0",
50+
"eslint-config-flat-gitignore": "^0.1.0",
4851
"eslint-define-config": "^1.23.0",
4952
"eslint-plugin-antfu": "1.0.0-beta.6",
5053
"eslint-plugin-astro": "^0.29.0",

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configs/javascript.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import globals from 'globals'
33
import { pluginAntfu, pluginUnusedImports } from '../plugins'
44
import { OFF } from '../flags'
55
import type { OptionsIsInEditor } from '../types'
6+
import { GLOB_SRC, GLOB_SRC_EXT } from '../globs'
67

78
export function javascript(options: OptionsIsInEditor = {}): FlatESLintConfigItem[] {
89
return [
@@ -48,7 +49,7 @@ export function javascript(options: OptionsIsInEditor = {}): FlatESLintConfigIte
4849
'max-statements-per-line': ['error', { max: 1 }],
4950
'new-cap': ['error', { capIsNew: false, newIsCap: true, properties: true }],
5051
'new-parens': 'error',
51-
'no-alert': 'warn',
52+
'no-alert': 'error',
5253
'no-array-constructor': 'error',
5354
'no-async-promise-executor': 'error',
5455
'no-caller': 'error',
@@ -213,7 +214,7 @@ export function javascript(options: OptionsIsInEditor = {}): FlatESLintConfigIte
213214

214215
'unused-imports/no-unused-imports': options.isInEditor ? OFF : 'error',
215216
'unused-imports/no-unused-vars': [
216-
'warn',
217+
'error',
217218
{ args: 'after-used', argsIgnorePattern: '^_', vars: 'all', varsIgnorePattern: '^_' },
218219
],
219220

@@ -225,7 +226,7 @@ export function javascript(options: OptionsIsInEditor = {}): FlatESLintConfigIte
225226
},
226227
},
227228
{
228-
files: ['scripts/**/*.*', 'cli.*'],
229+
files: [`scripts/${GLOB_SRC}`, `cli.${GLOB_SRC_EXT}`],
229230
rules: {
230231
'no-console': OFF,
231232
},

src/configs/stylistic.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const javascriptStylistic: FlatESLintConfigItem[] = [
1111
style: pluginStylisticJs,
1212
},
1313
rules: {
14+
'antfu/consistent-list-newline': 'error',
1415
'antfu/if-newline': 'error',
15-
'antfu/consistent-object-newline': 'error',
1616

1717
'comma-dangle': ['error', 'always-multiline'],
1818
'curly': ['error', 'multi-or-nest', 'consistent'],
@@ -27,8 +27,6 @@ export const javascriptStylistic: FlatESLintConfigItem[] = [
2727
'style/comma-style': ['error', 'last'],
2828
'style/computed-property-spacing': ['error', 'never', { enforceForClassMembers: true }],
2929
'style/dot-location': ['error', 'property'],
30-
'style/func-call-spacing': OFF,
31-
'style/generator-star-spacing': OFF,
3230
'style/indent': ['error', 2, {
3331
ArrayExpression: 1,
3432
CallExpression: { arguments: 1 },
@@ -77,7 +75,6 @@ export const javascriptStylistic: FlatESLintConfigItem[] = [
7775
'style/no-tabs': 'error',
7876
'style/no-trailing-spaces': 'error',
7977
'style/no-whitespace-before-property': 'error',
80-
'style/object-curly-newline': OFF,
8178
'style/object-curly-spacing': ['error', 'always'],
8279
'style/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }],
8380
'style/operator-linebreak': ['error', 'before'],

src/configs/typescript.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@ export function typescript(options?: OptionsComponentExts): FlatESLintConfigItem
6666
'ts/explicit-module-boundary-types': OFF,
6767
'ts/naming-convention': OFF,
6868
'ts/no-dupe-class-members': 'error',
69+
'ts/no-dynamic-delete': OFF,
6970
'ts/no-empty-function': OFF,
7071
'ts/no-empty-interface': OFF,
7172
'ts/no-explicit-any': OFF,
7273
'ts/no-extra-parens': ['error', 'functions'],
7374
'ts/no-invalid-this': 'error',
74-
'ts/no-loss-of-precision': 'error',
7575
'ts/no-invalid-void-type': OFF,
76+
'ts/no-loss-of-precision': 'error',
7677
'ts/no-non-null-assertion': OFF,
7778
'ts/no-redeclare': 'error',
7879
'ts/no-require-imports': 'error',

src/configs/vue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export function vue(options: OptionsHasTypeScript = {}): FlatESLintConfigItem[]
5555
rules: {
5656
...(isVue3 ? vue3Rules : vue2Rules),
5757

58+
'node/prefer-global/process': OFF,
59+
5860
'vue/array-bracket-spacing': ['error', 'never'],
5961
'vue/arrow-spacing': ['error', { after: true, before: true }],
6062
'vue/block-order': ['error', {
@@ -86,7 +88,6 @@ export function vue(options: OptionsHasTypeScript = {}): FlatESLintConfigItem[]
8688
'vue/keyword-spacing': ['error', { after: true, before: true }],
8789
'vue/max-attributes-per-line': OFF,
8890
'vue/multi-word-component-names': OFF,
89-
'vue/no-constant-condition': 'warn',
9091
'vue/no-dupe-keys': OFF,
9192
'vue/no-empty-pattern': 'error',
9293
'vue/no-extra-parens': ['error', 'functions'],
@@ -100,7 +101,6 @@ export function vue(options: OptionsHasTypeScript = {}): FlatESLintConfigItem[]
100101
],
101102
'vue/no-restricted-v-bind': ['error', '/^v-/'],
102103

103-
// reactivity transform
104104
'vue/no-setup-props-reactivity-loss': OFF,
105105
'vue/no-sparse-arrays': 'error',
106106
'vue/no-unused-refs': 'error',

src/factory.ts

Lines changed: 17 additions & 2 deletions
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
astro,
68
comments,
@@ -48,16 +50,29 @@ export function coderwyd(options: OptionsConfig & FlatESLintConfigItem = {}, ...
4850

4951
const enableTypeScript = options.typescript ?? (isPackageExists('typescript'))
5052
const enableStylistic = options.stylistic ?? true
53+
const enableGitignore = options.gitignore ?? true
5154

52-
const configs = [
55+
const configs: FlatESLintConfigItem[][] = []
56+
if (enableGitignore) {
57+
if (typeof enableGitignore !== 'boolean') {
58+
configs.push([gitignore(enableGitignore)])
59+
}
60+
else {
61+
if (fs.existsSync('.gitignore'))
62+
configs.push([gitignore()])
63+
}
64+
}
65+
66+
// Base configs
67+
configs.push(
5368
ignores,
5469
javascript({ isInEditor }),
5570
comments,
5671
node,
5772
jsdoc,
5873
imports,
5974
unicorn,
60-
]
75+
)
6176

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

src/types.ts

Lines changed: 12 additions & 0 deletions
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)