|
| 1 | +const features = ['canvas', 'generator', 'node-editor', 'node-palette'] |
| 2 | +const crossFeatureRules = features.map((feature) => ({ |
| 3 | + target: `./src/features/${feature}`, |
| 4 | + from: './src/features', |
| 5 | + except: [`./${feature}`], |
| 6 | + message: 'Features cannot import from other features. Move shared logic to core.' |
| 7 | +})) |
| 8 | + |
| 9 | +module.exports = { |
| 10 | + extends: [ |
| 11 | + 'eslint:recommended', |
| 12 | + 'plugin:react/recommended', |
| 13 | + 'plugin:react/jsx-runtime', |
| 14 | + 'plugin:react-hooks/recommended', |
| 15 | + 'plugin:jsx-a11y/recommended', |
| 16 | + 'plugin:@typescript-eslint/recommended', |
| 17 | + 'plugin:prettier/recommended' |
| 18 | + ], |
| 19 | + parser: '@typescript-eslint/parser', |
| 20 | + parserOptions: { |
| 21 | + ecmaVersion: 'latest', |
| 22 | + sourceType: 'module', |
| 23 | + ecmaFeatures: { |
| 24 | + jsx: true |
| 25 | + } |
| 26 | + }, |
| 27 | + settings: { |
| 28 | + react: { |
| 29 | + version: 'detect' |
| 30 | + } |
| 31 | + }, |
| 32 | + plugins: ['react', 'react-hooks', '@typescript-eslint', 'unused-imports', 'jsx-a11y', 'simple-import-sort', 'import'], |
| 33 | + ignorePatterns: ['dist', 'node_modules', 'build', 'vite.config.ts', 'examples/dist', '**/*.json'], |
| 34 | + rules: { |
| 35 | + '@typescript-eslint/explicit-module-boundary-types': 'off', |
| 36 | + '@typescript-eslint/no-explicit-any': 'warn', |
| 37 | + '@typescript-eslint/no-unused-vars': 'off', |
| 38 | + 'no-unused-vars': 'off', |
| 39 | + 'unused-imports/no-unused-imports': 'warn', |
| 40 | + 'unused-imports/no-unused-vars': [ |
| 41 | + 'warn', |
| 42 | + { |
| 43 | + vars: 'all', |
| 44 | + varsIgnorePattern: '^_', |
| 45 | + args: 'after-used', |
| 46 | + argsIgnorePattern: '^_' |
| 47 | + } |
| 48 | + ], |
| 49 | + 'no-console': ['warn', { allow: ['warn', 'error', 'info'] }], |
| 50 | + 'react/prop-types': 'off', |
| 51 | + 'react/react-in-jsx-scope': 'off', |
| 52 | + 'simple-import-sort/imports': [ |
| 53 | + 'error', |
| 54 | + { |
| 55 | + groups: [ |
| 56 | + // Side effect imports |
| 57 | + ['^\\u0000'], |
| 58 | + // React and React-related packages first |
| 59 | + ['^react', '^react-dom'], |
| 60 | + // Other external packages (starting with @ or letter) |
| 61 | + ['^@?\\w'], |
| 62 | + // Internal packages (using @ alias) |
| 63 | + ['^@/'], |
| 64 | + // Parent imports (../) |
| 65 | + ['^\\.\\.(?!/?$)', '^\\.\\./?$'], |
| 66 | + // Same directory imports (./) |
| 67 | + ['^\\./(?=.*/)(?!/?$)', '^\\.(?!/?$)', '^\\./?$'], |
| 68 | + // Type imports |
| 69 | + ['^.+\\.?(css|scss)$'] |
| 70 | + ] |
| 71 | + } |
| 72 | + ], |
| 73 | + 'simple-import-sort/exports': 'error', |
| 74 | + 'import/first': 'error', |
| 75 | + 'import/newline-after-import': 'error', |
| 76 | + 'import/no-duplicates': 'error', |
| 77 | + 'prettier/prettier': 'error', |
| 78 | + // Architectural boundary enforcement |
| 79 | + 'import/no-restricted-paths': [ |
| 80 | + 'error', |
| 81 | + { |
| 82 | + zones: [ |
| 83 | + // atoms/ can only import from core/types (not from features, infrastructure, or core utils) |
| 84 | + { |
| 85 | + target: './src/atoms', |
| 86 | + from: './src/features', |
| 87 | + message: 'Atoms cannot import from features. Keep atoms dumb and reusable.' |
| 88 | + }, |
| 89 | + { |
| 90 | + target: './src/atoms', |
| 91 | + from: './src/infrastructure', |
| 92 | + message: 'Atoms cannot import from infrastructure. Use props instead of contexts.' |
| 93 | + }, |
| 94 | + { |
| 95 | + target: './src/atoms', |
| 96 | + from: './src/core', |
| 97 | + except: ['./types'], |
| 98 | + message: 'Atoms can only import types from core/types, not utilities or business logic.' |
| 99 | + }, |
| 100 | + // core/ cannot import from anything (leaf node) |
| 101 | + { |
| 102 | + target: './src/core', |
| 103 | + from: './src/atoms', |
| 104 | + message: 'Core is a leaf node and cannot import from atoms.' |
| 105 | + }, |
| 106 | + { |
| 107 | + target: './src/core', |
| 108 | + from: './src/features', |
| 109 | + message: 'Core is a leaf node and cannot import from features.' |
| 110 | + }, |
| 111 | + { |
| 112 | + target: './src/core', |
| 113 | + from: './src/infrastructure', |
| 114 | + message: 'Core is a leaf node and cannot import from infrastructure.' |
| 115 | + }, |
| 116 | + // infrastructure/ can only import from core/ |
| 117 | + { |
| 118 | + target: './src/infrastructure', |
| 119 | + from: './src/atoms', |
| 120 | + message: 'Infrastructure cannot import from atoms. Move shared code to core.' |
| 121 | + }, |
| 122 | + { |
| 123 | + target: './src/infrastructure', |
| 124 | + from: './src/features', |
| 125 | + message: 'Infrastructure cannot import from features. Move shared code to core.' |
| 126 | + }, |
| 127 | + // features/ cannot import from other features (prevent cross-feature dependencies) |
| 128 | + ...crossFeatureRules |
| 129 | + ] |
| 130 | + } |
| 131 | + ] |
| 132 | + }, |
| 133 | + env: { |
| 134 | + browser: true, |
| 135 | + es2021: true, |
| 136 | + node: true |
| 137 | + }, |
| 138 | + overrides: [ |
| 139 | + { |
| 140 | + files: ['examples/**/*.{js,jsx,ts,tsx}'], |
| 141 | + rules: { |
| 142 | + 'no-console': 'off', |
| 143 | + '@typescript-eslint/no-non-null-assertion': 'off' |
| 144 | + } |
| 145 | + } |
| 146 | + ] |
| 147 | +} |
0 commit comments