Skip to content

Commit

Permalink
feat: add projectType option for TypeScript, default to 'app'
Browse files Browse the repository at this point in the history
  • Loading branch information
xsjcTony committed Dec 1, 2023
1 parent ecd925b commit 92adef5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ type TypescriptOptions =
& OptionsTypeScriptParserOptionsOverride
& {
overrides?: NonNullable<OptionsConfig['overrides']>['typescript']
projectType?: 'app' | 'lib'
}


const typescriptRules: FlatConfigItem['rules'] = {
const typescriptRules = (projectType: TypescriptOptions['projectType']): FlatConfigItem['rules'] => ({
'ts/adjacent-overload-signatures': 'error',
'ts/array-type': ['error', { 'default': 'array', readonly: 'array' }],
'ts/ban-ts-comment': [
Expand Down Expand Up @@ -85,7 +86,7 @@ const typescriptRules: FlatConfigItem['rules'] = {
objectLiteralTypeAssertions: 'allow-as-parameter'
}
],
'ts/consistent-type-definitions': ['error', 'interface'],
'ts/consistent-type-definitions': ['error', projectType === 'app' ? 'type' : 'interface'],
'ts/consistent-type-imports': [
'error',
{
Expand Down Expand Up @@ -226,7 +227,7 @@ const typescriptRules: FlatConfigItem['rules'] = {
}
],
'ts/unified-signatures': 'error'
}
})


const typeAwareTypescriptRules: FlatConfigItem['rules'] = {
Expand Down Expand Up @@ -472,7 +473,8 @@ export const typescript = async ({
files,
tsconfigPath,
parserOptionsOverride = {},
overrides = {}
overrides = {},
projectType = 'app'
}: TypescriptOptions = {}): Promise<FlatConfigItem[]> => {

const [pluginTypescript, parserTypescript] = await Promise.all([
Expand Down Expand Up @@ -515,7 +517,7 @@ export const typescript = async ({
}
},
rules: {
...typescriptRules,
...typescriptRules(projectType),
...typescriptStylisticRules,
...tsconfigPath && typeAwareTypescriptRules,
...overrides
Expand Down

0 comments on commit 92adef5

Please sign in to comment.