@agilebot/eslint-plugin 0.3.14 → 0.4.0
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/dist/index.js +48 -11
- package/package.json +7 -6
package/dist/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* @license @agilebot/eslint-plugin v0.
|
2
|
+
* @license @agilebot/eslint-plugin v0.4.0
|
3
3
|
*
|
4
4
|
* Copyright (c) Agilebot, Inc. and its affiliates.
|
5
5
|
*
|
@@ -32,6 +32,9 @@ function _interopNamespaceDefault(e) {
|
|
32
32
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
33
33
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
34
34
|
|
35
|
+
const rule = require('eslint-plugin-deprecation/dist/rules/deprecation')["default"];
|
36
|
+
var deprecation = eslintUtils.fixupRule(rule);
|
37
|
+
|
35
38
|
var enforceMuiIconAlias = eslintUtils.createESLintRule({
|
36
39
|
meta: {
|
37
40
|
type: 'problem',
|
@@ -674,15 +677,20 @@ var noThenCatchFinally = eslintUtils.createESLintRule({
|
|
674
677
|
create(context) {
|
675
678
|
const configuration = context.options[0] || {};
|
676
679
|
const restrictedFunctions = configuration.restrictedFunctions || [];
|
677
|
-
function
|
678
|
-
return context.getScope()
|
680
|
+
const getScope = typeof context.getScope === 'function' ? () => {
|
681
|
+
return context.getScope();
|
682
|
+
} : node => {
|
683
|
+
return context.sourceCode.getScope(node);
|
684
|
+
};
|
685
|
+
function isTopLevelScoped(node) {
|
686
|
+
return getScope(node).block.type === 'Program';
|
679
687
|
}
|
680
688
|
function isThenCatchFinally(node) {
|
681
689
|
return node.property && (node.property.name === 'then' || node.property.name === 'catch' || node.property.name === 'finally');
|
682
690
|
}
|
683
691
|
return {
|
684
692
|
'CallExpression > MemberExpression.callee'(node) {
|
685
|
-
if (isTopLevelScoped()) {
|
693
|
+
if (isTopLevelScoped(node)) {
|
686
694
|
return;
|
687
695
|
}
|
688
696
|
if (!isThenCatchFinally(node)) {
|
@@ -797,6 +805,16 @@ var reactBetterExhaustiveDeps = {
|
|
797
805
|
}
|
798
806
|
context.report(problem);
|
799
807
|
}
|
808
|
+
const getSource = typeof context.getSource === 'function' ? node => {
|
809
|
+
return context.getSource(node);
|
810
|
+
} : node => {
|
811
|
+
return context.sourceCode.getText(node);
|
812
|
+
};
|
813
|
+
const getScope = typeof context.getScope === 'function' ? () => {
|
814
|
+
return context.getScope();
|
815
|
+
} : node => {
|
816
|
+
return context.sourceCode.getScope(node);
|
817
|
+
};
|
800
818
|
const scopeManager = context.getSourceCode().scopeManager;
|
801
819
|
const setStateCallSites = new WeakMap();
|
802
820
|
const stateVariables = new WeakSet();
|
@@ -1099,7 +1117,7 @@ var reactBetterExhaustiveDeps = {
|
|
1099
1117
|
staleAssignments.add(key);
|
1100
1118
|
reportProblem({
|
1101
1119
|
node: writeExpr,
|
1102
|
-
message: "Assignments to the '".concat(key, "' variable from inside React Hook ") + "".concat(
|
1120
|
+
message: "Assignments to the '".concat(key, "' variable from inside React Hook ") + "".concat(getSource(reactiveHook), " will be lost after each ") + "render. To preserve the value over time, store it in a useRef " + "Hook and keep the mutable value in the '.current' property. " + "Otherwise, you can move this variable directly inside " + "".concat(getSource(reactiveHook), ".")
|
1103
1121
|
});
|
1104
1122
|
}
|
1105
1123
|
const stableDependencies = new Set();
|
@@ -1174,7 +1192,7 @@ var reactBetterExhaustiveDeps = {
|
|
1174
1192
|
if (declaredDependenciesNode.type !== 'ArrayExpression') {
|
1175
1193
|
reportProblem({
|
1176
1194
|
node: declaredDependenciesNode,
|
1177
|
-
message: "React Hook ".concat(
|
1195
|
+
message: "React Hook ".concat(getSource(reactiveHook), " was passed a ") + 'dependency list that is not an array literal. This means we ' + "can't statically verify whether you've passed the correct " + 'dependencies.'
|
1178
1196
|
});
|
1179
1197
|
} else {
|
1180
1198
|
declaredDependenciesNode.elements.forEach(declaredDependencyNode => {
|
@@ -1184,7 +1202,7 @@ var reactBetterExhaustiveDeps = {
|
|
1184
1202
|
if (declaredDependencyNode.type === 'SpreadElement') {
|
1185
1203
|
reportProblem({
|
1186
1204
|
node: declaredDependencyNode,
|
1187
|
-
message: "React Hook ".concat(
|
1205
|
+
message: "React Hook ".concat(getSource(reactiveHook), " has a spread ") + "element in its dependency array. This means we can't " + "statically verify whether you've passed the " + 'correct dependencies.'
|
1188
1206
|
});
|
1189
1207
|
return;
|
1190
1208
|
}
|
@@ -1208,7 +1226,7 @@ var reactBetterExhaustiveDeps = {
|
|
1208
1226
|
} else {
|
1209
1227
|
reportProblem({
|
1210
1228
|
node: declaredDependencyNode,
|
1211
|
-
message: "React Hook ".concat(
|
1229
|
+
message: "React Hook ".concat(getSource(reactiveHook), " has a ") + "complex expression in the dependency array. " + 'Extract it to a separate variable so it can be statically checked.'
|
1212
1230
|
});
|
1213
1231
|
}
|
1214
1232
|
return;
|
@@ -1368,7 +1386,7 @@ var reactBetterExhaustiveDeps = {
|
|
1368
1386
|
}
|
1369
1387
|
}
|
1370
1388
|
if (isPropsOnlyUsedInMembers) {
|
1371
|
-
extraWarning = " However, 'props' will change when *any* prop changes, so the " + "preferred fix is to destructure the 'props' object outside of " + "the ".concat(reactiveHookName, " call and refer to those specific props ") + "inside ".concat(
|
1389
|
+
extraWarning = " However, 'props' will change when *any* prop changes, so the " + "preferred fix is to destructure the 'props' object outside of " + "the ".concat(reactiveHookName, " call and refer to those specific props ") + "inside ".concat(getSource(reactiveHook), ".");
|
1372
1390
|
}
|
1373
1391
|
}
|
1374
1392
|
if (!extraWarning && missingDependencies.size > 0) {
|
@@ -1474,7 +1492,7 @@ var reactBetterExhaustiveDeps = {
|
|
1474
1492
|
}
|
1475
1493
|
reportProblem({
|
1476
1494
|
node: declaredDependenciesNode,
|
1477
|
-
message: "React Hook ".concat(
|
1495
|
+
message: "React Hook ".concat(getSource(reactiveHook), " has ") + (
|
1478
1496
|
getWarningMessage(missingDependencies, 'a', 'missing', 'include') || getWarningMessage(unnecessaryDependencies, 'an', 'unnecessary', 'exclude') || getWarningMessage(duplicateDependencies, 'a', 'duplicate', 'omit')) + extraWarning,
|
1479
1497
|
suggest: [{
|
1480
1498
|
desc: "Update the dependencies array to be: [".concat(suggestedDeps.map(element => formatDependency(element)).join(', '), "]"),
|
@@ -1522,7 +1540,7 @@ var reactBetterExhaustiveDeps = {
|
|
1522
1540
|
if (declaredDependenciesNode.elements && declaredDependenciesNode.elements.some(el => el && el.type === 'Identifier' && el.name === callback.name)) {
|
1523
1541
|
return;
|
1524
1542
|
}
|
1525
|
-
const variable =
|
1543
|
+
const variable = getScope(callback).set.get(callback.name);
|
1526
1544
|
if (variable == null || variable.defs == null) {
|
1527
1545
|
return;
|
1528
1546
|
}
|
@@ -2713,6 +2731,24 @@ var varNaming = eslintUtils.createESLintRule({
|
|
2713
2731
|
name: fnName
|
2714
2732
|
});
|
2715
2733
|
}
|
2734
|
+
} else if (node.id && node.init && node.init.type === 'LogicalExpression') {
|
2735
|
+
const varName = node.id.name;
|
2736
|
+
const parts = [node.init.left, node.init.right];
|
2737
|
+
let partIsReactComponent = false;
|
2738
|
+
for (const part of parts) {
|
2739
|
+
if (['FunctionExpression', 'ArrowFunctionExpression'].includes(part.type)) {
|
2740
|
+
const isReactComponent = checkJSXElement(part.body);
|
2741
|
+
if (isReactComponent) {
|
2742
|
+
partIsReactComponent = true;
|
2743
|
+
}
|
2744
|
+
}
|
2745
|
+
}
|
2746
|
+
if (!partIsReactComponent) {
|
2747
|
+
validate('var', {
|
2748
|
+
node,
|
2749
|
+
name: varName
|
2750
|
+
});
|
2751
|
+
}
|
2716
2752
|
} else if (node.id) {
|
2717
2753
|
const varName = node.id.name;
|
2718
2754
|
for (const excludeRegex of exclude) {
|
@@ -2755,6 +2791,7 @@ var varNaming = eslintUtils.createESLintRule({
|
|
2755
2791
|
|
2756
2792
|
var ruleFiles = /*#__PURE__*/Object.freeze({
|
2757
2793
|
__proto__: null,
|
2794
|
+
rules_deprecation: deprecation,
|
2758
2795
|
rules_enforce_mui_icon_alias: enforceMuiIconAlias,
|
2759
2796
|
rules_import_monorepo: importMonorepo,
|
2760
2797
|
rules_intl_id_missing: intlIdMissing,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@agilebot/eslint-plugin",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"description": "Agilebot's ESLint plugin",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -18,11 +18,12 @@
|
|
18
18
|
"node": "^18.18.0 || >=20.0.0"
|
19
19
|
},
|
20
20
|
"dependencies": {
|
21
|
+
"eslint-plugin-deprecation": "^3.0.0",
|
21
22
|
"eslint-plugin-react": "^7.35.0",
|
22
|
-
"@agilebot/eslint-utils": "0.
|
23
|
+
"@agilebot/eslint-utils": "0.4.0"
|
23
24
|
},
|
24
25
|
"peerDependencies": {
|
25
|
-
"eslint": "^7.0.0 || ^8.0.0"
|
26
|
+
"eslint": "^7.0.0 || ^8.0.0 || ^9.0.0"
|
26
27
|
},
|
27
28
|
"files": [
|
28
29
|
"dist"
|
@@ -31,11 +32,11 @@
|
|
31
32
|
"@types/color-name": "^1.1.4",
|
32
33
|
"@types/estree": "^1.0.5",
|
33
34
|
"color-name": "^2.0.0",
|
34
|
-
"eslint-vitest-rule-tester": "^0.
|
35
|
-
"typescript-eslint": "^
|
35
|
+
"eslint-vitest-rule-tester": "^0.6.1",
|
36
|
+
"typescript-eslint": "^8.0.0"
|
36
37
|
},
|
37
38
|
"scripts": {
|
38
39
|
"build": "rollup -c rollup.config.mjs",
|
39
|
-
"lint": "eslint src
|
40
|
+
"lint": "eslint-agilebot src"
|
40
41
|
}
|
41
42
|
}
|