Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add recommended-type-checked #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"files": [
"index.js",
"recommended.js"
"recommended.js",
"recommended-type-checked.js"
],
"scripts": {
"test": "jest"
Expand Down
52 changes: 52 additions & 0 deletions recommended-type-checked.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module.exports = {
extends: [
require.resolve('./index'),
'plugin:@typescript-eslint/recommended-type-checked'
],

// the ts-eslint recommended ruleset sets the parser so we need to set it back
parser: require.resolve('vue-eslint-parser'),

parserOptions: {
parser: require('typescript-eslint-parser-for-extra-files')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@segevfiner Curiously, what problems were you running into that required this dependency?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules that use type checking see the linked issues in the PR description.

},

rules: {
// this rule, if on, would require explicit return type on the `render` function
'@typescript-eslint/explicit-function-return-type': 'off',

// The following rules are enabled in an `overrides` field in the
// `@typescript-eslint/recommended` ruleset, only turned on for TypeScript source modules
// <https://github.com/typescript-eslint/typescript-eslint/blob/cb2d44650d27d8b917e8ce19423245b834db29d2/packages/eslint-plugin/src/configs/eslint-recommended.ts#L27-L30>

// But as ESLint cannot precisely target `<script lang="ts">` blocks and skip normal `<script>`s,
// no TypeScript code in `.vue` files would be checked against these rules.

// So we now enable them globally.
// That would also check plain JavaScript files, which diverges a little from
// the original intention of the `@typescript-eslint/recommended` rulset.
// But it should be mostly fine.
'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
},

overrides: [
{
files: ['shims-tsx.d.ts'],
rules: {
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': 'off'
}
},
{
files: ['*.js', '*.cjs'],
rules: {
// in plain CommonJS modules, you can't use `import foo = require('foo')` to pass this rule, so it has to be disabled
'@typescript-eslint/no-var-requires': 'off'
}
}
]
}