@akinon/eslint-plugin-projectzero 1.12.0 → 1.13.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 +6 -0
- package/dist/rules/check-middleware-order.js +54 -0
- package/dist/rules/index.js +3 -1
- package/package.json +1 -1
- package/rules/check-middleware-order.ts +64 -0
- package/rules/index.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
const correctOrder = [
|
|
5
|
+
'withOauthLogin',
|
|
6
|
+
'withLocale',
|
|
7
|
+
'withCurrency',
|
|
8
|
+
'withPrettyUrl',
|
|
9
|
+
'withRedirectionPayment',
|
|
10
|
+
'withThreeDRedirection',
|
|
11
|
+
'withUrlRedirection'
|
|
12
|
+
];
|
|
13
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
14
|
+
create(context) {
|
|
15
|
+
return {
|
|
16
|
+
CallExpression(node) {
|
|
17
|
+
if (node.callee.type === 'Identifier' &&
|
|
18
|
+
correctOrder.includes(node.callee.name)) {
|
|
19
|
+
let current = node;
|
|
20
|
+
const callSequence = [];
|
|
21
|
+
while (current.type === 'CallExpression' &&
|
|
22
|
+
current.callee.type === 'Identifier') {
|
|
23
|
+
if (correctOrder.includes(current.callee.name)) {
|
|
24
|
+
callSequence.unshift(current.callee.name);
|
|
25
|
+
}
|
|
26
|
+
current = current.parent;
|
|
27
|
+
}
|
|
28
|
+
let isValidOrder = true;
|
|
29
|
+
for (let i = 0; i < callSequence.length; i++) {
|
|
30
|
+
if (callSequence[i] !== correctOrder[i]) {
|
|
31
|
+
isValidOrder = false;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Report an error if the order is incorrect
|
|
36
|
+
if (!isValidOrder) {
|
|
37
|
+
context.report({
|
|
38
|
+
node,
|
|
39
|
+
message: `Incorrect order of middleware functions. Expected order: ${correctOrder.join(', ')}. Found order: ${callSequence.join(', ')}.`
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
meta: {
|
|
47
|
+
type: 'problem',
|
|
48
|
+
schema: [],
|
|
49
|
+
messages: {
|
|
50
|
+
incorrectMiddlewareOrder: 'Incorrect middleware order. Expected {{expected}}, found {{found}}.'
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
defaultOptions: []
|
|
54
|
+
});
|
package/dist/rules/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const router_import_1 = __importDefault(require("./router-import"));
|
|
|
11
11
|
const skip_trailing_slash_redirect_1 = __importDefault(require("./skip-trailing-slash-redirect"));
|
|
12
12
|
const check_locale_1 = __importDefault(require("./check-locale"));
|
|
13
13
|
const meta_data_import_1 = __importDefault(require("./meta-data-import"));
|
|
14
|
+
const check_middleware_order_1 = __importDefault(require("./check-middleware-order"));
|
|
14
15
|
const rules = {
|
|
15
16
|
'client-url': client_url_1.default,
|
|
16
17
|
'image-import': image_import_1.default,
|
|
@@ -18,6 +19,7 @@ const rules = {
|
|
|
18
19
|
'router-import': router_import_1.default,
|
|
19
20
|
'skip-trailing-slash-redirect': skip_trailing_slash_redirect_1.default,
|
|
20
21
|
'check-locale': check_locale_1.default,
|
|
21
|
-
'meta-data-import': meta_data_import_1.default
|
|
22
|
+
'meta-data-import': meta_data_import_1.default,
|
|
23
|
+
'check-middleware-order': check_middleware_order_1.default
|
|
22
24
|
};
|
|
23
25
|
exports.rules = rules;
|
package/package.json
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
const correctOrder = [
|
|
4
|
+
'withOauthLogin',
|
|
5
|
+
'withLocale',
|
|
6
|
+
'withCurrency',
|
|
7
|
+
'withPrettyUrl',
|
|
8
|
+
'withRedirectionPayment',
|
|
9
|
+
'withThreeDRedirection',
|
|
10
|
+
'withUrlRedirection'
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
export default ESLintUtils.RuleCreator.withoutDocs({
|
|
14
|
+
create(context: any) {
|
|
15
|
+
return {
|
|
16
|
+
CallExpression(node: any) {
|
|
17
|
+
if (
|
|
18
|
+
node.callee.type === 'Identifier' &&
|
|
19
|
+
correctOrder.includes(node.callee.name)
|
|
20
|
+
) {
|
|
21
|
+
let current = node;
|
|
22
|
+
const callSequence = [];
|
|
23
|
+
|
|
24
|
+
while (
|
|
25
|
+
current.type === 'CallExpression' &&
|
|
26
|
+
current.callee.type === 'Identifier'
|
|
27
|
+
) {
|
|
28
|
+
if (correctOrder.includes(current.callee.name)) {
|
|
29
|
+
callSequence.unshift(current.callee.name);
|
|
30
|
+
}
|
|
31
|
+
current = current.parent;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let isValidOrder = true;
|
|
35
|
+
for (let i = 0; i < callSequence.length; i++) {
|
|
36
|
+
if (callSequence[i] !== correctOrder[i]) {
|
|
37
|
+
isValidOrder = false;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Report an error if the order is incorrect
|
|
43
|
+
if (!isValidOrder) {
|
|
44
|
+
context.report({
|
|
45
|
+
node,
|
|
46
|
+
message: `Incorrect order of middleware functions. Expected order: ${correctOrder.join(
|
|
47
|
+
', '
|
|
48
|
+
)}. Found order: ${callSequence.join(', ')}.`
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
meta: {
|
|
56
|
+
type: 'problem',
|
|
57
|
+
schema: [],
|
|
58
|
+
messages: {
|
|
59
|
+
incorrectMiddlewareOrder:
|
|
60
|
+
'Incorrect middleware order. Expected {{expected}}, found {{found}}.'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
defaultOptions: []
|
|
64
|
+
});
|
package/rules/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import routerImport from './router-import';
|
|
|
5
5
|
import skipTrailingSlashRedirect from './skip-trailing-slash-redirect';
|
|
6
6
|
import checkLocale from './check-locale';
|
|
7
7
|
import metaDataImport from './meta-data-import';
|
|
8
|
+
import checkMiddlewareOrder from './check-middleware-order';
|
|
8
9
|
|
|
9
10
|
const rules = {
|
|
10
11
|
'client-url': clientUrl,
|
|
@@ -13,7 +14,8 @@ const rules = {
|
|
|
13
14
|
'router-import': routerImport,
|
|
14
15
|
'skip-trailing-slash-redirect': skipTrailingSlashRedirect,
|
|
15
16
|
'check-locale': checkLocale,
|
|
16
|
-
'meta-data-import': metaDataImport
|
|
17
|
+
'meta-data-import': metaDataImport,
|
|
18
|
+
'check-middleware-order': checkMiddlewareOrder
|
|
17
19
|
};
|
|
18
20
|
|
|
19
21
|
export { rules };
|