diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index ba883a4c..00000000 --- a/.eslintrc.json +++ /dev/null @@ -1,130 +0,0 @@ -{ - "env": { - "browser": true, - "shared-node-browser": true, - "node": true, - "es6": true - }, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:react/jsx-runtime", - "plugin:react-hooks/recommended", - "plugin:import/errors", - "plugin:import/warnings", - "plugin:prettier/recommended" - ], - "plugins": ["react-compiler"], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module", - "ecmaFeatures": { - "jsx": true - } - }, - "rules": { - "react-compiler/react-compiler": "warn", - "import/namespace": "off", - "import/named": "off", - "eqeqeq": "error", - "no-var": "error", - "prefer-const": "error", - "curly": ["warn", "multi-line", "consistent"], - "no-console": "off", - "import/extensions": ["error", "always"], - "import/no-unresolved": ["error", { "commonjs": true, "amd": true }], - "import/export": "error", - "import/no-duplicates": ["error"], - "@typescript-eslint/explicit-module-boundary-types": "off", - "@typescript-eslint/no-unused-vars": [ - "warn", - { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" } - ], - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-explicit-any": "off", - "import/order": [ - "error", - { - "alphabetize": { "order": "asc", "caseInsensitive": true }, - "groups": [ - "builtin", - "external", - "internal", - "parent", - "sibling", - "index", - "object" - ], - "newlines-between": "never", - "pathGroups": [ - { - "pattern": "react", - "group": "builtin", - "position": "before" - } - ], - "pathGroupsExcludedImportTypes": ["builtin"] - } - ], - "sort-imports": [ - "error", - { - "ignoreDeclarationSort": true - } - ] - }, - "settings": { - "react": { - "version": "detect" - }, - "import/extensions": [".js", ".jsx", ".ts", ".tsx"], - "import/parsers": { - "@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx"] - }, - "import/resolver": { - "alias": { - "extensions": [".js", ".jsx", ".ts", ".tsx"], - "map": [ - ["^valtio$", "./src/index.ts"], - ["valtio", "./src"] - ] - } - } - }, - "overrides": [ - { - "extends": [ - "plugin:jest-dom/recommended", - "plugin:testing-library/react", - "plugin:@vitest/legacy-recommended" - ], - "files": ["tests/**/*.ts", "tests/**/*.tsx"], - "rules": { - "import/extensions": ["error", "never"], - "@vitest/expect-expect": "off", - "@vitest/consistent-test-it": [ - "error", - { "fn": "it", "withinDescribe": "it" } - ], - "@typescript-eslint/no-unused-vars": "off" - } - }, - { - "files": ["./*.js"], - "rules": { - "@typescript-eslint/no-require-imports": "off" - } - }, - { - "files": [ - "src/vanilla/utils/proxyMap.ts", - "src/vanilla/utils/proxySet.ts" - ], - "rules": { - "@typescript-eslint/no-unused-expressions": "off" - } - } - ] -} diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 00000000..c2ba99da --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,142 @@ +const eslint = require('@eslint/js') +const vitest = require('@vitest/eslint-plugin') +const importPlugin = require('eslint-plugin-import') +const jestDom = require('eslint-plugin-jest-dom') +const prettierRecommended = require( + require.resolve('eslint-plugin-prettier/recommended'), +) +const react = require('eslint-plugin-react') +const reactCompiler = require('eslint-plugin-react-compiler') +const reactHooks = require('eslint-plugin-react-hooks') +const testingLibrary = require('eslint-plugin-testing-library') +const globals = require('globals') +const tseslint = require('typescript-eslint') + +module.exports = tseslint.config( + eslint.configs.recommended, + tseslint.configs.recommended, + react.configs.flat['jsx-runtime'], + importPlugin.flatConfigs.errors, + importPlugin.flatConfigs.warnings, + { + languageOptions: { + globals: { + ...globals.browser, + ...globals['shared-node-browser'], + ...globals.node, + ...globals.es2015, + }, + parser: tseslint.parser, + parserOptions: { + ecmaVersion: 2018, + sourceType: 'module', + ecmaFeatures: { + jsx: true, + }, + }, + }, + plugins: { + 'react-compiler': reactCompiler, + 'react-hooks': reactHooks, + }, + settings: { + react: { + version: 'detect', + }, + 'import/extensions': ['.js', '.jsx', '.ts', '.tsx'], + 'import/parsers': { + '@typescript-eslint/parser': ['.js', '.jsx', '.ts', '.tsx'], + }, + 'import/resolver': { + alias: { + extensions: ['.js', '.jsx', '.ts', '.tsx'], + map: [ + ['^valtio$', './src/index.ts'], + ['valtio', './src'], + ], + }, + }, + }, + rules: { + ...reactHooks.configs.recommended.rules, + 'react-compiler/react-compiler': 'warn', + 'import/namespace': 'off', + 'import/named': 'off', + eqeqeq: 'error', + 'no-var': 'error', + 'prefer-const': 'error', + curly: ['warn', 'multi-line', 'consistent'], + 'no-console': 'off', + 'import/extensions': ['error', 'always'], + 'import/no-unresolved': ['error', { commonjs: true, amd: true }], + 'import/export': 'error', + 'import/no-duplicates': ['error'], + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-unused-vars': [ + 'warn', + { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }, + ], + '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/no-empty-function': 'off', + '@typescript-eslint/no-explicit-any': 'off', + 'import/order': [ + 'error', + { + alphabetize: { order: 'asc', caseInsensitive: true }, + groups: [ + 'builtin', + 'external', + 'internal', + 'parent', + 'sibling', + 'index', + 'object', + ], + 'newlines-between': 'never', + pathGroups: [ + { + pattern: 'react', + group: 'builtin', + position: 'before', + }, + ], + pathGroupsExcludedImportTypes: ['builtin'], + }, + ], + 'sort-imports': [ + 'error', + { + ignoreDeclarationSort: true, + }, + ], + }, + }, + { + files: ['tests/**/*.{ts,tsx}'], + ...testingLibrary.configs['flat/react'], + ...jestDom.configs['flat/recommended'], + ...vitest.configs.recommended, + rules: { + 'import/extensions': ['error', 'never'], + 'vitest/expect-expect': 'off', + 'vitest/consistent-test-it': [ + 'error', + { fn: 'it', withinDescribe: 'it' }, + ], + '@typescript-eslint/no-unused-vars': 'off', + }, + }, + { + files: ['*.js'], + rules: { + '@typescript-eslint/no-require-imports': 'off', + }, + }, + { + files: ['src/vanilla/utils/proxyMap.ts', 'src/vanilla/utils/proxySet.ts'], + rules: { + '@typescript-eslint/no-unused-expressions': 'off', + }, + }, + prettierRecommended, +)