|
| 1 | +const storagePattern = { |
| 2 | + group: ['@react-native-async-storage/*'], |
| 3 | + message: |
| 4 | + "\n\nImport of @react-native-async-storage is allowed only in 'src/services/storage'. \n\nUse `import { DeviceStorage } from '@AppServices/storage'` instead", |
| 5 | +}; |
| 6 | + |
| 7 | +const deviceInfoPattern = { |
| 8 | + group: [ |
| 9 | + '@amazon-devices/react-native-device-info', |
| 10 | + '@amazon-devices/react-native-device-info/*', |
| 11 | + ], |
| 12 | + message: |
| 13 | + "\n\nImport of @amazon-devices/react-native-device-info is allowed only in 'src/services/deviceInfo'. \n\nUse `import { DeviceInfo } from '@AppServices/deviceInfo'` instead", |
| 14 | +}; |
| 15 | + |
| 16 | +const netInfoPattern = { |
| 17 | + group: [ |
| 18 | + '@amazon-devices/keplerscript-netmgr-lib', |
| 19 | + '@amazon-devices/keplerscript-netmgr-lib/*', |
| 20 | + ], |
| 21 | + message: |
| 22 | + "\n\nImport of @amazon-devices/keplerscript-netmgr-lib is allowed only in 'src/services/netInfo'. \n\nUse `import { NetInfo } from '@AppServices/netInfo'` instead", |
| 23 | +}; |
| 24 | + |
| 25 | +const appConfigPattern = { |
| 26 | + group: ['@AppEnvs'], |
| 27 | + message: |
| 28 | + "\n\nImport envs is allowed only in 'src/services/appConfig'. \n\nUse `import { AppEnvs } from '@AppServices/appConfig'` instead", |
| 29 | +}; |
| 30 | + |
| 31 | +const keplerUiComponentsGroup = { |
| 32 | + group: ['@amazon-devices/kepler-ui-components'], |
| 33 | + message: |
| 34 | + "\n\nImport Kepler UI component is allowed only in 'src/components/core' and 'src/theme'.\n\nImport needed component from '@AppComponents/core", |
| 35 | +}; |
| 36 | + |
| 37 | +const tvFocusGuideViewPath = { |
| 38 | + name: '@amazon-devices/react-native-kepler', |
| 39 | + importNames: ['TVFocusGuideView'], |
| 40 | + message: 'Please use FocusGuideView from @AppServices/focusGuide instead', |
| 41 | +}; |
| 42 | + |
| 43 | +const useTVEventHandlerPath = { |
| 44 | + name: '@amazon-devices/react-native-kepler', |
| 45 | + importNames: ['useTVEventHandler'], |
| 46 | + message: |
| 47 | + 'Please use useFocusGuideEventHandler from @AppServices/focusGuide instead', |
| 48 | +}; |
| 49 | + |
| 50 | +const rules = { |
| 51 | + 'react-compiler/react-compiler': 'error', |
| 52 | + 'import/order': [ |
| 53 | + 'error', |
| 54 | + { |
| 55 | + groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'], |
| 56 | + pathGroups: [ |
| 57 | + { |
| 58 | + pattern: '@App*', |
| 59 | + group: 'parent', |
| 60 | + position: 'before', |
| 61 | + }, |
| 62 | + { |
| 63 | + pattern: '@App*/**', |
| 64 | + group: 'parent', |
| 65 | + position: 'before', |
| 66 | + }, |
| 67 | + { |
| 68 | + pattern: './**', |
| 69 | + group: 'parent', |
| 70 | + position: 'after', |
| 71 | + }, |
| 72 | + ], |
| 73 | + alphabetize: { |
| 74 | + order: 'asc', |
| 75 | + caseInsensitive: false, |
| 76 | + }, |
| 77 | + distinctGroup: false, |
| 78 | + 'newlines-between': 'always', |
| 79 | + warnOnUnassignedImports: true, |
| 80 | + }, |
| 81 | + ], |
| 82 | + 'no-restricted-imports': [ |
| 83 | + 'error', |
| 84 | + { |
| 85 | + paths: [tvFocusGuideViewPath, useTVEventHandlerPath], |
| 86 | + patterns: [ |
| 87 | + storagePattern, |
| 88 | + deviceInfoPattern, |
| 89 | + netInfoPattern, |
| 90 | + appConfigPattern, |
| 91 | + keplerUiComponentsGroup, |
| 92 | + ], |
| 93 | + }, |
| 94 | + ], |
| 95 | + 'react-native/no-raw-text': [ |
| 96 | + 'error', |
| 97 | + { |
| 98 | + skip: ['Typography'], |
| 99 | + }, |
| 100 | + ], |
| 101 | + 'no-console': 'error', |
| 102 | + 'no-restricted-properties': [ |
| 103 | + 'error', |
| 104 | + { |
| 105 | + object: 'console', |
| 106 | + property: 'log', |
| 107 | + message: 'Please use `logDebug` from `@AppUtils/logging`', |
| 108 | + }, |
| 109 | + { |
| 110 | + object: 'console', |
| 111 | + property: 'warn', |
| 112 | + message: 'Please use `logWarning` from `@AppUtils/logging`', |
| 113 | + }, |
| 114 | + { |
| 115 | + object: 'console', |
| 116 | + property: 'error', |
| 117 | + message: 'Please use `logError` from `@AppUtils/logging`', |
| 118 | + }, |
| 119 | + ], |
| 120 | + curly: ['error'], |
| 121 | + '@typescript-eslint/no-explicit-any': 'error', |
| 122 | + '@typescript-eslint/consistent-type-imports': 'error', |
| 123 | + 'react-native-a11y/has-accessibility-hint': 'off', |
| 124 | + 'react-native-a11y/has-valid-accessibility-descriptors': 'off', // eslint-plugin-amzn-a11y rule is used instead |
| 125 | + 'amzn-a11y/no-inferior-a11y-props': 'error', |
| 126 | + 'amzn-a11y/no-missing-a11y-props': 'error', |
| 127 | +}; |
| 128 | + |
| 129 | +const overrides = [ |
| 130 | + { |
| 131 | + files: ['src/services/storage/**/*'], |
| 132 | + rules: { |
| 133 | + 'no-restricted-imports': [ |
| 134 | + 'off', |
| 135 | + { |
| 136 | + patterns: [storagePattern], |
| 137 | + }, |
| 138 | + ], |
| 139 | + }, |
| 140 | + }, |
| 141 | + { |
| 142 | + files: ['src/services/deviceInfo/**/*'], |
| 143 | + rules: { |
| 144 | + 'no-restricted-imports': [ |
| 145 | + 'off', |
| 146 | + { |
| 147 | + patterns: [deviceInfoPattern], |
| 148 | + }, |
| 149 | + ], |
| 150 | + }, |
| 151 | + }, |
| 152 | + { |
| 153 | + files: ['src/services/netInfo/**/*'], |
| 154 | + rules: { |
| 155 | + 'no-restricted-imports': [ |
| 156 | + 'off', |
| 157 | + { |
| 158 | + patterns: [netInfoPattern], |
| 159 | + }, |
| 160 | + ], |
| 161 | + }, |
| 162 | + }, |
| 163 | + { |
| 164 | + files: ['src/services/appConfig/**/*'], |
| 165 | + rules: { |
| 166 | + 'no-restricted-imports': [ |
| 167 | + 'off', |
| 168 | + { |
| 169 | + patterns: [appConfigPattern], |
| 170 | + }, |
| 171 | + ], |
| 172 | + }, |
| 173 | + }, |
| 174 | + { |
| 175 | + files: ['src/components/core/**/*', 'src/theme/**/*'], |
| 176 | + rules: { |
| 177 | + 'no-restricted-imports': [ |
| 178 | + 'off', |
| 179 | + { |
| 180 | + patterns: [keplerUiComponentsGroup], |
| 181 | + }, |
| 182 | + ], |
| 183 | + }, |
| 184 | + }, |
| 185 | + { |
| 186 | + files: ['src/**/*.test.tsx', 'src/**/*.spec.tsx'], |
| 187 | + rules: { |
| 188 | + 'react-native/no-color-literals': ['off'], |
| 189 | + 'react-native/no-inline-styles': ['off'], |
| 190 | + }, |
| 191 | + }, |
| 192 | + { |
| 193 | + files: ['src/services/focusGuide/**/*'], |
| 194 | + rules: { |
| 195 | + 'no-restricted-imports': [ |
| 196 | + 'off', |
| 197 | + { |
| 198 | + paths: [tvFocusGuideViewPath, useTVEventHandlerPath], |
| 199 | + }, |
| 200 | + ], |
| 201 | + }, |
| 202 | + }, |
| 203 | +]; |
| 204 | + |
| 205 | +module.exports = { |
| 206 | + root: true, |
| 207 | + extends: ['@callstack', 'plugin:react-native-a11y/basic'], |
| 208 | + plugins: [ |
| 209 | + '@typescript-eslint', |
| 210 | + 'import', |
| 211 | + 'amzn-a11y', |
| 212 | + 'eslint-plugin-react-compiler', |
| 213 | + ], |
| 214 | + rules, |
| 215 | + overrides, |
| 216 | + parserOptions: { |
| 217 | + project: './tsconfig.json', |
| 218 | + }, |
| 219 | + parser: '@typescript-eslint/parser', |
| 220 | + settings: { |
| 221 | + 'import/resolver': 'typescript', |
| 222 | + /** |
| 223 | + * below is to make all `@` imports internal to make sure we can |
| 224 | + * group them (external imports cannot be group with `groupPath`) |
| 225 | + */ |
| 226 | + 'import/internal-regex': '^@(.*?)/', |
| 227 | + }, |
| 228 | +}; |
0 commit comments