Skip to content

Commit d6c79a2

Browse files
authored
Add recommended-type-checked
1 parent 1ec0ef9 commit d6c79a2

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"main": "index.js",
66
"files": [
77
"index.js",
8-
"recommended.js"
8+
"recommended.js",
9+
"recommended-type-checked.js"
910
],
1011
"scripts": {
1112
"test": "jest"

recommended-type-checked.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module.exports = {
2+
extends: [
3+
require.resolve('./index'),
4+
'plugin:@typescript-eslint/recommended-type-checked'
5+
],
6+
7+
// the ts-eslint recommended ruleset sets the parser so we need to set it back
8+
parser: require.resolve('vue-eslint-parser'),
9+
10+
parserOptions: {
11+
parser: require('typescript-eslint-parser-for-extra-files')
12+
},
13+
14+
rules: {
15+
// this rule, if on, would require explicit return type on the `render` function
16+
'@typescript-eslint/explicit-function-return-type': 'off',
17+
18+
// The following rules are enabled in an `overrides` field in the
19+
// `@typescript-eslint/recommended` ruleset, only turned on for TypeScript source modules
20+
// <https://github.com/typescript-eslint/typescript-eslint/blob/cb2d44650d27d8b917e8ce19423245b834db29d2/packages/eslint-plugin/src/configs/eslint-recommended.ts#L27-L30>
21+
22+
// But as ESLint cannot precisely target `<script lang="ts">` blocks and skip normal `<script>`s,
23+
// no TypeScript code in `.vue` files would be checked against these rules.
24+
25+
// So we now enable them globally.
26+
// That would also check plain JavaScript files, which diverges a little from
27+
// the original intention of the `@typescript-eslint/recommended` rulset.
28+
// But it should be mostly fine.
29+
'no-var': 'error', // ts transpiles let/const to var, so no need for vars any more
30+
'prefer-const': 'error', // ts provides better types with const
31+
'prefer-rest-params': 'error', // ts provides better types with rest args over arguments
32+
'prefer-spread': 'error', // ts transpiles spread to apply, so no need for manual apply
33+
},
34+
35+
overrides: [
36+
{
37+
files: ['shims-tsx.d.ts'],
38+
rules: {
39+
'@typescript-eslint/no-empty-interface': 'off',
40+
'@typescript-eslint/no-explicit-any': 'off',
41+
'@typescript-eslint/no-unused-vars': 'off'
42+
}
43+
},
44+
{
45+
files: ['*.js', '*.cjs'],
46+
rules: {
47+
// in plain CommonJS modules, you can't use `import foo = require('foo')` to pass this rule, so it has to be disabled
48+
'@typescript-eslint/no-var-requires': 'off'
49+
}
50+
}
51+
]
52+
}

0 commit comments

Comments
 (0)