@amazon-devices/eslint-plugin-kepler 0.1.8 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/README.md +139 -16
  2. package/dist/formatters/default.js +8 -189
  3. package/dist/formatters/default.js.LICENSE.txt +1 -0
  4. package/dist/index.js +1 -107
  5. package/package.json +1 -1
  6. package/dist/formatters/KeplerReport.js +0 -40
  7. package/dist/metrics/Metrics.js +0 -69
  8. package/dist/metrics/TelemetryService.js +0 -48
  9. package/dist/rules/apiPrivileges/ApiPrivilegeStateCheck.js +0 -102
  10. package/dist/rules/apiPrivileges/ApiPrivilegesCheck.js +0 -67
  11. package/dist/rules/apiPrivileges/apiPermissionsNeeded.js +0 -58
  12. package/dist/rules/apiPrivileges/manifestHelper.js +0 -44
  13. package/dist/rules/backwardCompatibility/BackwardCompatibility.js +0 -119
  14. package/dist/rules/backwardCompatibility/BackwardCompatibilityCopyOnPack.js +0 -101
  15. package/dist/rules/backwardCompatibility/BackwardCompatibilitySysconfCheck.js +0 -73
  16. package/dist/rules/performance/Animated.js +0 -64
  17. package/dist/rules/performance/CheckSubscription.js +0 -150
  18. package/dist/rules/performance/DetectSplashScreen.js +0 -62
  19. package/dist/rules/performance/DetectUseReportFullyDrawn.js +0 -50
  20. package/dist/rules/performance/FlatList.js +0 -39
  21. package/dist/rules/systemDistributedLibs/SDLPackageVersionCheck.js +0 -136
  22. package/dist/rules/systemDistributedLibs/SDLPackageVersionCheckImports.js +0 -58
  23. package/dist/rules/systemDistributedLibs/sdlHelpers.js +0 -232
  24. package/dist/rules/systemDistributedLibs/sdlRuleMessages.js +0 -25
  25. package/dist/state/KeplerESLintPluginStateManager.js +0 -94
  26. package/dist/utils/Constants.js +0 -40
  27. package/dist/utils/PackageUtils.js +0 -50
  28. package/dist/utils/RuleUtils.js +0 -128
package/README.md CHANGED
@@ -36,11 +36,12 @@ To use Vega ESLint Plugin, complete the below steps in your Vega App Project.
36
36
  ```
37
37
 
38
38
  Available configs:
39
- - `kepler` - All Kepler rules (performance + system distributed library checks + API privileges + backward compatibility)
39
+ - `kepler` - All Vega rules (performance + system distributed library checks + API privileges + backward compatibility + component migration)
40
40
  - `performance` - Performance-related rules only
41
41
  - `system-distributed-libs` - System distributed library checks (package.json validation and import informational flagging)
42
42
  - `api-privileges` - API privileges validation rules
43
- - `backward-compatibility` - Backward compatibility validation rules for Kepler library projects
43
+ - `backward-compatibility` - Backward compatibility validation rules for Vega library projects
44
+ - `vega-ui-components` - Component migration and best practices rules (e.g., deprecated Carousel detection)
44
45
 
45
46
  You can use multiple configs:
46
47
  ```javascript
@@ -50,7 +51,7 @@ To use Vega ESLint Plugin, complete the below steps in your Vega App Project.
50
51
  "plugin:@amazon-devices/eslint-plugin-kepler/performance",
51
52
  "plugin:@amazon-devices/eslint-plugin-kepler/system-distributed-libs",
52
53
  "plugin:@amazon-devices/eslint-plugin-kepler/api-privileges",
53
- "plugin:@amazon-devices/eslint-plugin-kepler/backward-compatibility"
54
+ "plugin:@amazon-devices/eslint-plugin-kepler/backward-compatibility",
54
55
  ],
55
56
  }
56
57
  ```
@@ -70,12 +71,15 @@ To use Vega ESLint Plugin, complete the below steps in your Vega App Project.
70
71
  extends: ["plugin:@amazon-devices/eslint-plugin-kepler/kepler"],
71
72
  rules: {
72
73
  "@amazon-devices/kepler/flat-list": "error",
74
+ "@amazon-devices/kepler/url-constructor-check": "warn",
73
75
  "@amazon-devices/kepler/sdl-package-version-check": "warn",
74
76
  "@amazon-devices/kepler/sdl-package-version-check-imports": "off",
77
+ "@amazon-devices/kepler/turbo-module-sdl-native-module-check": "error",
75
78
  "@amazon-devices/kepler/api-privileges-check": "error",
76
79
  "@amazon-devices/kepler/api-privilege-state-check": "error",
77
80
  "@amazon-devices/kepler/backward-compatibility": "error",
78
- "@amazon-devices/kepler/backward-compatibility-copy-on-pack": "error"
81
+ "@amazon-devices/kepler/backward-compatibility-copy-on-pack": "error",
82
+ "@amazon-devices/kepler/package-migration": "error",
79
83
  }
80
84
  }
81
85
  ```
@@ -89,7 +93,7 @@ To use Vega ESLint Plugin, complete the below steps in your Vega App Project.
89
93
  plugins: ["@amazon-devices/eslint-plugin-kepler"],
90
94
  rules: {
91
95
  "@amazon-devices/kepler/sdl-package-version-check": ["error", { "semverGuidance": "auto" }],
92
- "@amazon-devices/kepler/sdl-package-version-check-imports": ["warn", { "semverGuidance": "auto" }]
96
+ "@amazon-devices/kepler/sdl-package-version-check-imports": ["warn", { "semverGuidance": "auto" }],
93
97
  }
94
98
  }
95
99
  ```
@@ -188,7 +192,7 @@ To use Vega ESLint Plugin, complete the below steps in your Vega App Project.
188
192
 
189
193
  ## System Distributed Library Rules
190
194
 
191
- The plugin includes two rules for managing system distributed libraries:
195
+ The plugin includes rules for managing system distributed libraries:
192
196
 
193
197
  ### `@amazon-devices/kepler/sdl-package-version-check`
194
198
  Validates that SDL dependencies in `package.json` use proper semantic versioning:
@@ -199,22 +203,95 @@ Validates that SDL dependencies in `package.json` use proper semantic versioning
199
203
  ### `@amazon-devices/kepler/sdl-package-version-check-imports`
200
204
  Flags imports of system distributed libraries with informational messages to ensure developers understand the implications of using these libraries.
201
205
 
206
+ ### `@amazon-devices/kepler/turbo-module-sdl-native-module-check`
207
+ Validates that System Distributed Library (SDL) dependencies with native modules are properly declared in the `kepler-system-conf.toml` file for Turbo Modules:
208
+ - Checks that SDL packages are installed in `node_modules`
209
+ - Validates that SDL packages include required `kepler-compatibility.json` files
210
+ - Ensures native module dependencies are declared in `kepler-system-conf.toml`
211
+ - Verifies that installed SDL versions are supported by the compatibility configuration
212
+
213
+ **Example errors:**
214
+ ```
215
+ System Distributed Library (SDL) dependency '@amazon-devices/kepler-example' is not installed in node_modules. Run npm install to resolve.
216
+ ```
217
+ ```
218
+ System Distributed Library (SDL) dependency '@amazon-devices/kepler-example@1.0.0' requires native module 'ExampleNativeModule' to be declared in kepler-system-conf.toml
219
+ ```
220
+
202
221
  ## Backward Compatibility Rules
203
222
 
204
- The plugin includes rules for managing backward compatibility in Kepler library projects:
223
+ The plugin includes rules for managing backward compatibility in Vega library projects:
205
224
 
206
225
  ### `@amazon-devices/kepler/backward-compatibility`
207
- Validates that Kepler library projects have proper version compatibility configuration:
226
+ Validates that Vega library projects have proper version compatibility configuration:
208
227
  - Checks for the existence of `kepler-compatibility.json` file in the project root
209
228
  - Validates that the current package version is listed in the compatibility file
210
- - Only runs in Brazil repositories with SDL project configuration
229
+ - Only runs in repositories with SDL project configuration
211
230
 
212
231
  ### `@amazon-devices/kepler/backward-compatibility-copy-on-pack`
213
232
  Ensures that the `kepler-compatibility.json` file is included in npm packages:
214
233
  - Validates that `kepler-compatibility.json` is listed in the `files` array of `package.json`
215
- - Only runs in Brazil repositories with SDL project configuration
234
+ - Only runs in repositories with SDL project configuration
216
235
  - Required for proper version compatibility validation in published packages
217
236
 
237
+ ### `@amazon-devices/kepler/backward-compatibility-sysconf-check`
238
+ Validates that SDL library projects properly declare their native modules in the system configuration:
239
+ - Checks that `kepler-system-conf.toml` exists in SDL library projects
240
+ - Validates that the library's native modules are declared in the system configuration
241
+ - Ensures proper integration with the Vega system distributed library architecture
242
+ - Only runs in repositories with SDL project configuration
243
+
244
+ **Example error:**
245
+ ```
246
+ SDL library project must declare native module 'ExampleNativeModule' in kepler-system-conf.toml
247
+ ```
248
+
249
+ ## Component Migration Rules
250
+
251
+ The plugin includes rules for detecting deprecated component usage and suggesting migrations:
252
+
253
+ ### `@amazon-devices/kepler/carousel-deprecated`
254
+ Detects deprecated Carousel V1 usage from @amazon-devices/kepler-ui-components and suggests migration to @amazon-devices/vega-carousel. This rule helps identify code that needs to be updated for better performance and features.
255
+
256
+ **What it detects:**
257
+ - Carousel imports from `@amazon-devices/kepler-ui-components`
258
+ - Usage of deprecated props on Carousel components (from `@amazon-devices/kepler-ui-components`)
259
+
260
+ **Deprecated V1 props detected:**
261
+ - Props removed/replaced: `data`, `keyProvider`, `rowId`, `itemDimensions`, `getItemForIndex`, `selectionBorderStrategy`
262
+ - Props renamed: `maxToRenderPerBatch`, `hasTVPreferredFocus`, `trapFocusOnAxis`, `itemPadding`, `itemSelectionExpansion`, `itemScrollDelay`, `focusIndicatorType`, `pinnedFocusOffset`
263
+
264
+ **Example warnings:**
265
+ ```
266
+ Carousel imported from @amazon-devices/kepler-ui-components. Consider migrating to @amazon-devices/vega-carousel for better performance and features.
267
+ Carousel uses deprecated props (data, keyProvider). Consider migrating to @amazon-devices/vega-carousel.
268
+ ```
269
+
270
+ This rule provides the same detection capabilities as the Vega Studio Performance Extension's Carousel detection system, ensuring consistent warnings across different development environments.
271
+
272
+ ### `@amazon-devices/kepler/package-migration`
273
+ Validates that packages requiring migration to system distributed libraries are updated to newer versions:
274
+ - Checks specific packages that have been released as system distributed libraries
275
+ - Provides package version recommendations to make use of SDL released libs
276
+
277
+ ## URL Constructor Check Rule
278
+
279
+ The plugin includes a rule for managing URL polyfill usage in Kepler projects:
280
+
281
+ ### `@amazon-devices/kepler/url-constructor-check`
282
+ Flags usage of `react-native-url-polyfill` when it's no longer needed in Kepler versions > 2.0.0. Amazon has fixed the URL implementation issues in newer releases of React Native for Vega, making the polyfill unnecessary.
283
+
284
+ **Rule behavior:**
285
+ - Only activates when Kepler version > 2.0.0 AND `react-native-url-polyfill` is in dependencies
286
+ - Flags imports from `react-native-url-polyfill` package
287
+ - Flags usage of `new URL()` and `new URLSearchParams()` constructors
288
+ - Does nothing if Kepler <= 2.0.0 or polyfill is not a dependency
289
+
290
+ **Example error:**
291
+ ```
292
+ URL polyfill is not needed in this version of "@amazon-devices/react-native-kepler" as Amazon has fixed the issues with the stock React Native implementation.
293
+ ```
294
+
218
295
  ## API Privileges Rules
219
296
 
220
297
  The plugin includes two rules for validating API privilege requirements:
@@ -236,11 +313,57 @@ The rule checks imports of known privilege-requiring packages and ensures the co
236
313
  ### `@amazon-devices/kepler/api-privilege-state-check`
237
314
  Validates that APIs requiring user privilege prompts have proper SecurityManager implementation. Some APIs require explicit user consent through privilege request dialogs.
238
315
 
239
- **Requirements for APIs with user prompts:**
240
- - SecurityManager package dependency (`@amazon-devices/security-manager-lib` or `@amazon-devices/security-manager-lib`) in `package.json`
241
- - SecurityManager method calls (`SecurityManager.getPrivilegeState` and `SecurityManager.requestPrivilege`) in the codebase
242
-
243
316
  **Example error:**
244
317
  ```
245
- The API @amazon-devices/kepler-identifiers requires you prompt the user for privilige acceptance. See the Vega documentation for this API as well as for SecurityManager.
246
- ```
318
+ The API @amazon-devices/kepler-identifiers requires you prompt the user for privilege acceptance. See the Vega documentation for this API as well as for SecurityManager.
319
+ ```
320
+
321
+ ### `@amazon-devices/kepler/privilege-request-pattern-check`
322
+ Validates that APIs requiring user prompts properly handle both `PrivilegeState.ALLOW` and `PrivilegeState.DENY` cases when calling `SecurityManager.requestPrivilege()`. This rule ensures developers implement the complete privilege request pattern to prevent runtime errors and improve user experience.
323
+
324
+ **Supported patterns:**
325
+ - Promise chains with `.then()` callbacks
326
+ - Async/await with if/else or switch statements
327
+ - Nested conditionals and ternary operators
328
+
329
+ **Example of correct implementation (Promise chain):**
330
+ ```typescript
331
+ import { SecurityManager, PrivilegeState } from '@amazon-devices/kepler-security-manager';
332
+
333
+ SecurityManager.requestPrivilege('com.amazon.device-messaging.privilege.access')
334
+ .then((state) => {
335
+ if (state === PrivilegeState.ALLOW) {
336
+ // Handle permission granted
337
+ console.log('Permission granted');
338
+ } else if (state === PrivilegeState.DENY) {
339
+ // Handle permission denied
340
+ console.log('Permission denied');
341
+ }
342
+ });
343
+ ```
344
+
345
+ **Example of correct implementation (async/await):**
346
+ ```typescript
347
+ import { SecurityManager, PrivilegeState } from '@amazon-devices/kepler-security-manager';
348
+
349
+ const requestPermission = async () => {
350
+ const state = await SecurityManager.requestPrivilege('com.amazon.device-messaging.privilege.access');
351
+ if (state === PrivilegeState.ALLOW) {
352
+ // Handle permission granted
353
+ console.log('Permission granted');
354
+ } else if (state === PrivilegeState.DENY) {
355
+ // Handle permission denied
356
+ console.log('Permission denied');
357
+ }
358
+ };
359
+ ```
360
+
361
+ **Example errors:**
362
+ ```
363
+ API @amazon-devices/kepler-amazon-device-messaging requires proper privilege request pattern implementation. Your code is missing the DENY case handling for privilege 'com.amazon.device-messaging.privilege.access' in the Promise chain.
364
+ ```
365
+ ```
366
+ API @amazon-devices/kepler-amazon-device-messaging requires proper privilege request pattern implementation. Your code is missing the ALLOW and DENY case handling for privilege 'com.amazon.device-messaging.privilege.access' in the Promise chain.
367
+ ```
368
+
369
+ The rule automatically applies to APIs configured in `API_PRIV_NEEDED` with `requiresUserPrompt: true`, and provides detailed error messages with code examples and documentation links.