-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: pipeline append `lvPlugin` * chore: let go oxlintRules type hints * chore: refactoring * chore: almost * feat: works. * chore: rename
- Loading branch information
Showing
12 changed files
with
295 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,95 @@ | ||
import antfu, { ensurePackages, typescript } from '@antfu/eslint-config' | ||
import type { FlatConfigItem, OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes } from '@antfu/eslint-config' | ||
import type { OptionsTypeScriptParserOptions, OptionsTypeScriptWithTypes } from '@antfu/eslint-config' | ||
import { lvPlugin } from '@lvjiaxuan/eslint-plugin' | ||
import type { OptionsOXLint } from '@lvjiaxuan/eslint-plugin-oxlint' | ||
import type { OXLintOptions } from '@lvjiaxuan/eslint-plugin-oxlint' | ||
import { detectTsconfigPaths } from './tsconfigs' | ||
|
||
type Antfu = typeof antfu | ||
type _Params<Params extends Parameters<Antfu> = Parameters<Antfu>> = [ options?: Params[0] & { oxlint: OptionsOXLint }, ...userConfigs: Params[1][] ] | ||
type AntfuParams<Params extends Parameters<Antfu> = Parameters<Antfu>> = [ options?: Params[0] & { oxlint: OXLintOptions }, ...userConfigs: Params[1][] ] | ||
type AntfuReturnType = ReturnType<Antfu> | ||
|
||
const lv: (...args: _Params) => ReturnType<Antfu> = async (...args) => { | ||
const [options] = args | ||
const lv: (...args: AntfuParams) => AntfuReturnType = (...args) => { | ||
let pipeline = antfu(...args) | ||
|
||
const pluginsInstalled = [lvPlugin()] | ||
pipeline = pipeline.append( | ||
lvPlugin(), | ||
) | ||
|
||
if (options?.oxlint) { | ||
await ensurePackages(['@lvjiaxuan/eslint-plugin-oxlint']) | ||
const { oxlint } = await import('@lvjiaxuan/eslint-plugin-oxlint') | ||
pluginsInstalled.push(...(await oxlint(options.oxlint))) | ||
const [antfuOptions] = args | ||
if (antfuOptions?.oxlint) { | ||
pipeline = pipeline.append((async () => { | ||
await ensurePackages(['@lvjiaxuan/eslint-plugin-oxlint']) | ||
const { oxlint } = await import('@lvjiaxuan/eslint-plugin-oxlint') | ||
return oxlint(antfuOptions.oxlint) | ||
})()) | ||
} | ||
|
||
const merged = await antfu( | ||
...args, | ||
...pluginsInstalled, | ||
) as FlatConfigItem[] | ||
void pipeline.onResolved(async (configs) => { | ||
// The name comes from https://github.com/antfu/eslint-config/blob/main/src/configs/typescript.ts . | ||
if (configs.findIndex(item => item.name === 'antfu/typescript/setup') > -1) { | ||
let tsOptions = antfuOptions!.typescript as OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions | ||
|
||
if (merged.find(item => item.name === 'antfu:typescript:setup')) { | ||
// Means ts is setup. | ||
let tsOptions = args[0]?.typescript as OptionsTypeScriptWithTypes & OptionsTypeScriptParserOptions | ||
let isUseDetected = false | ||
if (typeof tsOptions === 'object') { | ||
if (tsOptions.notDetectTsconfig === true) { | ||
// Do nothing. | ||
} | ||
else if (!Object.hasOwn(tsOptions, 'tsconfigPath')) { | ||
// Add detected `tsconfigPath` if no-set. | ||
const paths = await detectTsconfigPaths() | ||
if (paths.length) { | ||
tsOptions.tsconfigPath = paths | ||
isUseDetected = true | ||
} | ||
} | ||
|
||
let isUseDetected = false | ||
if (typeof tsOptions === 'object') { | ||
if ('notDetectTsconfig' in tsOptions && tsOptions.notDetectTsconfig === true) { | ||
// Do nothing. | ||
// Use settings. | ||
|
||
tsOptions.parserOptions ??= {} | ||
tsOptions.parserOptions = { | ||
warnOnUnsupportedTypeScriptVersion: true, | ||
EXPERIMENTAL_useProjectService: true, | ||
...tsOptions.parserOptions, | ||
} | ||
} | ||
else if (!Object.hasOwn(tsOptions, 'tsconfigPath')) { | ||
// Overwrite with detected `tsconfigPath` if no-set. | ||
else { | ||
const paths = await detectTsconfigPaths() | ||
if (paths.length) { | ||
tsOptions.tsconfigPath = paths | ||
// typescript = true means {} | ||
tsOptions = { | ||
tsconfigPath: paths, | ||
parserOptions: { | ||
warnOnUnsupportedTypeScriptVersion: true, | ||
EXPERIMENTAL_useProjectService: true, | ||
}, | ||
} | ||
isUseDetected = true | ||
} | ||
} | ||
|
||
// Use settings. | ||
|
||
tsOptions.parserOptions ??= {} | ||
tsOptions.parserOptions = { | ||
warnOnUnsupportedTypeScriptVersion: true, | ||
EXPERIMENTAL_useProjectService: true, | ||
...tsOptions.parserOptions, | ||
} | ||
} | ||
else { | ||
const paths = await detectTsconfigPaths() | ||
if (paths.length) { | ||
// typescript = true means {} | ||
tsOptions = { | ||
tsconfigPath: paths, | ||
parserOptions: { | ||
warnOnUnsupportedTypeScriptVersion: true, | ||
EXPERIMENTAL_useProjectService: true, | ||
}, | ||
} | ||
isUseDetected = true | ||
} | ||
} | ||
|
||
if (isUseDetected) { | ||
// New ts flat config with detected `tsconfigPath`. | ||
const tsItemsWithTsConfig = await typescript(tsOptions as OptionsTypeScriptWithTypes) | ||
if (isUseDetected) { | ||
// New ts flat config items with detected `tsconfigPath`. | ||
const flatConfigItemsWithTsConfig = await typescript(tsOptions as OptionsTypeScriptWithTypes) | ||
|
||
const parserItemName = 'antfu:typescript:parser' | ||
const originParserItemIdx = merged.findIndex(item => item.name === parserItemName) | ||
merged.splice(originParserItemIdx, 1, tsItemsWithTsConfig.find(item => item.name === parserItemName)!) | ||
const parserItemIdx = configs.findIndex(item => item.name === 'antfu/typescript/parser') | ||
configs.splice( | ||
parserItemIdx, | ||
1, | ||
flatConfigItemsWithTsConfig.find(item => item.name === 'antfu/typescript/type-aware-parser')!, | ||
flatConfigItemsWithTsConfig.find(item => item.name === 'antfu/typescript/parser')!, | ||
) | ||
|
||
const typeAwareParserItemName = 'antfu:typescript:type-aware-parser' | ||
merged.splice(originParserItemIdx + 1, 0, tsItemsWithTsConfig.find(item => item.name === typeAwareParserItemName)!) | ||
|
||
const typeAwareItemName = 'antfu:typescript:rules-type-aware' | ||
const tsTypeAwareItemIdx = merged.findIndex(item => item.name === typeAwareItemName) | ||
merged.splice(tsTypeAwareItemIdx, 1, tsItemsWithTsConfig.find(item => item.name === typeAwareItemName)!) | ||
const rulesItemIdx = configs.findIndex(item => item.name = 'antfu/typescript/rules') | ||
configs.splice( | ||
rulesItemIdx + 1, | ||
0, | ||
flatConfigItemsWithTsConfig.find(item => item.name === 'antfu/typescript/rules-type-aware')!, | ||
) | ||
} | ||
} | ||
} | ||
}) | ||
|
||
return merged | ||
return pipeline | ||
} | ||
|
||
export default lv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.