Files
electron-opencode/eslint.config.js
houakang c738e638cf refactor: 统一代码风格并更新依赖配置
- 统一使用单引号替代双引号
- 移除不必要的分号
- 更新prettier配置使用更宽松的格式
- 添加eslint配置文件和相关依赖
- 更新package.json中的脚本和依赖版本
2026-04-10 10:39:41 +08:00

107 lines
3.3 KiB
JavaScript

import { defineConfig, globalIgnores } from 'eslint/config'
import vitest from 'eslint-plugin-vitest'
import globals from 'globals'
import js from '@eslint/js'
import pluginVue from 'eslint-plugin-vue'
import skipFormatting from '@vue/eslint-config-prettier/skip-formatting'
export default defineConfig([
{
name: 'app/files-to-lint',
files: ['**/*.{js,mjs,jsx,vue}'],
},
globalIgnores(['**/dist/**', '**/dist-ssr/**', '**/coverage/**', '**/cypress/**', '**/public/**']),
{
languageOptions: {
globals: {
...globals.browser,
...globals.node,
// Electron globals
process: 'readonly',
__dirname: 'readonly',
// Vite globals
MAIN_WINDOW_VITE_DEV_SERVER_URL: 'readonly',
MAIN_WINDOW_VITE_NAME: 'readonly',
// Allow using Vue Composition API and <script setup> macros without explicit imports
// because unplugin-auto-import injects them at build time, while ESLint works on source text.
// Mark as read-only to prevent accidental reassignment warnings.
// Composition API
ref: 'readonly',
shallowRef: 'readonly',
computed: 'readonly',
reactive: 'readonly',
shallowReactive: 'readonly',
readonly: 'readonly',
unref: 'readonly',
toRef: 'readonly',
toRefs: 'readonly',
toRaw: 'readonly',
markRaw: 'readonly',
isRef: 'readonly',
isReactive: 'readonly',
isReadonly: 'readonly',
isProxy: 'readonly',
watch: 'readonly',
watchEffect: 'readonly',
watchPostEffect: 'readonly',
watchSyncEffect: 'readonly',
// Lifecycle
onMounted: 'readonly',
onUpdated: 'readonly',
onUnmounted: 'readonly',
onBeforeMount: 'readonly',
onBeforeUpdate: 'readonly',
onBeforeUnmount: 'readonly',
onActivated: 'readonly',
onDeactivated: 'readonly',
onErrorCaptured: 'readonly',
onRenderTracked: 'readonly',
onRenderTriggered: 'readonly',
// Misc
nextTick: 'readonly',
getCurrentInstance: 'readonly',
inject: 'readonly',
provide: 'readonly',
// Vue 3.5+ template ref helper
useTemplateRef: 'readonly',
// <script setup> compiler macros
defineProps: 'readonly',
defineEmits: 'readonly',
defineExpose: 'readonly',
withDefaults: 'readonly',
},
},
},
// Enable Vitest globals and rules for test files
{
name: 'app/tests-vitest',
files: ['tests/**/*.{test,spec}.{js,jsx,ts,tsx}'],
plugins: { vitest },
rules: {
// Apply Vitest recommended rules
...(vitest.configs?.recommended?.rules ?? {}),
},
languageOptions: {
// Register Vitest testing globals so ESLint doesn't flag them as undefined
globals: (vitest.environments && vitest.environments.env && vitest.environments.env.globals) || {
describe: 'readonly',
test: 'readonly',
it: 'readonly',
expect: 'readonly',
vi: 'readonly',
beforeAll: 'readonly',
afterAll: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
},
},
},
js.configs.recommended,
...pluginVue.configs['flat/essential'],
skipFormatting,
])