-
Notifications
You must be signed in to change notification settings - Fork 64
/
typescript.ts
78 lines (72 loc) · 3.09 KB
/
typescript.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import parserTs from '@typescript-eslint/parser'
import pluginTs from '@typescript-eslint/eslint-plugin'
import type { FlatConfigItem } from 'eslint-flat-config-utils'
import type { NuxtESLintConfigOptions } from '@nuxt/eslint-config/flat'
import { resolveOptions } from '../utils'
export default function typescript(options: NuxtESLintConfigOptions): FlatConfigItem[] {
const resolved = resolveOptions(options)
if (resolved.features.typescript === false) {
return []
}
const tsOptions = resolved.features.typescript === true ? {} : resolved.features.typescript
return [
{
name: 'nuxt/typescript/setup',
plugins: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'@typescript-eslint': pluginTs as any,
},
},
{
name: 'nuxt/typescript/rules',
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts', '**/*.vue'],
languageOptions: {
parser: parserTs,
},
rules: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
...pluginTs.configs['eslint-recommended'].overrides![0].rules as any,
...pluginTs.configs.recommended.rules,
...(tsOptions.strict === false
? {}
: pluginTs.configs.strict.rules),
// Include typescript eslint rules in *.vue files
// https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/eslint-recommended.ts
'constructor-super': 'off', // ts(2335) & ts(2377)
'getter-return': 'off', // ts(2378)
'no-const-assign': 'off', // ts(2588)
'no-dupe-args': 'off', // ts(2300)
'no-dupe-class-members': 'off', // ts(2393) & ts(2300)
'no-dupe-keys': 'off', // ts(1117)
'no-func-assign': 'off', // ts(2539)
'no-import-assign': 'off', // ts(2539) & ts(2540)
'no-new-symbol': 'off', // ts(7009)
'no-obj-calls': 'off', // ts(2349)
'no-redeclare': 'off', // ts(2451)
'no-setter-return': 'off', // ts(2408)
'no-this-before-super': 'off', // ts(2376)
'no-undef': 'off', // ts(2304)
'no-unreachable': 'off', // ts(7027)
'no-unsafe-negation': 'off', // ts(2365) & ts(2360) & ts(2358)
'no-var': 'error', // ts transpiles let/const to var, so no need for vars any more
'prefer-const': 'error', // ts provides better types with const
'prefer-rest-params': 'error', // ts provides better types with rest args over arguments
'prefer-spread': 'error', // ts transpiles spread to apply, so no need for manual apply
'valid-typeof': 'off', // ts(2367)
'no-unused-vars': 'off', // ts takes care of this
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/consistent-type-imports': ['error', {
disallowTypeAnnotations: false,
prefer: 'type-imports',
}],
'@typescript-eslint/no-unused-vars': ['error', {
args: 'after-used',
argsIgnorePattern: '^_',
ignoreRestSiblings: true,
vars: 'all',
varsIgnorePattern: '^_',
}],
},
},
]
}