Skip to content

Commit 3dd7b57

Browse files
committed
feat: introduce type options, enable ts/explicit-function-return-type for lib
1 parent c118b46 commit 3dd7b57

File tree

12 files changed

+50
-14
lines changed

12 files changed

+50
-14
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ And that's it! Or you can configure each integration individually, for example:
172172
import antfu from '@antfu/eslint-config'
173173

174174
export default antfu({
175+
// Type of the project. 'lib' for libraries, the default is 'app'
176+
type: 'lib',
177+
175178
// Enable stylistic formatting rules
176179
// stylistic: true,
177180

@@ -181,7 +184,7 @@ export default antfu({
181184
quotes: 'single', // or 'double'
182185
},
183186

184-
// TypeScript and Vue are auto-detected, you can also explicitly enable them:
187+
// TypeScript and Vue are autoetected, you can also explicitly enable them:
185188
typescript: true,
186189
vue: true,
187190

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default antfu(
1111
astro: true,
1212
typescript: true,
1313
formatters: true,
14+
type: 'lib',
1415
},
1516
{
1617
ignores: [

src/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as p from '@clack/prompts'
66
import { run } from './run'
77
import { pkgJson } from './constants'
88

9-
function header() {
9+
function header(): void {
1010
// eslint-disable-next-line no-console
1111
console.log('\n')
1212
p.intro(`${c.green(`@antfu/eslint-config `)}${c.dim(`v${pkgJson.version}`)}`)

src/cli/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface CliRunOptions {
2727
extra?: string[]
2828
}
2929

30-
export async function run(options: CliRunOptions = {}) {
30+
export async function run(options: CliRunOptions = {}): Promise<void> {
3131
const argSkipPrompt = !!process.env.SKIP_PROMPT || options.yes
3232
const argTemplate = <FrameworkOption[]>options.frameworks?.map(m => m.trim())
3333
const argExtra = <ExtraLibrariesOption[]>options.extra?.map(m => m.trim())

src/cli/stages/update-eslint-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import parse from 'parse-gitignore'
1010
import { getEslintConfigContent } from '../utils'
1111
import type { PromptResult } from '../types'
1212

13-
export async function updateEslintFiles(result: PromptResult) {
13+
export async function updateEslintFiles(result: PromptResult): Promise<void> {
1414
const cwd = process.cwd()
1515
const pathESLintIgnore = path.join(cwd, '.eslintignore')
1616
const pathPackageJSON = path.join(cwd, 'package.json')

src/cli/stages/update-package-json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as p from '@clack/prompts'
77
import { dependenciesMap, pkgJson } from '../constants'
88
import type { ExtraLibrariesOption, PromptResult } from '../types'
99

10-
export async function updatePackageJson(result: PromptResult) {
10+
export async function updatePackageJson(result: PromptResult): Promise<void> {
1111
const cwd = process.cwd()
1212

1313
const pathPackageJSON = path.join(cwd, 'package.json')

src/cli/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { execSync } from 'node:child_process'
22

3-
export function isGitClean() {
3+
export function isGitClean(): boolean {
44
try {
55
execSync('git diff-index --quiet HEAD --')
66
return true
@@ -13,7 +13,7 @@ export function isGitClean() {
1313
export function getEslintConfigContent(
1414
mainConfig: string,
1515
additionalConfigs?: string[],
16-
) {
16+
): string {
1717
return `
1818
import antfu from '@antfu/eslint-config'
1919

src/configs/test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export async function test(
5252
'test/prefer-hooks-in-order': 'error',
5353
'test/prefer-lowercase-title': 'error',
5454

55+
'ts/explicit-function-return-type': 'off',
56+
5557
...overrides,
5658
},
5759
},

src/configs/typescript.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import process from 'node:process'
22
import { GLOB_ASTRO_TS, GLOB_MARKDOWN, GLOB_TS, GLOB_TSX } from '../globs'
3-
import type { OptionsComponentExts, OptionsFiles, OptionsOverrides, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
3+
import type { OptionsComponentExts, OptionsFiles, OptionsOverrides, OptionsProjectType, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes, TypedFlatConfigItem } from '../types'
44
import { pluginAntfu } from '../plugins'
55
import { interopDefault, renameRules } from '../utils'
66

77
export async function typescript(
8-
options: OptionsFiles & OptionsComponentExts & OptionsOverrides & OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions = {},
8+
options: OptionsFiles & OptionsComponentExts & OptionsOverrides & OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions & OptionsProjectType = {},
99
): Promise<TypedFlatConfigItem[]> {
1010
const {
1111
componentExts = [],
1212
overrides = {},
1313
parserOptions = {},
14+
type = 'app',
1415
} = options
1516

1617
const files = options.files ?? [
@@ -123,7 +124,11 @@ export async function typescript(
123124
'no-useless-constructor': 'off',
124125
'ts/ban-ts-comment': ['error', { 'ts-expect-error': 'allow-with-description' }],
125126
'ts/consistent-type-definitions': ['error', 'interface'],
126-
'ts/consistent-type-imports': ['error', { disallowTypeAnnotations: false, prefer: 'type-imports' }],
127+
'ts/consistent-type-imports': ['error', {
128+
disallowTypeAnnotations: false,
129+
prefer: 'type-imports',
130+
}],
131+
127132
'ts/method-signature-style': ['error', 'property'], // https://www.totaltypescript.com/method-shorthand-syntax-considered-harmful
128133
'ts/no-dupe-class-members': 'error',
129134
'ts/no-dynamic-delete': 'off',
@@ -143,6 +148,17 @@ export async function typescript(
143148
'ts/prefer-ts-expect-error': 'error',
144149
'ts/triple-slash-reference': 'off',
145150
'ts/unified-signatures': 'off',
151+
152+
...(type === 'lib'
153+
? {
154+
'ts/explicit-function-return-type': ['error', {
155+
allowExpressions: true,
156+
allowHigherOrderFunctions: true,
157+
allowIIFEs: true,
158+
}],
159+
}
160+
: {}
161+
),
146162
...overrides,
147163
},
148164
},

src/factory.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import { interopDefault } from './utils'
3434
import { formatters } from './configs/formatters'
3535
import { regexp } from './configs/regexp'
36+
import type { RuleOptions } from './typegen'
3637

3738
const flatConfigProps: (keyof TypedFlatConfigItem)[] = [
3839
'name',
@@ -155,6 +156,7 @@ export function antfu(
155156
...typescriptOptions,
156157
componentExts,
157158
overrides: getOverrides(options, 'typescript'),
159+
type: options.type,
158160
}))
159161
}
160162

@@ -308,7 +310,7 @@ export function resolveSubOptions<K extends keyof OptionsConfig>(
308310
export function getOverrides<K extends keyof OptionsConfig>(
309311
options: OptionsConfig,
310312
key: K,
311-
) {
313+
): Partial<Linter.RulesRecord & RuleOptions> {
312314
const sub = resolveSubOptions(options, key)
313315
return {
314316
...(options.overrides as any)?.[key],

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy