@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.
- package/README.md +139 -16
- package/dist/formatters/default.js +8 -189
- package/dist/formatters/default.js.LICENSE.txt +1 -0
- package/dist/index.js +1 -107
- package/package.json +1 -1
- package/dist/formatters/KeplerReport.js +0 -40
- package/dist/metrics/Metrics.js +0 -69
- package/dist/metrics/TelemetryService.js +0 -48
- package/dist/rules/apiPrivileges/ApiPrivilegeStateCheck.js +0 -102
- package/dist/rules/apiPrivileges/ApiPrivilegesCheck.js +0 -67
- package/dist/rules/apiPrivileges/apiPermissionsNeeded.js +0 -58
- package/dist/rules/apiPrivileges/manifestHelper.js +0 -44
- package/dist/rules/backwardCompatibility/BackwardCompatibility.js +0 -119
- package/dist/rules/backwardCompatibility/BackwardCompatibilityCopyOnPack.js +0 -101
- package/dist/rules/backwardCompatibility/BackwardCompatibilitySysconfCheck.js +0 -73
- package/dist/rules/performance/Animated.js +0 -64
- package/dist/rules/performance/CheckSubscription.js +0 -150
- package/dist/rules/performance/DetectSplashScreen.js +0 -62
- package/dist/rules/performance/DetectUseReportFullyDrawn.js +0 -50
- package/dist/rules/performance/FlatList.js +0 -39
- package/dist/rules/systemDistributedLibs/SDLPackageVersionCheck.js +0 -136
- package/dist/rules/systemDistributedLibs/SDLPackageVersionCheckImports.js +0 -58
- package/dist/rules/systemDistributedLibs/sdlHelpers.js +0 -232
- package/dist/rules/systemDistributedLibs/sdlRuleMessages.js +0 -25
- package/dist/state/KeplerESLintPluginStateManager.js +0 -94
- package/dist/utils/Constants.js +0 -40
- package/dist/utils/PackageUtils.js +0 -50
- package/dist/utils/RuleUtils.js +0 -128
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.CheckSubscription = void 0;
|
|
7
|
-
var _Constants = require("../../utils/Constants");
|
|
8
|
-
// Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
9
|
-
// AMAZON PROPRIETARY/CONFIDENTIAL
|
|
10
|
-
// You may not use this file except in compliance with the terms and conditions
|
|
11
|
-
// set forth in the accompanying LICENSE.TXT file.
|
|
12
|
-
// THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
|
|
13
|
-
// DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
|
|
14
|
-
// IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
16
|
-
|
|
17
|
-
const moreUrlMessage = `See ${_Constants.VEGA_BEST_PRACTICE_URL}#listeners-event-subscriptions-and-timers for more.`;
|
|
18
|
-
const CheckSubscription = exports.CheckSubscription = {
|
|
19
|
-
meta: {
|
|
20
|
-
type: 'suggestion',
|
|
21
|
-
docs: {
|
|
22
|
-
description: 'Checks if subscriptions are set to be cleaned up',
|
|
23
|
-
recommended: true,
|
|
24
|
-
category: 'Performance'
|
|
25
|
-
},
|
|
26
|
-
fixable: 'code',
|
|
27
|
-
schema: [],
|
|
28
|
-
messages: {
|
|
29
|
-
failedToKeepSubscription: `Subscription must be kept in variable so that it can be cleaned up on the component is detached. ${moreUrlMessage}`,
|
|
30
|
-
missingCleanUp: `Subscription \`{{varName}}\` is not cleaned up. ${moreUrlMessage}`
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
create(context) {
|
|
34
|
-
const addListenerFuncs = new Set();
|
|
35
|
-
const subscriptionVars = new Set();
|
|
36
|
-
const subscriptionCollections = new Set();
|
|
37
|
-
const stateManagerVars = new Set();
|
|
38
|
-
|
|
39
|
-
// Return true if the given node is a call to adding a listener.
|
|
40
|
-
// Ex. `addInputListener(..)` or `appStateManager.addAppStateListener(...)`
|
|
41
|
-
function isExpressionToAddListener(node) {
|
|
42
|
-
if (node.callee.type === 'Identifier') {
|
|
43
|
-
return addListenerFuncs.has(node.callee.name);
|
|
44
|
-
}
|
|
45
|
-
if (node.callee.type === 'MemberExpression') {
|
|
46
|
-
if (node.callee.object.type === 'Identifier' && stateManagerVars.has(node.callee.object.name) && node.callee.property.type === 'Identifier' && node.callee.property.name === 'addAppStateListener') {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
// Collect variables containing functions to add listener.
|
|
54
|
-
// Ex. `const ${var} = useAddKeplerAppStateListenerCallback()`
|
|
55
|
-
'VariableDeclarator[init.callee.name = /^useAdd(KeplerAppState|UserInput)ListenerCallback$/]': node => {
|
|
56
|
-
if (node.id.type === 'Identifier') {
|
|
57
|
-
const varName = node.id.name;
|
|
58
|
-
addListenerFuncs.add(varName);
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
// Collect variables containing AppStateManager.
|
|
62
|
-
// Ex. `const ${varName} = useKeplerAppStateManager()`
|
|
63
|
-
'VariableDeclarator[init.callee.name = /^useKeplerAppStateManager$/]': node => {
|
|
64
|
-
if (node.id.type === 'Identifier') {
|
|
65
|
-
const varName = node.id.name;
|
|
66
|
-
stateManagerVars.add(varName);
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
// Check the code adding listeners and collect variables containing subscriptions.
|
|
70
|
-
// Warn code like `useEffect(() => {...; ${addListenerFunc}(....); ...}`
|
|
71
|
-
// Collect vars like `useEffect(() => {...; ${subscriptionVar} = ${addListenerFunc}(....); ...}`
|
|
72
|
-
// or `useEffect(() => {...; ${subscriptionCollection}.push(${addListenerFunc}(....)); ...}`
|
|
73
|
-
"CallExpression[callee.name='useEffect'] :function CallExpression": node => {
|
|
74
|
-
if (isExpressionToAddListener(node)) {
|
|
75
|
-
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
76
|
-
const ancestors = sourceCode.getAncestors?.(node) ?? context.getAncestors();
|
|
77
|
-
if (ancestors.length >= 1) {
|
|
78
|
-
const parent = ancestors[ancestors.length - 1];
|
|
79
|
-
if (parent.type === 'VariableDeclarator' && parent.id.type == 'Identifier') {
|
|
80
|
-
// [const|let|var] ${var} = ${addListenerFunc}(....)
|
|
81
|
-
subscriptionVars.add(parent.id.name);
|
|
82
|
-
return;
|
|
83
|
-
} else if (parent.type === 'AssignmentExpression' && parent.left.type == 'Identifier') {
|
|
84
|
-
// ${var} = ${addListenerFunc}(....)
|
|
85
|
-
subscriptionVars.add(parent.left.name);
|
|
86
|
-
return;
|
|
87
|
-
} else if (parent.type === 'CallExpression' && parent.arguments[0] === node && parent.callee.type === 'MemberExpression') {
|
|
88
|
-
const callee = parent.callee;
|
|
89
|
-
if (
|
|
90
|
-
// ${collection}.[add|push](${addListenerFunc}(....));
|
|
91
|
-
callee.property.type === 'Identifier' && ['add', 'push'].includes(callee.property.name) && callee.object.type === 'Identifier') {
|
|
92
|
-
subscriptionCollections.add(callee.object.name);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
context.report({
|
|
98
|
-
node: node,
|
|
99
|
-
messageId: 'failedToKeepSubscription'
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
},
|
|
103
|
-
// Remove subscription vars that are cleaned up in a function returned by the effect function.
|
|
104
|
-
// Ex. `useEffect(() => {...; return () => ${subscriptionVar}.remove()});`
|
|
105
|
-
"CallExpression[callee.name='useEffect'] :function ReturnStatement CallExpression[callee.property.name='remove']": removeCall => {
|
|
106
|
-
if (removeCall.callee.type === 'MemberExpression') {
|
|
107
|
-
const callee = removeCall.callee;
|
|
108
|
-
if (callee.object.type === 'Identifier' && subscriptionVars.has(callee.object.name)) {
|
|
109
|
-
subscriptionVars.delete(callee.object.name);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
// Remove subscription collections that are cleaned up in a function returned by the effect function.
|
|
114
|
-
// Ex. `useEffect(() => {...; return () => ${subscriptionCollection}.forEach(s => s.remove())});`
|
|
115
|
-
"CallExpression[callee.name='useEffect'] :function ReturnStatement CallExpression[callee.property.name='forEach']": forEachCall => {
|
|
116
|
-
if (forEachCall.callee.type === 'MemberExpression') {
|
|
117
|
-
const callee = forEachCall.callee;
|
|
118
|
-
if (callee.object.type === 'Identifier' && subscriptionCollections.has(callee.object.name)) {
|
|
119
|
-
// Though it would be more precise to check if each subscription is removed in the function passed to `forEach`,
|
|
120
|
-
// it's overkill. Let's accept false-negative by now.
|
|
121
|
-
subscriptionCollections.delete(callee.object.name);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
// Report all subscription vars and collections that are not removed at the exit of `useEffect` call
|
|
126
|
-
"CallExpression[callee.name='useEffect']:exit": node => {
|
|
127
|
-
for (const varName of subscriptionVars) {
|
|
128
|
-
context.report({
|
|
129
|
-
node,
|
|
130
|
-
messageId: 'missingCleanUp',
|
|
131
|
-
data: {
|
|
132
|
-
varName
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
for (const varName of subscriptionCollections) {
|
|
137
|
-
context.report({
|
|
138
|
-
node,
|
|
139
|
-
messageId: 'missingCleanUp',
|
|
140
|
-
data: {
|
|
141
|
-
varName
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
subscriptionVars.clear();
|
|
146
|
-
subscriptionCollections.clear();
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DetectSplashScreen = void 0;
|
|
7
|
-
var _KeplerESLintPluginStateManager = require("../../state/KeplerESLintPluginStateManager");
|
|
8
|
-
var _RuleUtils = require("../../utils/RuleUtils");
|
|
9
|
-
// Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
10
|
-
// AMAZON PROPRIETARY/CONFIDENTIAL
|
|
11
|
-
// You may not use this file except in compliance with the terms and conditions
|
|
12
|
-
// set forth in the accompanying LICENSE.TXT file.
|
|
13
|
-
// THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
|
|
14
|
-
// DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
|
|
15
|
-
// IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
// FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
17
|
-
|
|
18
|
-
const USE_PREVENT_HIDE_SPLASH_SCREEN = 'usePreventHideSplashScreen';
|
|
19
|
-
const USE_HIDE_SPLASH_SCREEN_CALLBACK = 'useHideSplashScreenCallback';
|
|
20
|
-
const DetectSplashScreen = exports.DetectSplashScreen = {
|
|
21
|
-
meta: {
|
|
22
|
-
type: 'suggestion',
|
|
23
|
-
docs: {
|
|
24
|
-
description: 'usePreventHideSplashScreen() should be used to natively render splash screen, for better App launch performance',
|
|
25
|
-
recommended: true,
|
|
26
|
-
category: 'Performance'
|
|
27
|
-
},
|
|
28
|
-
fixable: 'code',
|
|
29
|
-
schema: []
|
|
30
|
-
},
|
|
31
|
-
create(context) {
|
|
32
|
-
const usePreventHideSplashScreenAliases = new Set();
|
|
33
|
-
const useHideSplashScreenCallbackAliases = new Set();
|
|
34
|
-
return {
|
|
35
|
-
VariableDeclarator(node) {
|
|
36
|
-
// Check usePreventHideSplashScreen()
|
|
37
|
-
if ((0, _RuleUtils.isFunctionAssignedToVariable)(node, USE_PREVENT_HIDE_SPLASH_SCREEN) || (0, _RuleUtils.isModuleFunctionAssignedToVariable)(node, USE_PREVENT_HIDE_SPLASH_SCREEN)) {
|
|
38
|
-
usePreventHideSplashScreenAliases.add(node.id['name']);
|
|
39
|
-
}
|
|
40
|
-
// Check useHideSplashScreenCallback()
|
|
41
|
-
else if ((0, _RuleUtils.isFunctionAssignedToVariable)(node, USE_HIDE_SPLASH_SCREEN_CALLBACK) || (0, _RuleUtils.isModuleFunctionAssignedToVariable)(node, USE_HIDE_SPLASH_SCREEN_CALLBACK)) {
|
|
42
|
-
useHideSplashScreenCallbackAliases.add(node.id['name']);
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
CallExpression(node) {
|
|
46
|
-
// Check usePreventHideSplashScreen()
|
|
47
|
-
if ((0, _RuleUtils.isDirectCall)(node, USE_PREVENT_HIDE_SPLASH_SCREEN) || (0, _RuleUtils.isAliasCall)(node, USE_PREVENT_HIDE_SPLASH_SCREEN, usePreventHideSplashScreenAliases) || (0, _RuleUtils.isNamespacedCall)(node, USE_PREVENT_HIDE_SPLASH_SCREEN)) {
|
|
48
|
-
const keplerESLintState = _KeplerESLintPluginStateManager.KeplerESLintPluginStateManager.getInstance().getKeplerESLintState();
|
|
49
|
-
keplerESLintState.splashScreen.usePreventHideSplashScreenFound = true;
|
|
50
|
-
_KeplerESLintPluginStateManager.KeplerESLintPluginStateManager.getInstance().setKeplerESLintState(keplerESLintState);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Check useHideSplashScreenCallback()
|
|
54
|
-
else if ((0, _RuleUtils.isDirectCall)(node, USE_HIDE_SPLASH_SCREEN_CALLBACK) || (0, _RuleUtils.isAliasCall)(node, USE_HIDE_SPLASH_SCREEN_CALLBACK, useHideSplashScreenCallbackAliases) || (0, _RuleUtils.isNamespacedCall)(node, USE_HIDE_SPLASH_SCREEN_CALLBACK)) {
|
|
55
|
-
const keplerESLintState = _KeplerESLintPluginStateManager.KeplerESLintPluginStateManager.getInstance().getKeplerESLintState();
|
|
56
|
-
keplerESLintState.splashScreen.useHideSplashScreenCallbackFound = true;
|
|
57
|
-
_KeplerESLintPluginStateManager.KeplerESLintPluginStateManager.getInstance().setKeplerESLintState(keplerESLintState);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.DetectUseReportFullyDrawn = void 0;
|
|
7
|
-
var _KeplerESLintPluginStateManager = require("../../state/KeplerESLintPluginStateManager");
|
|
8
|
-
var _RuleUtils = require("../../utils/RuleUtils");
|
|
9
|
-
// Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
10
|
-
// AMAZON PROPRIETARY/CONFIDENTIAL
|
|
11
|
-
// You may not use this file except in compliance with the terms and conditions
|
|
12
|
-
// set forth in the accompanying LICENSE.TXT file.
|
|
13
|
-
// THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
|
|
14
|
-
// DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
|
|
15
|
-
// IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
// FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
17
|
-
|
|
18
|
-
const USE_REPORT_FULLY_DRAWN_FUNCTION_NAME = 'useReportFullyDrawn';
|
|
19
|
-
const DetectUseReportFullyDrawn = exports.DetectUseReportFullyDrawn = {
|
|
20
|
-
meta: {
|
|
21
|
-
type: 'suggestion',
|
|
22
|
-
docs: {
|
|
23
|
-
description: 'useReportFullyDrawn() callback should be used to measure Time to Fully Drawn',
|
|
24
|
-
recommended: true,
|
|
25
|
-
category: 'Performance'
|
|
26
|
-
},
|
|
27
|
-
fixable: 'code',
|
|
28
|
-
schema: []
|
|
29
|
-
},
|
|
30
|
-
create(context) {
|
|
31
|
-
const useReportFullyDrawnAliases = new Set();
|
|
32
|
-
return {
|
|
33
|
-
VariableDeclarator(node) {
|
|
34
|
-
if ((0, _RuleUtils.isFunctionAssignedToVariable)(node, USE_REPORT_FULLY_DRAWN_FUNCTION_NAME)) {
|
|
35
|
-
useReportFullyDrawnAliases.add(node.id['name']);
|
|
36
|
-
}
|
|
37
|
-
if ((0, _RuleUtils.isModuleFunctionAssignedToVariable)(node, USE_REPORT_FULLY_DRAWN_FUNCTION_NAME)) {
|
|
38
|
-
useReportFullyDrawnAliases.add(node.id['name']);
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
CallExpression(node) {
|
|
42
|
-
if ((0, _RuleUtils.isDirectCall)(node, USE_REPORT_FULLY_DRAWN_FUNCTION_NAME) || (0, _RuleUtils.isAliasCall)(node, USE_REPORT_FULLY_DRAWN_FUNCTION_NAME, useReportFullyDrawnAliases) || (0, _RuleUtils.isNamespacedCall)(node, USE_REPORT_FULLY_DRAWN_FUNCTION_NAME)) {
|
|
43
|
-
const keplerESLintState = _KeplerESLintPluginStateManager.KeplerESLintPluginStateManager.getInstance().getKeplerESLintState();
|
|
44
|
-
keplerESLintState.fullyDrawn.useReportFullyDrawnFound = true;
|
|
45
|
-
_KeplerESLintPluginStateManager.KeplerESLintPluginStateManager.getInstance().setKeplerESLintState(keplerESLintState);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.FlatList = void 0;
|
|
7
|
-
var _Constants = require("../../utils/Constants");
|
|
8
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
9
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
|
-
|
|
11
|
-
const FLATLIST_PERF_REQD_PROPS = ['initialNumToRender', 'windowSize', 'removeClippedSubviews', 'maxToRenderPerBatch', 'updateCellsBatchingPeriod'];
|
|
12
|
-
const FlatList = exports.FlatList = {
|
|
13
|
-
meta: {
|
|
14
|
-
type: 'suggestion',
|
|
15
|
-
docs: {
|
|
16
|
-
description: 'FlatList causes performance overhead and should be used carefully',
|
|
17
|
-
recommended: true,
|
|
18
|
-
category: 'Performance'
|
|
19
|
-
},
|
|
20
|
-
fixable: 'code',
|
|
21
|
-
schema: []
|
|
22
|
-
},
|
|
23
|
-
create(context) {
|
|
24
|
-
return {
|
|
25
|
-
JSXOpeningElement(node) {
|
|
26
|
-
if (node.name.name === 'FlatList') {
|
|
27
|
-
const currentFlatListPropNames = node.attributes.map(attr => attr.name.name);
|
|
28
|
-
const missingProps = FLATLIST_PERF_REQD_PROPS.filter(prop => !currentFlatListPropNames.includes(prop));
|
|
29
|
-
if (missingProps.length > 0) {
|
|
30
|
-
context.report({
|
|
31
|
-
node,
|
|
32
|
-
message: `FlatList missing props: '${missingProps}'. FlatList performance is not fully unlocked without these props. ` + `See ${_Constants.VEGA_BEST_PRACTICE_URL}#flatlist for more.`
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
};
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SDLPackageVersionCheck = void 0;
|
|
7
|
-
var _sdlHelpers = require("./sdlHelpers");
|
|
8
|
-
var _sdlRuleMessages = require("./sdlRuleMessages");
|
|
9
|
-
// Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
10
|
-
// AMAZON PROPRIETARY/CONFIDENTIAL
|
|
11
|
-
// You may not use this file except in compliance with the terms and conditions
|
|
12
|
-
// set forth in the accompanying LICENSE.TXT file.
|
|
13
|
-
// THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
|
|
14
|
-
// DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
|
|
15
|
-
// IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
// FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
17
|
-
|
|
18
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */ // ESLint Rule API uses complex inferred types
|
|
19
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */ // AST node types are complex, using any for simplicity
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* ESLint rule to validate SDL package versions in package.json
|
|
23
|
-
*/
|
|
24
|
-
const SDLPackageVersionCheck = exports.SDLPackageVersionCheck = {
|
|
25
|
-
meta: {
|
|
26
|
-
type: 'problem',
|
|
27
|
-
docs: {
|
|
28
|
-
description: 'Validates that SDL dependencies use proper semantic versioning with ~ or < prefixes',
|
|
29
|
-
recommended: true,
|
|
30
|
-
category: 'System Distributed Libraries'
|
|
31
|
-
},
|
|
32
|
-
schema: [{
|
|
33
|
-
type: 'object',
|
|
34
|
-
properties: {
|
|
35
|
-
semverGuidance: {
|
|
36
|
-
oneOf: [{
|
|
37
|
-
type: 'string',
|
|
38
|
-
enum: ['minor', 'patch', 'auto']
|
|
39
|
-
}]
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
additionalProperties: false
|
|
43
|
-
}]
|
|
44
|
-
},
|
|
45
|
-
create(context) {
|
|
46
|
-
const options = context.options[0] || {};
|
|
47
|
-
const isMinorUpgradeMode = (0, _sdlHelpers.determineMinorUpdateMode)(options.semverGuidance);
|
|
48
|
-
return {
|
|
49
|
-
JSONProperty(node) {
|
|
50
|
-
// Only check properties in dependencies and peerDependencies
|
|
51
|
-
const parent = node.parent;
|
|
52
|
-
if (parent?.type === 'JSONObjectExpression' && parent.parent?.type === 'JSONProperty') {
|
|
53
|
-
const grandParent = parent.parent;
|
|
54
|
-
if (grandParent.key?.type === 'JSONLiteral') {
|
|
55
|
-
const sectionName = grandParent.key.value;
|
|
56
|
-
if (['dependencies', 'peerDependencies'].includes(sectionName)) {
|
|
57
|
-
// Check if this property is an SDL package
|
|
58
|
-
if (node.key?.type === 'JSONLiteral' && node.value?.type === 'JSONLiteral') {
|
|
59
|
-
const packageName = node.key.value;
|
|
60
|
-
const version = node.value.value;
|
|
61
|
-
const isSDLPackage = (0, _sdlHelpers.isSystemDistributedLibrary)(packageName);
|
|
62
|
-
if (isSDLPackage && typeof version === 'string') {
|
|
63
|
-
// Check for greater-than operators (error in both modes)
|
|
64
|
-
if ((0, _sdlHelpers.hasGreaterThanOperators)(version)) {
|
|
65
|
-
context.report({
|
|
66
|
-
node: node.value,
|
|
67
|
-
message: _sdlRuleMessages.GREATER_THAN_VERSION_ERROR
|
|
68
|
-
});
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Check for wildcards - but allow patch-only wildcards like "2.0.x"
|
|
73
|
-
if ((0, _sdlHelpers.hasWildcards)(version)) {
|
|
74
|
-
// If it's a patch-only wildcard, it's allowed in conservative mode
|
|
75
|
-
if (!(0, _sdlHelpers.allowsPatchUpgrades)(version)) {
|
|
76
|
-
if (isMinorUpgradeMode) {
|
|
77
|
-
context.report({
|
|
78
|
-
node: node.value,
|
|
79
|
-
message: _sdlRuleMessages.MINOR_UPGRADE_MODE_WILDCARD_WARNING
|
|
80
|
-
});
|
|
81
|
-
} else {
|
|
82
|
-
context.report({
|
|
83
|
-
node: node.value,
|
|
84
|
-
message: _sdlRuleMessages.WILDCARD_VERSION_ERROR
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Check for locked versions or partial ranges (flagged in both modes)
|
|
92
|
-
if ((0, _sdlHelpers.isLockedOrPartialRange)(version)) {
|
|
93
|
-
if (isMinorUpgradeMode) {
|
|
94
|
-
context.report({
|
|
95
|
-
node: node.value,
|
|
96
|
-
message: _sdlRuleMessages.MINOR_UPGRADE_MODE_LOCKED_VERSION_WARNING
|
|
97
|
-
});
|
|
98
|
-
} else {
|
|
99
|
-
context.report({
|
|
100
|
-
node: node.value,
|
|
101
|
-
message: _sdlRuleMessages.LOCKED_VERSION_WARNING
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (isMinorUpgradeMode) {
|
|
107
|
-
// Pre-release mode: flag major upgrades or prohibiting minor upgrades
|
|
108
|
-
if ((0, _sdlHelpers.allowsMajorUpgrades)(version)) {
|
|
109
|
-
context.report({
|
|
110
|
-
node: node.value,
|
|
111
|
-
message: _sdlRuleMessages.MAJOR_UPGRADE_WARNING
|
|
112
|
-
});
|
|
113
|
-
} else if ((0, _sdlHelpers.prohibitsMinorUpgrades)(version)) {
|
|
114
|
-
context.report({
|
|
115
|
-
node: node.value,
|
|
116
|
-
message: _sdlRuleMessages.PROHIBITS_MINOR_WARNING
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
// Conservative mode: flag minor or major upgrades
|
|
121
|
-
if ((0, _sdlHelpers.allowsMinorUpgrades)(version) || (0, _sdlHelpers.allowsMajorUpgrades)(version)) {
|
|
122
|
-
context.report({
|
|
123
|
-
node: node.value,
|
|
124
|
-
message: _sdlRuleMessages.MINOR_OR_MAJOR_UPGRADE_WARNING
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SDLPackageVersionCheckImports = void 0;
|
|
7
|
-
var _sdlHelpers = require("./sdlHelpers");
|
|
8
|
-
var _sdlRuleMessages = require("./sdlRuleMessages");
|
|
9
|
-
// Copyright 2025 Amazon.com, Inc. or its affiliates. All rights reserved.
|
|
10
|
-
// AMAZON PROPRIETARY/CONFIDENTIAL
|
|
11
|
-
// You may not use this file except in compliance with the terms and conditions
|
|
12
|
-
// set forth in the accompanying LICENSE.TXT file.
|
|
13
|
-
// THESE MATERIALS ARE PROVIDED ON AN "AS IS" BASIS. AMAZON SPECIFICALLY
|
|
14
|
-
// DISCLAIMS, WITH RESPECT TO THESE MATERIALS, ALL WARRANTIES, EXPRESS,
|
|
15
|
-
// IMPLIED, OR STATUTORY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
// FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
17
|
-
|
|
18
|
-
/* eslint-disable @typescript-eslint/explicit-function-return-type */ // ESLint Rule API uses complex inferred types
|
|
19
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */ // AST node types are complex, using any for simplicity
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* ESLint rule to flag imports of system distributed libraries
|
|
23
|
-
*/
|
|
24
|
-
const SDLPackageVersionCheckImports = exports.SDLPackageVersionCheckImports = {
|
|
25
|
-
meta: {
|
|
26
|
-
type: 'suggestion',
|
|
27
|
-
docs: {
|
|
28
|
-
description: 'Flags imports of system distributed libraries with informational messages',
|
|
29
|
-
recommended: true,
|
|
30
|
-
category: 'System Distributed Libraries'
|
|
31
|
-
},
|
|
32
|
-
schema: [{
|
|
33
|
-
type: 'object',
|
|
34
|
-
properties: {
|
|
35
|
-
semverGuidance: {
|
|
36
|
-
oneOf: [{
|
|
37
|
-
type: 'string',
|
|
38
|
-
enum: ['minor', 'patch', 'auto']
|
|
39
|
-
}]
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
additionalProperties: false
|
|
43
|
-
}]
|
|
44
|
-
},
|
|
45
|
-
create(context) {
|
|
46
|
-
return {
|
|
47
|
-
ImportDeclaration(node) {
|
|
48
|
-
const importSource = node.source.value;
|
|
49
|
-
if ((0, _sdlHelpers.isSystemDistributedLibrary)(importSource)) {
|
|
50
|
-
context.report({
|
|
51
|
-
node: node.source,
|
|
52
|
-
message: `${importSource} ${_sdlRuleMessages.SBL_IMPORT_MESSAGE}`
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
};
|