Skip to content

Commit 99f710b

Browse files
committed
lint doc updates
1 parent 246a9e9 commit 99f710b

File tree

3 files changed

+59
-25
lines changed

3 files changed

+59
-25
lines changed

eslint-local-rules/README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4254
The 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

5858
1. Create a new rule file in this directory (e.g., `my-rule.js`)

eslint-local-rules/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2025, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
/**
218
* Local ESLint Rules
319
*

eslint-local-rules/require-platform-declaration.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/**
2+
* Copyright 2025, Optimizely
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
/**
218
* ESLint Rule: require-platform-declaration
319
*
@@ -17,6 +33,8 @@
1733
* // Not exported as const array
1834
*/
1935

36+
/* eslint-disable @typescript-eslint/no-var-requires */
37+
2038
const { getValidPlatforms } = require('../scripts/platform-utils');
2139

2240
module.exports = {

0 commit comments

Comments
 (0)