@akinon/eslint-plugin-projectzero 2.0.0-beta.2 → 2.0.0-beta.20
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 +114 -6
- package/dist/rules/check-pre-order-middleware-order.js +87 -0
- package/dist/rules/check-sentry-options.js +1 -11
- package/dist/rules/index.js +3 -1
- package/package.json +3 -3
- package/rules/check-pre-order-middleware-order.ts +116 -0
- package/rules/check-sentry-options.ts +1 -12
- package/rules/index.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,18 +1,126 @@
|
|
|
1
1
|
# @akinon/eslint-plugin-projectzero
|
|
2
2
|
|
|
3
|
-
## 2.0.0-beta.
|
|
3
|
+
## 2.0.0-beta.20
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 1.125.0
|
|
6
|
+
|
|
7
|
+
## 1.124.0
|
|
8
|
+
|
|
9
|
+
## 1.123.0
|
|
10
|
+
|
|
11
|
+
## 1.122.0
|
|
12
|
+
|
|
13
|
+
## 1.121.0
|
|
14
|
+
|
|
15
|
+
## 1.120.0
|
|
16
|
+
|
|
17
|
+
## 1.119.0
|
|
18
|
+
|
|
19
|
+
## 1.118.0
|
|
20
|
+
|
|
21
|
+
## 1.117.0
|
|
22
|
+
|
|
23
|
+
## 1.116.0
|
|
24
|
+
|
|
25
|
+
## 1.115.0
|
|
26
|
+
|
|
27
|
+
## 1.114.0
|
|
28
|
+
|
|
29
|
+
## 1.113.0
|
|
30
|
+
|
|
31
|
+
## 1.112.0
|
|
32
|
+
|
|
33
|
+
## 1.111.0
|
|
34
|
+
|
|
35
|
+
## 1.110.0
|
|
36
|
+
|
|
37
|
+
## 1.109.0
|
|
38
|
+
|
|
39
|
+
## 1.108.0
|
|
40
|
+
|
|
41
|
+
## 1.107.0
|
|
42
|
+
|
|
43
|
+
## 1.106.0
|
|
44
|
+
|
|
45
|
+
## 1.105.0
|
|
46
|
+
|
|
47
|
+
### Minor Changes
|
|
48
|
+
|
|
49
|
+
- 62779ee: ZERO-3668: Refactor check-menu-depth rule to simplify depth validation logic and remove unused error messages
|
|
50
|
+
|
|
51
|
+
## 1.104.0
|
|
52
|
+
|
|
53
|
+
## 1.103.0
|
|
54
|
+
|
|
55
|
+
## 1.102.0
|
|
56
|
+
|
|
57
|
+
## 1.101.0
|
|
58
|
+
|
|
59
|
+
## 1.100.0
|
|
60
|
+
|
|
61
|
+
### Minor Changes
|
|
62
|
+
|
|
63
|
+
- e57cd93: ZERO-3460: prevent installment loop on payment method switch
|
|
64
|
+
|
|
65
|
+
## 1.99.0
|
|
6
66
|
|
|
7
67
|
### Minor Changes
|
|
8
68
|
|
|
9
|
-
- ZERO-
|
|
69
|
+
- d58538b: ZERO-3638: Enhance RC pipeline: add fetch, merge, and pre-release setup with conditional commit
|
|
70
|
+
|
|
71
|
+
## 1.98.0
|
|
72
|
+
|
|
73
|
+
## 1.97.0
|
|
74
|
+
|
|
75
|
+
## 1.96.0
|
|
76
|
+
|
|
77
|
+
## 1.95.0
|
|
78
|
+
|
|
79
|
+
### Minor Changes
|
|
80
|
+
|
|
81
|
+
- 3b47394: ZERO-3582: Enhance check-menu-depth rule to enforce depth parameter in getMenu calls and add corresponding error messages
|
|
82
|
+
|
|
83
|
+
## 1.94.0
|
|
84
|
+
|
|
85
|
+
## 1.93.0
|
|
86
|
+
|
|
87
|
+
## 1.92.0
|
|
88
|
+
|
|
89
|
+
## 1.91.0
|
|
90
|
+
|
|
91
|
+
## 1.90.0
|
|
92
|
+
|
|
93
|
+
## 1.89.0
|
|
94
|
+
|
|
95
|
+
## 1.88.0
|
|
96
|
+
|
|
97
|
+
## 1.87.0
|
|
98
|
+
|
|
99
|
+
## 1.86.0
|
|
100
|
+
|
|
101
|
+
## 1.85.0
|
|
102
|
+
|
|
103
|
+
### Minor Changes
|
|
104
|
+
|
|
105
|
+
- 443ea19: ZERO-3254: Add ESLint rule to enforce correct order of pre-order middlewares
|
|
106
|
+
|
|
107
|
+
## 1.84.0
|
|
108
|
+
|
|
109
|
+
## 1.83.0
|
|
110
|
+
|
|
111
|
+
## 1.82.0
|
|
112
|
+
|
|
113
|
+
## 1.81.0
|
|
114
|
+
|
|
115
|
+
## 1.80.0
|
|
116
|
+
|
|
117
|
+
## 1.79.0
|
|
10
118
|
|
|
11
|
-
##
|
|
119
|
+
## 1.78.0
|
|
12
120
|
|
|
13
|
-
|
|
121
|
+
## 1.77.0
|
|
14
122
|
|
|
15
|
-
|
|
123
|
+
## 1.76.0
|
|
16
124
|
|
|
17
125
|
## 1.75.0
|
|
18
126
|
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
const CORRECT_PRE_ORDER_MIDDLEWARE_ORDER = [
|
|
5
|
+
'shippingStepMiddleware',
|
|
6
|
+
'installmentOptionMiddleware',
|
|
7
|
+
'paymentOptionResetMiddleware',
|
|
8
|
+
'paymentOptionMiddleware',
|
|
9
|
+
'attributeBasedShippingOptionMiddleware',
|
|
10
|
+
'dataSourceShippingOptionMiddleware',
|
|
11
|
+
'shippingOptionMiddleware',
|
|
12
|
+
'setAddressMiddleware',
|
|
13
|
+
'deliveryOptionMiddleware',
|
|
14
|
+
'setPreOrderMiddleware',
|
|
15
|
+
'redirectionMiddleware',
|
|
16
|
+
'preOrderValidationMiddleware'
|
|
17
|
+
];
|
|
18
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
19
|
+
create(context) {
|
|
20
|
+
function checkPreOrderMiddlewareOrder(node) {
|
|
21
|
+
if (!isPreOrderMiddlewaresDeclaration(node)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
const arrayExpression = node.init;
|
|
25
|
+
const foundOrder = extractMiddlewareNames(arrayExpression);
|
|
26
|
+
validateMiddlewareOrder(foundOrder, node);
|
|
27
|
+
}
|
|
28
|
+
function isPreOrderMiddlewaresDeclaration(node) {
|
|
29
|
+
var _a;
|
|
30
|
+
return (node.id.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
31
|
+
node.id.name === 'preOrderMiddlewares' &&
|
|
32
|
+
((_a = node.init) === null || _a === void 0 ? void 0 : _a.type) === utils_1.AST_NODE_TYPES.ArrayExpression);
|
|
33
|
+
}
|
|
34
|
+
function extractMiddlewareNames(arrayExpression) {
|
|
35
|
+
return arrayExpression.elements
|
|
36
|
+
.map((element) => {
|
|
37
|
+
if ((element === null || element === void 0 ? void 0 : element.type) === utils_1.AST_NODE_TYPES.Identifier) {
|
|
38
|
+
return element.name;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
})
|
|
42
|
+
.filter((name) => Boolean(name));
|
|
43
|
+
}
|
|
44
|
+
function validateMiddlewareOrder(foundOrder, node) {
|
|
45
|
+
for (let i = 0; i < foundOrder.length; i++) {
|
|
46
|
+
const middleware = foundOrder[i];
|
|
47
|
+
const correctIndex = CORRECT_PRE_ORDER_MIDDLEWARE_ORDER.indexOf(middleware);
|
|
48
|
+
if (correctIndex === -1) {
|
|
49
|
+
context.report({
|
|
50
|
+
node,
|
|
51
|
+
messageId: 'unknownMiddleware',
|
|
52
|
+
data: { middleware }
|
|
53
|
+
});
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
if (i !== correctIndex) {
|
|
57
|
+
context.report({
|
|
58
|
+
node,
|
|
59
|
+
messageId: 'incorrectPreOrderMiddlewarePosition',
|
|
60
|
+
data: {
|
|
61
|
+
middleware,
|
|
62
|
+
currentPosition: i + 1,
|
|
63
|
+
expectedPosition: correctIndex + 1
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
VariableDeclarator: checkPreOrderMiddlewareOrder
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
meta: {
|
|
75
|
+
type: 'problem',
|
|
76
|
+
docs: {
|
|
77
|
+
description: 'Enforces the correct order of pre-order middlewares',
|
|
78
|
+
recommended: 'error'
|
|
79
|
+
},
|
|
80
|
+
schema: [],
|
|
81
|
+
messages: {
|
|
82
|
+
incorrectPreOrderMiddlewarePosition: '{{middleware}} is at position {{currentPosition}}, but it should be at position {{expectedPosition}}.',
|
|
83
|
+
unknownMiddleware: '{{middleware}} is not recognized as a valid pre-order middleware.'
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
defaultOptions: []
|
|
87
|
+
});
|
|
@@ -33,15 +33,6 @@ exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
if (key === 'tracesSampleRate') {
|
|
37
|
-
const traceRate = property.value.value;
|
|
38
|
-
if (traceRate !== 1.0) {
|
|
39
|
-
context.report({
|
|
40
|
-
node: property,
|
|
41
|
-
messageId: 'incorrectTraceRate'
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
36
|
}
|
|
46
37
|
});
|
|
47
38
|
}
|
|
@@ -51,8 +42,7 @@ exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
|
51
42
|
},
|
|
52
43
|
meta: {
|
|
53
44
|
messages: {
|
|
54
|
-
invalidDsn: 'Sentry DSN should not be empty.'
|
|
55
|
-
incorrectTraceRate: 'Sentry tracesSampleRate should be set to 1.0.'
|
|
45
|
+
invalidDsn: 'Sentry DSN should not be empty.'
|
|
56
46
|
},
|
|
57
47
|
type: 'problem',
|
|
58
48
|
fixable: 'code',
|
package/dist/rules/index.js
CHANGED
|
@@ -17,6 +17,7 @@ const invalid_imports_1 = __importDefault(require("./invalid-imports"));
|
|
|
17
17
|
const case_warning_1 = __importDefault(require("./case-warning"));
|
|
18
18
|
const check_sentry_options_1 = __importDefault(require("./check-sentry-options"));
|
|
19
19
|
const check_menu_depth_1 = __importDefault(require("./check-menu-depth"));
|
|
20
|
+
const check_pre_order_middleware_order_1 = __importDefault(require("./check-pre-order-middleware-order"));
|
|
20
21
|
const rules = {
|
|
21
22
|
'client-url': client_url_1.default,
|
|
22
23
|
'image-import': image_import_1.default,
|
|
@@ -30,6 +31,7 @@ const rules = {
|
|
|
30
31
|
'invalid-imports': invalid_imports_1.default,
|
|
31
32
|
'case-warning': case_warning_1.default,
|
|
32
33
|
'check-sentry-options': check_sentry_options_1.default,
|
|
33
|
-
'check-menu-depth': check_menu_depth_1.default
|
|
34
|
+
'check-menu-depth': check_menu_depth_1.default,
|
|
35
|
+
'check-pre-order-middleware-order': check_pre_order_middleware_order_1.default
|
|
34
36
|
};
|
|
35
37
|
exports.rules = rules;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akinon/eslint-plugin-projectzero",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.20",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "ESLint plugin for Project Zero Next",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"author": "",
|
|
14
14
|
"license": "ISC",
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@typescript-eslint/eslint-plugin": "
|
|
17
|
-
"@typescript-eslint/parser": "
|
|
16
|
+
"@typescript-eslint/eslint-plugin": "5.44.0",
|
|
17
|
+
"@typescript-eslint/parser": "5.44.0"
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AST_NODE_TYPES,
|
|
3
|
+
ESLintUtils,
|
|
4
|
+
TSESTree
|
|
5
|
+
} from '@typescript-eslint/utils';
|
|
6
|
+
import { RuleContext } from '@typescript-eslint/utils/dist/ts-eslint';
|
|
7
|
+
|
|
8
|
+
const CORRECT_PRE_ORDER_MIDDLEWARE_ORDER = [
|
|
9
|
+
'shippingStepMiddleware',
|
|
10
|
+
'installmentOptionMiddleware',
|
|
11
|
+
'paymentOptionResetMiddleware',
|
|
12
|
+
'paymentOptionMiddleware',
|
|
13
|
+
'attributeBasedShippingOptionMiddleware',
|
|
14
|
+
'dataSourceShippingOptionMiddleware',
|
|
15
|
+
'shippingOptionMiddleware',
|
|
16
|
+
'setAddressMiddleware',
|
|
17
|
+
'deliveryOptionMiddleware',
|
|
18
|
+
'setPreOrderMiddleware',
|
|
19
|
+
'redirectionMiddleware',
|
|
20
|
+
'preOrderValidationMiddleware'
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
type MessageIds = 'incorrectPreOrderMiddlewarePosition' | 'unknownMiddleware';
|
|
24
|
+
type Options = [];
|
|
25
|
+
|
|
26
|
+
export default ESLintUtils.RuleCreator.withoutDocs({
|
|
27
|
+
create(context: RuleContext<MessageIds, Options>) {
|
|
28
|
+
function checkPreOrderMiddlewareOrder(
|
|
29
|
+
node: TSESTree.VariableDeclarator
|
|
30
|
+
): void {
|
|
31
|
+
if (!isPreOrderMiddlewaresDeclaration(node)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const arrayExpression = node.init as TSESTree.ArrayExpression;
|
|
36
|
+
const foundOrder = extractMiddlewareNames(arrayExpression);
|
|
37
|
+
|
|
38
|
+
validateMiddlewareOrder(foundOrder, node);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function isPreOrderMiddlewaresDeclaration(
|
|
42
|
+
node: TSESTree.VariableDeclarator
|
|
43
|
+
): boolean {
|
|
44
|
+
return (
|
|
45
|
+
node.id.type === AST_NODE_TYPES.Identifier &&
|
|
46
|
+
node.id.name === 'preOrderMiddlewares' &&
|
|
47
|
+
node.init?.type === AST_NODE_TYPES.ArrayExpression
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function extractMiddlewareNames(
|
|
52
|
+
arrayExpression: TSESTree.ArrayExpression
|
|
53
|
+
): string[] {
|
|
54
|
+
return arrayExpression.elements
|
|
55
|
+
.map((element) => {
|
|
56
|
+
if (element?.type === AST_NODE_TYPES.Identifier) {
|
|
57
|
+
return element.name;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
})
|
|
61
|
+
.filter((name): name is string => Boolean(name));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function validateMiddlewareOrder(
|
|
65
|
+
foundOrder: string[],
|
|
66
|
+
node: TSESTree.Node
|
|
67
|
+
): void {
|
|
68
|
+
for (let i = 0; i < foundOrder.length; i++) {
|
|
69
|
+
const middleware = foundOrder[i];
|
|
70
|
+
const correctIndex =
|
|
71
|
+
CORRECT_PRE_ORDER_MIDDLEWARE_ORDER.indexOf(middleware);
|
|
72
|
+
|
|
73
|
+
if (correctIndex === -1) {
|
|
74
|
+
context.report({
|
|
75
|
+
node,
|
|
76
|
+
messageId: 'unknownMiddleware',
|
|
77
|
+
data: { middleware }
|
|
78
|
+
});
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (i !== correctIndex) {
|
|
83
|
+
context.report({
|
|
84
|
+
node,
|
|
85
|
+
messageId: 'incorrectPreOrderMiddlewarePosition',
|
|
86
|
+
data: {
|
|
87
|
+
middleware,
|
|
88
|
+
currentPosition: i + 1,
|
|
89
|
+
expectedPosition: correctIndex + 1
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
VariableDeclarator: checkPreOrderMiddlewareOrder
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
meta: {
|
|
102
|
+
type: 'problem',
|
|
103
|
+
docs: {
|
|
104
|
+
description: 'Enforces the correct order of pre-order middlewares',
|
|
105
|
+
recommended: 'error'
|
|
106
|
+
},
|
|
107
|
+
schema: [],
|
|
108
|
+
messages: {
|
|
109
|
+
incorrectPreOrderMiddlewarePosition:
|
|
110
|
+
'{{middleware}} is at position {{currentPosition}}, but it should be at position {{expectedPosition}}.',
|
|
111
|
+
unknownMiddleware:
|
|
112
|
+
'{{middleware}} is not recognized as a valid pre-order middleware.'
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
defaultOptions: []
|
|
116
|
+
});
|
|
@@ -42,16 +42,6 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
if (key === 'tracesSampleRate') {
|
|
47
|
-
const traceRate = (property.value as TSESTree.Literal).value;
|
|
48
|
-
if (traceRate !== 1.0) {
|
|
49
|
-
context.report({
|
|
50
|
-
node: property,
|
|
51
|
-
messageId: 'incorrectTraceRate'
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
45
|
}
|
|
56
46
|
});
|
|
57
47
|
}
|
|
@@ -61,8 +51,7 @@ export default ESLintUtils.RuleCreator.withoutDocs({
|
|
|
61
51
|
},
|
|
62
52
|
meta: {
|
|
63
53
|
messages: {
|
|
64
|
-
invalidDsn: 'Sentry DSN should not be empty.'
|
|
65
|
-
incorrectTraceRate: 'Sentry tracesSampleRate should be set to 1.0.'
|
|
54
|
+
invalidDsn: 'Sentry DSN should not be empty.'
|
|
66
55
|
},
|
|
67
56
|
type: 'problem',
|
|
68
57
|
fixable: 'code',
|
package/rules/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import invalidImports from './invalid-imports';
|
|
|
11
11
|
import caseWarning from './case-warning';
|
|
12
12
|
import checkSentryOptions from './check-sentry-options';
|
|
13
13
|
import checkMenuDepth from './check-menu-depth';
|
|
14
|
+
import checkPreOrderMiddlewareOrder from './check-pre-order-middleware-order';
|
|
14
15
|
|
|
15
16
|
const rules = {
|
|
16
17
|
'client-url': clientUrl,
|
|
@@ -25,7 +26,8 @@ const rules = {
|
|
|
25
26
|
'invalid-imports': invalidImports,
|
|
26
27
|
'case-warning': caseWarning,
|
|
27
28
|
'check-sentry-options': checkSentryOptions,
|
|
28
|
-
'check-menu-depth': checkMenuDepth
|
|
29
|
+
'check-menu-depth': checkMenuDepth,
|
|
30
|
+
'check-pre-order-middleware-order': checkPreOrderMiddlewareOrder
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
export { rules };
|