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

Migrate to eslint 9 #79

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
21 changes: 0 additions & 21 deletions .eslintrc.js

This file was deleted.

19 changes: 19 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import eslint from '@eslint/js';
import vue from 'eslint-plugin-vue';
import recommended from './recommended.mjs';
import tseslint from "typescript-eslint";
import globals from "globals"

export default tseslint.config(...vue.configs["flat/essential"], eslint.configs.recommended, ...recommended, {
languageOptions: {
globals: globals.browser,
}
}, {
files: ['test/**.spec.js'],
languageOptions: {
globals: globals.jest,
},
rules: {
'@typescript-eslint/no-var-requires': 'off'
}
});
46 changes: 0 additions & 46 deletions index.js

This file was deleted.

33 changes: 33 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import tseslint from "typescript-eslint";

export default tseslint.config(tseslint.configs.eslintRecommended, {
plugins: {
'@typescript-eslint': tseslint.plugin,
},
languageOptions: {
parserOptions: {
parser: {
'ts': tseslint.parser,
'tsx': tseslint.parser,
'cts': tseslint.parser,
'mts': tseslint.parser,
},
extraFileExtensions: ['.vue'],
ecmaFeatures: {
jsx: true,
}
}
},

}, {
files: ['*.ts', '*.cts', '*.mts', '*.tsx', '*.vue'],
rules: {
// The core 'no-unused-vars' rules (in the eslint:recommeded ruleset)
// does not work with type definitions
'no-unused-vars': 'off',
// TS already checks for that, and Typescript-Eslint recommends to disable it
// https://typescript-eslint.io/linting/troubleshooting#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors
'no-undef': 'off',
'@typescript-eslint/no-unused-vars': 'warn'
}
});
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "@vue/eslint-config-typescript",
"version": "13.0.0",
"description": "eslint-config-typescript for vue-cli",
"main": "index.js",
"main": "index.mjs",
"files": [
"index.js",
"recommended.js"
"index.mjs",
"recommended.mjs"
],
"scripts": {
"test": "jest"
Expand All @@ -30,7 +30,7 @@
},
"homepage": "https://github.com/vuejs/eslint-config-typescript#readme",
"devDependencies": {
"eslint": "^8.56.0",
"eslint": "^9.8.0",
"eslint-plugin-vue": "^9.22.0",
"execa": "^4.1.0",
"jest": "^26.6.3",
Expand All @@ -40,7 +40,7 @@
"vue-property-decorator": "^9.1.2"
},
"peerDependencies": {
"eslint": "^8.56.0",
"eslint": "^9.8.0",
"eslint-plugin-vue": "^9.0.0",
"typescript": ">=4.7.4"
},
Expand All @@ -50,8 +50,8 @@
}
},
"dependencies": {
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"@eslint/js": "^9.8.0",
"typescript-eslint": "^8.0.1",
"vue-eslint-parser": "^9.3.1"
},
"engines": {
Expand Down
48 changes: 0 additions & 48 deletions recommended.js

This file was deleted.

42 changes: 42 additions & 0 deletions recommended.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import tseslint from "typescript-eslint";
import index from "./index.mjs";
import eslintParser from 'vue-eslint-parser';

export default tseslint.config(...index, ...tseslint.configs.recommended, {
languageOptions: {
parser: eslintParser,
},
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
},
}, {
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'
}
});
3 changes: 3 additions & 0 deletions test/fixtures/default/src/shims-tsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import Vue, { VNode } from 'vue'
declare global {
namespace JSX {
// tslint:disable no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface Element extends VNode {}
// tslint:disable no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
interface ElementClass extends Vue {}
interface IntrinsicElements {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[elem: string]: any;
}
}
Expand Down
2 changes: 0 additions & 2 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ async function lintProject (name) {
eslintPath,
[
`${projectPath}/`,
'--ext',
'.vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts',
'--no-ignore'
],
{
Expand Down