Skip to content

Commit

Permalink
* fix `Parsing error: "parserOptions.programs" has been provided for …
Browse files Browse the repository at this point in the history
…@typescript-eslint/parser.

The file was not found in any of the provided program instance(s):` by vuejs/vue-eslint-parser#104 (comment)
* reset `languageOptions.parserOptions.ecmaVersion` to `latest` as it's set to `2018` by `pluginImportX.configs.recommended`
- rules from `@typescript-eslint` for file `eslint.config.js`
* simplify the importing of `vite.config.ts`
* ignore files generated by yarn
- rule `@typescript-eslint/no-throw-literal`: typescript-eslint/typescript-eslint#9083
@ eslint.config.js

$ yarn eslint --fix
@ fe
  • Loading branch information
n0099 committed Jun 5, 2024
1 parent 0effb52 commit d06b60f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
37 changes: 23 additions & 14 deletions fe/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const rules = [{ // as of eslint-plugin-unicorn@50.0.1
'unicorn/prevent-abbreviations': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/filename-case': 'off',
'unicorn/prefer-string-raw': 'off',
},
optin: {
'unicorn/catch-error-name': ['error', { name: 'e' }],
Expand Down Expand Up @@ -283,8 +284,6 @@ const rules = [{ // as of eslint-plugin-unicorn@50.0.1
hoist: 'all',
allow: ['name'],
}],
'no-throw-literal': 'off',
'@typescript-eslint/no-throw-literal': 'error',
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': 'error',
'no-use-before-define': 'off',
Expand Down Expand Up @@ -522,17 +521,17 @@ const rules = [{ // as of eslint-plugin-unicorn@50.0.1
}];

import viteConfig from './vite.config.ts';
import pluginStylistic from '@stylistic/eslint-plugin';
import pluginImportX from 'eslint-plugin-import-x';
import pluginUnicorn from 'eslint-plugin-unicorn';
import * as typescriptESLintParserForExtraFiles from 'typescript-eslint-parser-for-extra-files';
import * as vueESLintParser from 'vue-eslint-parser';
import vueESLintConfigTypescriptRecommendedExtends from '@vue/eslint-config-typescript/recommended.js';
import pluginVue from 'eslint-plugin-vue';
import { fixupConfigRules } from '@eslint/compat';
import { FlatCompat } from '@eslint/eslintrc';
import eslintJs from '@eslint/js';
import * as vueESLintParser from 'vue-eslint-parser';
import pluginVue from 'eslint-plugin-vue'
import vueESLintConfigTypescriptRecommendedExtends from '@vue/eslint-config-typescript/recommended.js'
import * as typescriptESLintParserForExtraFiles from 'typescript-eslint-parser-for-extra-files';
import pluginStylistic from '@stylistic/eslint-plugin';
import stylisticMigrate from '@stylistic/eslint-plugin-migrate';
import pluginImportX from 'eslint-plugin-import-x';
import pluginUnicorn from 'eslint-plugin-unicorn';
import * as _ from 'lodash-es';

// https://github.com/eslint/eslint/issues/18093
Expand All @@ -553,6 +552,8 @@ export default [
'plugin:@tanstack/eslint-plugin-query/recommended', // https://github.com/TanStack/query/pull/7253
)),
pluginUnicorn.configs['flat/recommended'],
{ languageOptions: { parserOptions: { ecmaVersion: 'latest' } } },
{ ignores: ['.yarn/', '.pnp.*'] },
{ linterOptions: { reportUnusedDisableDirectives: 'error' } },
{
languageOptions: {
Expand All @@ -562,9 +563,15 @@ export default [
},
},
plugins: { '@stylistic': pluginStylistic },

// https://stackoverflow.com/questions/30221286/how-to-convert-an-array-of-objects-to-an-object-in-lodash/36692117#36692117
rules: Object.assign({}, ..._.flatten(_.map(rules, Object.values))),
rules: Object.assign({}, ..._.flatMap(rules, Object.values)),
},
{
files: ['**/*.js'],
languageOptions: { // https://github.com/vuejs/vue-eslint-parser/issues/104#issuecomment-2148652586
parserOptions: { disallowAutomaticSingleRunInference: true },
},
},
{
files: ['**/*.ts'],
Expand All @@ -584,9 +591,7 @@ export default [
settings: {
'import-x/resolver': {
typescript: true,

// https://github.com/pzmosquito/eslint-import-resolver-vite/issues/12#issuecomment-1979897899
vite: { viteConfig: import('./vite.config') },
vite: { viteConfig }, // https://github.com/pzmosquito/eslint-import-resolver-vite/issues/12#issuecomment-2148676875
},
},
},
Expand All @@ -598,6 +603,10 @@ export default [
'@stylistic/migrate/migrate-ts': 'error',
'@stylistic/comma-dangle': ['error', 'always-multiline'],
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
},
},
];
2 changes: 1 addition & 1 deletion fe/src/views/Post.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ useHead({
const forumName = `${firstPostPage.forum.name}吧`;
const threadTitle = firstPostPage.threads[0].title;
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
switch (queryFormRef.value?.getCurrentQueryType()) {
case 'fid':
case 'search':
Expand Down

0 comments on commit d06b60f

Please sign in to comment.