@akinon/eslint-plugin-projectzero 1.94.0 → 1.95.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @akinon/eslint-plugin-projectzero
2
2
 
3
+ ## 1.95.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3b47394: ZERO-3582: Enhance check-menu-depth rule to enforce depth parameter in getMenu calls and add corresponding error messages
8
+
3
9
  ## 1.94.0
4
10
 
5
11
  ## 1.93.0
@@ -8,21 +8,33 @@ exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
8
8
  CallExpression(node) {
9
9
  const { callee, arguments: args } = node;
10
10
  if (callee.type !== types_1.AST_NODE_TYPES.Identifier ||
11
- callee.name !== 'getMenu' ||
12
- args.length === 0 ||
13
- args[0].type !== types_1.AST_NODE_TYPES.ObjectExpression) {
11
+ callee.name !== 'getMenu') {
14
12
  return;
15
13
  }
16
- const depthProperty = args[0].properties.find((prop) => {
17
- var _a;
18
- return prop.type === types_1.AST_NODE_TYPES.Property &&
19
- prop.key.type === types_1.AST_NODE_TYPES.Identifier &&
20
- prop.key.name === 'depth' &&
21
- ((_a = prop.value) === null || _a === void 0 ? void 0 : _a.type) === types_1.AST_NODE_TYPES.Literal &&
22
- typeof prop.value.value === 'number' &&
23
- prop.value.value > 3;
24
- });
25
- if (depthProperty) {
14
+ if (args.length === 0) {
15
+ context.report({
16
+ node: callee,
17
+ messageId: 'noDepthMessage'
18
+ });
19
+ return;
20
+ }
21
+ if (args[0].type !== types_1.AST_NODE_TYPES.ObjectExpression) {
22
+ return;
23
+ }
24
+ const depthProperty = args[0].properties.find((prop) => prop.type === types_1.AST_NODE_TYPES.Property &&
25
+ prop.key.type === types_1.AST_NODE_TYPES.Identifier &&
26
+ prop.key.name === 'depth');
27
+ if (!depthProperty) {
28
+ context.report({
29
+ node: args[0],
30
+ messageId: 'noDepthMessage'
31
+ });
32
+ return;
33
+ }
34
+ if (depthProperty.type === types_1.AST_NODE_TYPES.Property &&
35
+ depthProperty.value.type === types_1.AST_NODE_TYPES.Literal &&
36
+ typeof depthProperty.value.value === 'number' &&
37
+ depthProperty.value.value > 3) {
26
38
  context.report({
27
39
  node: depthProperty,
28
40
  messageId: 'depthMessage'
@@ -35,7 +47,8 @@ exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
35
47
  type: 'problem',
36
48
  fixable: 'code',
37
49
  messages: {
38
- depthMessage: 'A request for a menu deeper than 3 levels from the server can lead to unnecessary memory usage and unwanted outcomes. Therefore, sending a request for a 3-level menu on the client side and making additional requests on hover for deeper levels may be more efficient.'
50
+ depthMessage: 'A request for a menu deeper than 3 levels from the server can lead to unnecessary memory usage and unwanted outcomes. Therefore, sending a request for a 3-level menu on the client side and making additional requests on hover for deeper levels may be more efficient.',
51
+ noDepthMessage: 'Calling getMenu() without a depth parameter fetches the entire menu, which can cause performance and memory issues. Please provide a depth parameter (maximum 3).'
39
52
  },
40
53
  schema: []
41
54
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/eslint-plugin-projectzero",
3
- "version": "1.94.0",
3
+ "version": "1.95.0",
4
4
  "private": false,
5
5
  "description": "ESLint plugin for Project Zero Next",
6
6
  "main": "dist/index.js",
@@ -9,24 +9,44 @@ export default ESLintUtils.RuleCreator.withoutDocs({
9
9
 
10
10
  if (
11
11
  callee.type !== AST_NODE_TYPES.Identifier ||
12
- callee.name !== 'getMenu' ||
13
- args.length === 0 ||
14
- args[0].type !== AST_NODE_TYPES.ObjectExpression
12
+ callee.name !== 'getMenu'
15
13
  ) {
16
14
  return;
17
15
  }
18
16
 
17
+ if (args.length === 0) {
18
+ context.report({
19
+ node: callee,
20
+ messageId: 'noDepthMessage'
21
+ });
22
+ return;
23
+ }
24
+
25
+ if (args[0].type !== AST_NODE_TYPES.ObjectExpression) {
26
+ return;
27
+ }
28
+
19
29
  const depthProperty = args[0].properties.find(
20
30
  (prop) =>
21
31
  prop.type === AST_NODE_TYPES.Property &&
22
32
  prop.key.type === AST_NODE_TYPES.Identifier &&
23
- prop.key.name === 'depth' &&
24
- prop.value?.type === AST_NODE_TYPES.Literal &&
25
- typeof prop.value.value === 'number' &&
26
- prop.value.value > 3
33
+ prop.key.name === 'depth'
27
34
  );
28
35
 
29
- if (depthProperty) {
36
+ if (!depthProperty) {
37
+ context.report({
38
+ node: args[0],
39
+ messageId: 'noDepthMessage'
40
+ });
41
+ return;
42
+ }
43
+
44
+ if (
45
+ depthProperty.type === AST_NODE_TYPES.Property &&
46
+ depthProperty.value.type === AST_NODE_TYPES.Literal &&
47
+ typeof depthProperty.value.value === 'number' &&
48
+ depthProperty.value.value > 3
49
+ ) {
30
50
  context.report({
31
51
  node: depthProperty,
32
52
  messageId: 'depthMessage'
@@ -40,7 +60,9 @@ export default ESLintUtils.RuleCreator.withoutDocs({
40
60
  fixable: 'code',
41
61
  messages: {
42
62
  depthMessage:
43
- 'A request for a menu deeper than 3 levels from the server can lead to unnecessary memory usage and unwanted outcomes. Therefore, sending a request for a 3-level menu on the client side and making additional requests on hover for deeper levels may be more efficient.'
63
+ 'A request for a menu deeper than 3 levels from the server can lead to unnecessary memory usage and unwanted outcomes. Therefore, sending a request for a 3-level menu on the client side and making additional requests on hover for deeper levels may be more efficient.',
64
+ noDepthMessage:
65
+ 'Calling getMenu() without a depth parameter fetches the entire menu, which can cause performance and memory issues. Please provide a depth parameter (maximum 3).'
44
66
  },
45
67
  schema: []
46
68
  },