@@ -6,53 +6,53 @@ This directory contains custom ESLint rules specific to this project.
66
77### ` require-platform-declaration `
88
9- ** Purpose:** ** Enforces that every non-test source file exports ` __platforms ` ** to declare which platforms it supports.
9+ ** Purpose:** ** Enforces that every configured source file exports ` __platforms ` ** to declare which platforms it supports.
1010
11- ** Why:** This is a mandatory requirement for platform isolation. The rule catches missing declarations at lint time, before build or runtime .
11+ ** Why:** This is a mandatory requirement for platform isolation. The rule catches missing declarations at lint time.
1212
13- ** Requirement:** Every ` .ts ` /` .js ` file in ` lib/ ` (except tests) MUST export ` __platforms ` array with valid platform values.
14-
15- ** Enforcement:**
16- - ✅ Enabled for all ` .ts ` files in ` lib/ ` directory
17- - ❌ Disabled for test files (` .spec.ts ` , ` .test.ts ` , etc.)
18- - ❌ Disabled for ` __mocks__ ` and ` tests ` directories
13+ ** Requirement:** Every configured source file MUST export ` __platforms ` array with valid platform values.
1914
2015** Valid Examples:**
2116
2217``` typescript
2318// Universal file (all platforms)
24- export const __platforms = [' __universal__' ] as const ;
19+ export const __platforms: Platform [] = [' __universal__' ];
2520
2621// Platform-specific file
27- export const __platforms = [' browser' , ' node' ] as const ;
22+ export const __platforms: Platform [] = [' browser' , ' node' ];
2823
29- // With type annotation
30- export const __platforms: Platform [] = [' react_native' ] as const ;
24+ // Single platform
25+ export const __platforms: Platform [] = [' react_native' ];
3126```
3227
3328** Invalid:**
3429
3530``` typescript
3631// Missing __platforms export
37- // ESLint Error: File must export __platforms to declare which platforms it supports
32+ // ESLint Error: File must export __platforms to declare which platforms it supports. Example: export const __platforms = ['__universal__'];
33+
34+ // Not an array
35+ export const __platforms: Platform [] = ' browser' ;
36+ // ESLint Error: __platforms must be an array literal. Example: export const __platforms = ['browser', 'node'];
37+
38+ // Empty array
39+ export const __platforms: Platform [] = [];
40+ // ESLint Error: __platforms array cannot be empty. Specify at least one platform or use ['__universal__'].
41+
42+ // Using variables or computed values
43+ const myPlatform = ' browser' ;
44+ export const __platforms: Platform [] = [myPlatform ];
45+ // ESLint Error: __platforms must only contain string literals. Do NOT use variables, computed values, or spread operators.
46+
47+ // Invalid platform value
48+ export const __platforms: Platform [] = [' desktop' ];
49+ // ESLint Error: Invalid platform value "desktop". Valid platforms are: 'browser', 'node', 'react_native', '__universal__'
3850```
3951
4052## Configuration
4153
4254The rules are loaded via ` eslint-plugin-local-rules ` and configured in ` .eslintrc.js ` :
4355
44- ``` javascript
45- {
46- plugins: [' local-rules' ],
47- overrides: [{
48- files: [' *.ts' , ' !*.spec.ts' , ' !*.test.ts' ],
49- rules: {
50- ' local-rules/require-platform-declaration' : ' error'
51- }
52- }]
53- }
54- ```
55-
5656## Adding New Rules
5757
58581 . Create a new rule file in this directory (e.g., ` my-rule.js ` )
0 commit comments