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

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 +198 -23
  2. package/dist/formatters/KeplerReport.js +40 -0
  3. package/dist/formatters/default.js +189 -8
  4. package/dist/index.js +107 -1
  5. package/dist/metrics/Metrics.js +69 -0
  6. package/dist/metrics/TelemetryService.js +48 -0
  7. package/dist/rules/apiPrivileges/ApiPrivilegeStateCheck.js +102 -0
  8. package/dist/rules/apiPrivileges/ApiPrivilegesCheck.js +67 -0
  9. package/dist/rules/apiPrivileges/apiPermissionsNeeded.js +58 -0
  10. package/dist/rules/apiPrivileges/manifestHelper.js +44 -0
  11. package/dist/rules/backwardCompatibility/BackwardCompatibility.js +119 -0
  12. package/dist/rules/backwardCompatibility/BackwardCompatibilityCopyOnPack.js +101 -0
  13. package/dist/rules/backwardCompatibility/BackwardCompatibilitySysconfCheck.js +73 -0
  14. package/dist/rules/performance/Animated.js +64 -0
  15. package/dist/rules/performance/CheckSubscription.js +150 -0
  16. package/dist/rules/performance/DetectSplashScreen.js +62 -0
  17. package/dist/rules/performance/DetectUseReportFullyDrawn.js +50 -0
  18. package/dist/rules/performance/FlatList.js +39 -0
  19. package/dist/rules/systemDistributedLibs/SDLPackageVersionCheck.js +136 -0
  20. package/dist/rules/systemDistributedLibs/SDLPackageVersionCheckImports.js +58 -0
  21. package/dist/rules/systemDistributedLibs/sdlHelpers.js +232 -0
  22. package/dist/rules/systemDistributedLibs/sdlRuleMessages.js +25 -0
  23. package/dist/state/KeplerESLintPluginStateManager.js +94 -0
  24. package/dist/utils/Constants.js +40 -0
  25. package/dist/utils/PackageUtils.js +50 -0
  26. package/dist/utils/RuleUtils.js +128 -0
  27. package/package.json +1 -1
  28. package/dist/formatters/default.js.LICENSE.txt +0 -1
package/README.md CHANGED
@@ -1,51 +1,137 @@
1
-
2
1
  # eslint-plugin-kepler
3
2
 
4
- An ESLint Plugin to suggest Kepler App Development best practices.
3
+ An ESLint Plugin to suggest Vega App Development best practices.
5
4
 
6
5
  ## Install
7
- 1. Make sure that you can access kepler NPM repo: See [Start installing SDK](https://developer.amazon.com/docs/kepler/install-kepler-sdk.html).
8
- 2. Add this package to `devDependencies` section of `package.json`:
6
+ 1. Add this package to `devDependencies` section of `package.json`:
9
7
 
10
- ```bash
11
- npm install --save-dev @amazon-devices/eslint-plugin-kepler
12
- ```
8
+ ```
9
+ npm install --save-dev @amazon-devices/eslint-plugin-kepler
10
+ ```
11
+
12
+ 2. For package.json validation (System Distributed Library rules), you must install the ESLint JSON parser:
13
+
14
+ ```
15
+ npm install --save-dev jsonc-eslint-parser
16
+ ```
17
+
18
+ You must also add the `package.json` to the `lint` command line in your `package.json` scripts as shown below.
19
+ ```
20
+ "lint": "eslint src test package.json --ext .ts,.tsx --format node_modules/@amazon-devices/eslint-plugin-kepler/dist/formatters/default.js"
21
+ ```
13
22
 
14
23
  ## Set up
15
24
 
16
- To use Kepler ESLint Plugin, complete the below steps in your Kepler App Project.
25
+ To use Vega ESLint Plugin, complete the below steps in your Vega App Project.
17
26
 
18
- 1. Configure Kepler rules in the App's eslint config
27
+ 1. Configure Vega rules in the App's eslint config
19
28
 
20
- KeplerESLintPlugin provides default configs that can be directly imported in App projects. To do so, add the following configuration in Kepler App's ESLint config file `.eslintrc.js`.
29
+ `eslint-plugin-kepler` provides default configs that can be directly imported in App projects. To do so, add the following configuration in Vega App's ESLint config file `.eslintrc.js`.
21
30
 
22
31
  ``` javascript
23
32
  module.exports = {
24
33
  plugins: ["@amazon-devices/eslint-plugin-kepler"],
25
- extends: ["plugin:@amazon-devices/eslint-plugin-kepler/performance"],
34
+ extends: ["plugin:@amazon-devices/eslint-plugin-kepler/kepler"],
26
35
  }
27
36
  ```
28
37
 
29
- You can also override severity of specific rules according do your use case like below
38
+ Available configs:
39
+ - `kepler` - All Kepler rules (performance + system distributed library checks + API privileges + backward compatibility)
40
+ - `performance` - Performance-related rules only
41
+ - `system-distributed-libs` - System distributed library checks (package.json validation and import informational flagging)
42
+ - `api-privileges` - API privileges validation rules
43
+ - `backward-compatibility` - Backward compatibility validation rules for Kepler library projects
44
+
45
+ You can use multiple configs:
30
46
  ```javascript
31
47
  module.exports = {
32
48
  plugins: ["@amazon-devices/eslint-plugin-kepler"],
33
- extends: ["plugin:@amazon-devices/eslint-plugin-kepler/performance"],
49
+ extends: [
50
+ "plugin:@amazon-devices/eslint-plugin-kepler/performance",
51
+ "plugin:@amazon-devices/eslint-plugin-kepler/system-distributed-libs",
52
+ "plugin:@amazon-devices/eslint-plugin-kepler/api-privileges",
53
+ "plugin:@amazon-devices/eslint-plugin-kepler/backward-compatibility"
54
+ ],
55
+ }
56
+ ```
57
+
58
+ Or use the comprehensive config:
59
+ ```javascript
60
+ module.exports = {
61
+ plugins: ["@amazon-devices/eslint-plugin-kepler"],
62
+ extends: ["plugin:@amazon-devices/eslint-plugin-kepler/kepler"],
63
+ }
64
+ ```
65
+
66
+ You can also override severity of specific rules:
67
+ ```javascript
68
+ module.exports = {
69
+ plugins: ["@amazon-devices/eslint-plugin-kepler"],
70
+ extends: ["plugin:@amazon-devices/eslint-plugin-kepler/kepler"],
34
71
  rules: {
35
72
  "@amazon-devices/kepler/flat-list": "error",
73
+ "@amazon-devices/kepler/sdl-package-version-check": "warn",
74
+ "@amazon-devices/kepler/sdl-package-version-check-imports": "off",
75
+ "@amazon-devices/kepler/api-privileges-check": "error",
76
+ "@amazon-devices/kepler/api-privilege-state-check": "error",
77
+ "@amazon-devices/kepler/backward-compatibility": "error",
78
+ "@amazon-devices/kepler/backward-compatibility-copy-on-pack": "error"
36
79
  }
37
80
  }
38
81
  ```
39
82
 
83
+ ### System Distributed Library Rules Configuration
84
+
85
+ The system distributed library rules support a `semverGuidance` configuration option:
86
+
87
+ ```javascript
88
+ module.exports = {
89
+ plugins: ["@amazon-devices/eslint-plugin-kepler"],
90
+ rules: {
91
+ "@amazon-devices/kepler/sdl-package-version-check": ["error", { "semverGuidance": "auto" }],
92
+ "@amazon-devices/kepler/sdl-package-version-check-imports": ["warn", { "semverGuidance": "auto" }]
93
+ }
94
+ }
95
+ ```
96
+
97
+ **`semverGuidance` Options:**
98
+ - `"patch"` - Conservative mode: Only allows patch updates (`~` prefix)
99
+ - `"minor"` - Allows minor updates (`^` prefix) in addition to patch
100
+ - `"auto"` (default) - Automatically detects mode based on signatures in the project repo
101
+
102
+ The rules for System Distributed Libraries require an ESLint JSON parser to parse the `package.json` and the addition of this parser to the `.eslintrc` (or `.eslintrc.json`). To install the parser (if you did not above):
103
+
104
+ ``` bash
105
+ npm install -D jsonc-eslint-parser
106
+ ```
107
+
108
+ Then, in your ESLint config file, add the JSON parser for `package.json`:
109
+
110
+ ``` javascript
111
+ overrides: [
112
+ {
113
+ files: ['**/*.ts', '**/*.tsx'],
114
+ parser: '@typescript-eslint/parser',
115
+ parserOptions: {
116
+ project: './tsconfig.json',
117
+ },
118
+ },
119
+ {
120
+ files: ['package.json'],
121
+ parser: 'jsonc-eslint-parser',
122
+ },
123
+ ]
124
+ ```
125
+
40
126
  2. Specify formatter on lint tasks:
41
127
  ```javascript
42
128
  "scripts": {
43
129
  :
44
- "lint": "eslint src test --ext .ts,.tsx --format node_modules/@amazon-devices/eslint-plugin-kepler/dist/formatters/default.js",
130
+ "lint": "eslint src test package.json --ext .ts,.tsx --format node_modules/@amazon-devices/eslint-plugin-kepler/dist/formatters/default.js",
45
131
  "lint:fix": "eslint src test --ext .ts,.tsx --fix --format node_modules/@amazon-devices/eslint-plugin-kepler/dist/formatters/default.js",
46
132
  ```
47
133
 
48
- 3. Run Kepler ESLint Plugin
134
+ 3. Run ESLint
49
135
 
50
136
  ```bash
51
137
  $ npm run lint
@@ -56,16 +142,105 @@ To use Kepler ESLint Plugin, complete the below steps in your Kepler App Project
56
142
  ```bash
57
143
  $ npm run lint
58
144
 
59
- > @amazon-devices/kepler-eslint-testapp@0.1.0 lint
145
+ > @amazon-devices/vega-sample-app@0.1.0 lint
60
146
  > eslint src test --ext .ts,.tsx --format node_modules/@amazon-devices/eslint-plugin-kepler/dist/formatters/default.js
61
-
62
-
63
- /Volumes/workspace/KeplerESLint/src/KeplerESLintTestApp/src/components/Link.tsx
64
- 32:5 ❌ 'useNativeDriver' property is set to 'false'. Set useNativeDriver to 'true' to run animations on UI thread for better performance. See https://developer.amazon.com/docs/kepler-tv/best_practices.html#animations for more. @amazon-devices/kepler/animated
65
- 43:5 ⚠️ Subscription must be kept in variable so that it can be cleaned up on the component is detached. See https://developer.amazon.com/docs/kepler-tv/best_practices.html#listeners-event-subscriptions-and-timers for more. @amazon-devices/kepler/check-subscription
66
- 64:11 ⚠️ FlatList missing props: 'initialNumToRender,windowSize,removeClippedSubviews,maxToRenderPerBatch,updateCellsBatchingPeriod'. FlatList performance is not fully unlocked without these props. See https://developer.amazon.com/docs/kepler-tv/best_practices.html#flatlist for more. @amazon-devices/kepler/flat-list
147
+
148
+ /Volumes/workspace/VegaSampleApp/src/components/Link.tsx
149
+ 32:5 ❌ 'useNativeDriver' property is set to 'false'. Set useNativeDriver to 'true' to run animations on UI thread for better performance. See https://developer.amazon.com/docs/vega/0.21/best_practices.html#the-animated-library for more. @amazon-devices/kepler/animated
150
+ 43:5 ⚠️ Subscription must be kept in variable so that it can be cleaned up on the component is detached. See https://developer.amazon.com/docs/vega/0.21/best_practices.html#listeners-event-subscriptions-and-timers for more. @amazon-devices/kepler/check-subscription
151
+ 64:11 ⚠️ FlatList missing props: 'initialNumToRender,windowSize,removeClippedSubviews,maxToRenderPerBatch,updateCellsBatchingPeriod'. FlatList performance is not fully unlocked without these props. See https://developer.amazon.com/docs/vega/0.21/best_practices.html#flatlist for more. @amazon-devices/kepler/flat-list
152
+
153
+ ⚠️ useReportFullyDrawn() call not found in project. Add useReportFullyDrawn() in your App to accurately measure Time To Fully Drawn (TTFD) KPI. See https://developer.amazon.com/docs/vega/0.21/measure-app-kpis.html#fully-drawn-marker for more. @amazon-devices/kepler/detect-report-fully-drawn
154
+
155
+ ⚠️ usePreventHideSplashScreen() call not found in project. Use usePreventHideSplashScreen() to natively render SplashScreen for better App launch performance. See https://developer.amazon.com/docs/react-native-vega/0.72/splashscreenmanager.html for more. @amazon-devices/kepler/detect-splash-screen
156
+
157
+ Summary:
158
+ ❌ 1 error(s)
159
+ ⚠️ 4 warning(s)
160
+
161
+ Vega ESLint HTML report generated at: /Volumes/workspace/VegaSampleApp/generated/eslint-plugin-kepler/vega-eslint-report.html
67
162
  ```
68
163
 
69
- 4. Kepler ESLint Plugin generated warnings will show in VS Code Editor when [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) is installed.
164
+ 4. Vega ESLint Plugin generated warnings will show in VS Code Editor when [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) is installed.
70
165
 
71
166
  ![](./assets/checkSubscription.png)
167
+
168
+ 5. Seeing errors and warnings in VSCode in the `package.json` requires an additional configuration step. In the VSCode `settings.json` file you will need to add `json` to the following entries, as shown:
169
+
170
+ ``` javascript
171
+ "eslint.validate": [
172
+ "javascript",
173
+ "javascriptreact",
174
+ "typescript",
175
+ "typescriptreact",
176
+ // add the line below
177
+ "json"
178
+ ],
179
+ "eslint.probe": [
180
+ "javascript",
181
+ "javascriptreact",
182
+ "typescript",
183
+ "typescriptreact",
184
+ // add the line below
185
+ "json"
186
+ ],
187
+ ```
188
+
189
+ ## System Distributed Library Rules
190
+
191
+ The plugin includes two rules for managing system distributed libraries:
192
+
193
+ ### `@amazon-devices/kepler/sdl-package-version-check`
194
+ Validates that SDL dependencies in `package.json` use proper semantic versioning:
195
+ - **Patch only mode** (`semverGuidance: "patch"`): Only allows patch updates using `~` prefix.
196
+ - **Minor and patch mode** (`semverGuidance: "minor"`): Allows minor updates using `^` prefix.
197
+ - **Auto mode** (`semverGuidance: "auto"`): Automatically detects based on signatures in the project repo. This is the default.
198
+
199
+ ### `@amazon-devices/kepler/sdl-package-version-check-imports`
200
+ Flags imports of system distributed libraries with informational messages to ensure developers understand the implications of using these libraries.
201
+
202
+ ## Backward Compatibility Rules
203
+
204
+ The plugin includes rules for managing backward compatibility in Kepler library projects:
205
+
206
+ ### `@amazon-devices/kepler/backward-compatibility`
207
+ Validates that Kepler library projects have proper version compatibility configuration:
208
+ - Checks for the existence of `kepler-compatibility.json` file in the project root
209
+ - Validates that the current package version is listed in the compatibility file
210
+ - Only runs in Brazil repositories with SDL project configuration
211
+
212
+ ### `@amazon-devices/kepler/backward-compatibility-copy-on-pack`
213
+ Ensures that the `kepler-compatibility.json` file is included in npm packages:
214
+ - Validates that `kepler-compatibility.json` is listed in the `files` array of `package.json`
215
+ - Only runs in Brazil repositories with SDL project configuration
216
+ - Required for proper version compatibility validation in published packages
217
+
218
+ ## API Privileges Rules
219
+
220
+ The plugin includes two rules for validating API privilege requirements:
221
+
222
+ ### `@amazon-devices/kepler/api-privileges-check`
223
+ Validates that APIs requiring permissions have the proper entries in the Vega `manifest.toml` file. Some Vega APIs require specific privileges to be declared in the manifest for the app to function correctly.
224
+
225
+ **Supported privilege types:**
226
+ - `[[needs.privilege]]` - Required privileges that must be present
227
+ - `[[wants.privilege]]` - Optional privileges that should be present
228
+
229
+ **Example error:**
230
+ ```
231
+ Using the APIs in @amazon-devices/kepler-amazon-device-messaging requires the [[needs.privilege]] id="com.amazon.device-messaging.privilege.access" entry in the Vega manifest.toml.
232
+ ```
233
+
234
+ The rule checks imports of known privilege-requiring packages and ensures the corresponding privilege entries exist in your project's `manifest.toml` file.
235
+
236
+ ### `@amazon-devices/kepler/api-privilege-state-check`
237
+ Validates that APIs requiring user privilege prompts have proper SecurityManager implementation. Some APIs require explicit user consent through privilege request dialogs.
238
+
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
+ **Example error:**
244
+ ```
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
+ ```
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.exportHTMLReport = exportHTMLReport;
7
+ var _eslint = require("eslint");
8
+ var fs = _interopRequireWildcard(require("fs"));
9
+ var path = _interopRequireWildcard(require("path"));
10
+ var _Constants = require("../utils/Constants");
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ // Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
13
+ // AMAZON PROPRIETARY/CONFIDENTIAL
14
+ // You may not use this file except in compliance with the terms and conditions
15
+ // set forth in the accompanying LICENSE.TXT file.
16
+ // THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
17
+ // DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
18
+ // IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
20
+
21
+ const KEPLER_ESLINT_HTML_REPORT_FILE_NAME = path.join(_Constants.KEPLER_ESLINT_OUTPUT_DIR_PATH, 'vega-eslint-report.html');
22
+
23
+ /**
24
+ * Exports ESLint results to HTML file.
25
+ * @param results
26
+ */
27
+ async function exportHTMLReport(results, outputPath = KEPLER_ESLINT_HTML_REPORT_FILE_NAME) {
28
+ try {
29
+ const eslint = new _eslint.ESLint();
30
+ const htmlFormatter = await eslint.loadFormatter('html');
31
+ const output = htmlFormatter.format(results);
32
+ if (!output) {
33
+ throw new Error('No Results to write');
34
+ }
35
+ fs.writeFileSync(outputPath, output, 'utf8');
36
+ return outputPath;
37
+ } catch (error) {
38
+ throw error;
39
+ }
40
+ }