diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..79e1774 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,107 @@ +import globals from 'globals'; +import eslintConfigPrettier from 'eslint-config-prettier'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { FlatCompat } from '@eslint/eslintrc'; +import pluginJs from '@eslint/js'; +import pluginImport from 'eslint-plugin-import'; + +// mimic CommonJS variables -- not needed if using CommonJS +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: pluginJs.configs.recommended, +}); + +export default [ + { + ignores: [ + '.vscode/', + '.yarn/', + 'dist/', + 'public/', + 'docs/', + 'src/**/*.generated.*', + 'eslint.config.js', + ], + }, + { languageOptions: { globals: { ...globals.browser, ...globals.node } } }, + ...compat.extends('standard'), + { + languageOptions: { + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + }, + plugins: { + import: pluginImport, + }, + settings: { + // This will do the trick + 'import/parsers': { + espree: ['.js', '.cjs', '.mjs', '.jsx'], + }, + 'import/resolver': { + node: true, + alias: { + map: [ + ['@', './src'], + ['~', './node_modules'], + ], + extensions: ['.js', '.jsx'], + }, + }, + vite: { + configPath: './vite.config.ts', + }, + }, + rules: { + camelcase: 'off', + 'no-unused-vars': 'warn', + // Fix for Vue setup style + 'import/default': 'off', + // Fix for Vue setup style + 'import/no-default-export': 'off', + // Sort Import Order. + // see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md#importorder-enforce-a-convention-in-module-import-order + 'import/order': [ + 'error', + { + groups: [ + 'builtin', + 'external', + 'parent', + 'sibling', + 'index', + 'object', + 'type', + ], + pathGroups: [ + // Vue Core + { + pattern: + '{vue,vue-router,vuex,@/stores,vue-i18n,pinia,vite,vitest,vitest/**,@vitejs/**,@vue/**}', + group: 'external', + position: 'before', + }, + // Internal Codes + { + pattern: '{@/**}', + group: 'internal', + position: 'before', + }, + ], + pathGroupsExcludedImportTypes: ['builtin'], + alphabetize: { + order: 'asc', + }, + 'newlines-between': 'always', + }, + ], + }, + }, + // ...pluginVue.configs['flat/recommended'], + eslintConfigPrettier, +];