Skip to content

Commit 7c769fe

Browse files
authoredNov 29, 2022
feat(ts): add rules that required parserOptions (#131)
Closes #112
1 parent 6189a92 commit 7c769fe

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed
 

‎packages/typescript/index.js

+26-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const fs = require('fs')
2+
const { join } = require('path')
13
const basic = require('@antfu/eslint-config-basic')
24

35
module.exports = {
@@ -11,7 +13,30 @@ module.exports = {
1113
node: { extensions: ['.js', '.jsx', '.mjs', '.ts', '.tsx', '.d.ts'] },
1214
},
1315
},
14-
overrides: basic.overrides,
16+
overrides: basic.overrides.concat(
17+
!fs.existsSync(join(process.cwd(), 'tsconfig.json'))
18+
? []
19+
: [{
20+
parserOptions: {
21+
tsconfigRootDir: process.cwd(),
22+
project: ['tsconfig.json'],
23+
},
24+
parser: '@typescript-eslint/parser',
25+
excludedFiles: ['**/*.md/*.*'],
26+
files: ['*.ts', '*.tsx'],
27+
rules: {
28+
'no-throw-literal': 'off',
29+
'@typescript-eslint/no-throw-literal': 'error',
30+
'no-implied-eval': 'off',
31+
'@typescript-eslint/no-implied-eval': 'error',
32+
'dot-notation': 'off',
33+
'@typescript-eslint/dot-notation': ['error', { allowKeywords: true }],
34+
'no-void': ['error', { 'allowAsStatement': true }],
35+
'@typescript-eslint/no-floating-promises': 'error',
36+
'@typescript-eslint/no-misused-promises': 'error',
37+
},
38+
}],
39+
),
1540
rules: {
1641
'import/named': 'off',
1742

@@ -109,17 +134,6 @@ module.exports = {
109134
// antfu
110135
'antfu/generic-spacing': 'error',
111136

112-
// The following rule overrides require a parser service, aka. require a `typescript.json` path.
113-
// This needs to be done individually for each project, and it slows down linting significantly.
114-
// 'no-throw-literal': 'off',
115-
// '@typescript-eslint/no-throw-literal': 'error',
116-
// 'no-implied-eval': 'off',
117-
// '@typescript-eslint/no-implied-eval': 'error',
118-
// 'dot-notation': 'off',
119-
// '@typescript-eslint/dot-notation': ['error', { allowKeywords: true }],
120-
// '@typescript-eslint/no-floating-promises': 'error',
121-
// '@typescript-eslint/no-misused-promises': 'error',
122-
123137
// off
124138
'@typescript-eslint/consistent-indexed-object-style': 'off',
125139
'@typescript-eslint/naming-convention': 'off',

0 commit comments

Comments
 (0)
Please sign in to comment.