@akinon/eslint-plugin-projectzero 1.49.0 → 1.50.0-rc.1
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 +11 -0
- package/configs/core.ts +3 -0
- package/dist/configs/core.js +3 -0
- package/dist/rules/case-warning.js +32 -0
- package/dist/rules/check-menu-depth.js +43 -0
- package/dist/rules/check-sentry-options.js +62 -0
- package/dist/rules/index.js +7 -1
- package/package.json +1 -1
- package/rules/case-warning.ts +39 -0
- package/rules/check-menu-depth.ts +48 -0
- package/rules/check-sentry-options.ts +72 -0
- package/rules/index.ts +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @akinon/eslint-plugin-projectzero
|
|
2
2
|
|
|
3
|
+
## 1.50.0-rc.1
|
|
4
|
+
|
|
5
|
+
## 1.50.0-rc.0
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- 4d64ef7: ZERO-2611: Add check-sentry-options rule to eslint-plugin-projectzero
|
|
10
|
+
- 5a4c6076: ZERO-2764: Add case-warning rule to eslint-plugin-projectzero
|
|
11
|
+
- 64699d3: ZERO-2761: Fix invalid import for plugin module
|
|
12
|
+
- c4747807: ZERO-2666: Add rule to check menu depth
|
|
13
|
+
|
|
3
14
|
## 1.49.0
|
|
4
15
|
|
|
5
16
|
## 1.48.0
|
package/configs/core.ts
CHANGED
|
@@ -9,6 +9,9 @@ export default {
|
|
|
9
9
|
'@akinon/projectzero/meta-data-import': 'error',
|
|
10
10
|
'@akinon/projectzero/urls-without-slash': 'error',
|
|
11
11
|
'@akinon/projectzero/invalid-imports': 'error',
|
|
12
|
+
'@akinon/projectzero/check-menu-depth': 'error',
|
|
13
|
+
'@akinon/projectzero/case-warning': 'warn',
|
|
14
|
+
'@akinon/projectzero/check-sentry-options': 'error',
|
|
12
15
|
'no-restricted-syntax': [
|
|
13
16
|
'error',
|
|
14
17
|
{
|
package/dist/configs/core.js
CHANGED
|
@@ -11,6 +11,9 @@ exports.default = {
|
|
|
11
11
|
'@akinon/projectzero/meta-data-import': 'error',
|
|
12
12
|
'@akinon/projectzero/urls-without-slash': 'error',
|
|
13
13
|
'@akinon/projectzero/invalid-imports': 'error',
|
|
14
|
+
'@akinon/projectzero/check-menu-depth': 'error',
|
|
15
|
+
'@akinon/projectzero/case-warning': 'warn',
|
|
16
|
+
'@akinon/projectzero/check-sentry-options': 'error',
|
|
14
17
|
'no-restricted-syntax': [
|
|
15
18
|
'error',
|
|
16
19
|
{
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
5
|
+
create(context) {
|
|
6
|
+
return {
|
|
7
|
+
CallExpression(node) {
|
|
8
|
+
if (node.callee.type === 'MemberExpression' &&
|
|
9
|
+
node.callee.property.type === 'Identifier' &&
|
|
10
|
+
(node.callee.property.name === 'toLocaleUpperCase' ||
|
|
11
|
+
node.callee.property.name === 'toLocaleLowerCase')) {
|
|
12
|
+
const args = node.arguments;
|
|
13
|
+
if (args.length === 0) {
|
|
14
|
+
context.report({
|
|
15
|
+
node,
|
|
16
|
+
messageId: 'noLocale'
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
meta: {
|
|
24
|
+
messages: {
|
|
25
|
+
noLocale: 'toLocaleUpperCase() or toLocaleLowerCase() should specify a locale for consistent behavior across different environments.'
|
|
26
|
+
},
|
|
27
|
+
type: 'problem',
|
|
28
|
+
fixable: 'code',
|
|
29
|
+
schema: []
|
|
30
|
+
},
|
|
31
|
+
defaultOptions: []
|
|
32
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
const types_1 = require("@typescript-eslint/types");
|
|
5
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
6
|
+
create: function (context) {
|
|
7
|
+
return {
|
|
8
|
+
CallExpression(node) {
|
|
9
|
+
const { callee, arguments: args } = node;
|
|
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) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
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) {
|
|
26
|
+
context.report({
|
|
27
|
+
node: depthProperty,
|
|
28
|
+
messageId: 'depthMessage'
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
meta: {
|
|
35
|
+
type: 'problem',
|
|
36
|
+
fixable: 'code',
|
|
37
|
+
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.'
|
|
39
|
+
},
|
|
40
|
+
schema: []
|
|
41
|
+
},
|
|
42
|
+
defaultOptions: []
|
|
43
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
|
+
exports.default = utils_1.ESLintUtils.RuleCreator.withoutDocs({
|
|
5
|
+
create(context) {
|
|
6
|
+
return {
|
|
7
|
+
CallExpression(node) {
|
|
8
|
+
const callee = node.callee;
|
|
9
|
+
if (callee.object &&
|
|
10
|
+
callee.object.name === 'Sentry' &&
|
|
11
|
+
callee.property &&
|
|
12
|
+
callee.property.name === 'init') {
|
|
13
|
+
const optionsArgument = node
|
|
14
|
+
.arguments[0];
|
|
15
|
+
if (optionsArgument && optionsArgument.type === 'ObjectExpression') {
|
|
16
|
+
optionsArgument.properties.forEach((property) => {
|
|
17
|
+
if (property.type === 'Property') {
|
|
18
|
+
const key = property.key.name;
|
|
19
|
+
if (key === 'dsn') {
|
|
20
|
+
const dsnValue = property.value;
|
|
21
|
+
if (dsnValue.type === 'Literal' && !dsnValue.value) {
|
|
22
|
+
context.report({
|
|
23
|
+
node: property,
|
|
24
|
+
messageId: 'invalidDsn'
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (dsnValue.type === 'MemberExpression') {
|
|
28
|
+
const objectName = dsnValue.object
|
|
29
|
+
.name;
|
|
30
|
+
const propertyName = dsnValue.property.name;
|
|
31
|
+
if (objectName === 'process' && propertyName === 'env') {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
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
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
meta: {
|
|
53
|
+
messages: {
|
|
54
|
+
invalidDsn: 'Sentry DSN should not be empty.',
|
|
55
|
+
incorrectTraceRate: 'Sentry tracesSampleRate should be set to 1.0.'
|
|
56
|
+
},
|
|
57
|
+
type: 'problem',
|
|
58
|
+
fixable: 'code',
|
|
59
|
+
schema: []
|
|
60
|
+
},
|
|
61
|
+
defaultOptions: []
|
|
62
|
+
});
|
package/dist/rules/index.js
CHANGED
|
@@ -14,6 +14,9 @@ const meta_data_import_1 = __importDefault(require("./meta-data-import"));
|
|
|
14
14
|
const check_middleware_order_1 = __importDefault(require("./check-middleware-order"));
|
|
15
15
|
const urls_without_slash_1 = __importDefault(require("./urls-without-slash"));
|
|
16
16
|
const invalid_imports_1 = __importDefault(require("./invalid-imports"));
|
|
17
|
+
const check_menu_depth_1 = __importDefault(require("./check-menu-depth"));
|
|
18
|
+
const case_warning_1 = __importDefault(require("./case-warning"));
|
|
19
|
+
const check_sentry_options_1 = __importDefault(require("./check-sentry-options"));
|
|
17
20
|
const rules = {
|
|
18
21
|
'client-url': client_url_1.default,
|
|
19
22
|
'image-import': image_import_1.default,
|
|
@@ -24,6 +27,9 @@ const rules = {
|
|
|
24
27
|
'meta-data-import': meta_data_import_1.default,
|
|
25
28
|
'check-middleware-order': check_middleware_order_1.default,
|
|
26
29
|
'urls-without-slash': urls_without_slash_1.default,
|
|
27
|
-
'invalid-imports': invalid_imports_1.default
|
|
30
|
+
'invalid-imports': invalid_imports_1.default,
|
|
31
|
+
'check-menu-depth': check_menu_depth_1.default,
|
|
32
|
+
'case-warning': case_warning_1.default,
|
|
33
|
+
'check-sentry-options': check_sentry_options_1.default
|
|
28
34
|
};
|
|
29
35
|
exports.rules = rules;
|
package/package.json
CHANGED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
import { TSESTree } from '@typescript-eslint/types';
|
|
3
|
+
|
|
4
|
+
type MessageIds = 'noLocale';
|
|
5
|
+
type Options = readonly [];
|
|
6
|
+
|
|
7
|
+
export default ESLintUtils.RuleCreator.withoutDocs<Options, MessageIds>({
|
|
8
|
+
create(context) {
|
|
9
|
+
return {
|
|
10
|
+
CallExpression(node: TSESTree.CallExpression) {
|
|
11
|
+
if (
|
|
12
|
+
node.callee.type === 'MemberExpression' &&
|
|
13
|
+
node.callee.property.type === 'Identifier' &&
|
|
14
|
+
(node.callee.property.name === 'toLocaleUpperCase' ||
|
|
15
|
+
node.callee.property.name === 'toLocaleLowerCase')
|
|
16
|
+
) {
|
|
17
|
+
const args = node.arguments;
|
|
18
|
+
|
|
19
|
+
if (args.length === 0) {
|
|
20
|
+
context.report({
|
|
21
|
+
node,
|
|
22
|
+
messageId: 'noLocale'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
meta: {
|
|
30
|
+
messages: {
|
|
31
|
+
noLocale:
|
|
32
|
+
'toLocaleUpperCase() or toLocaleLowerCase() should specify a locale for consistent behavior across different environments.'
|
|
33
|
+
},
|
|
34
|
+
type: 'problem',
|
|
35
|
+
fixable: 'code',
|
|
36
|
+
schema: []
|
|
37
|
+
},
|
|
38
|
+
defaultOptions: []
|
|
39
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
3
|
+
|
|
4
|
+
export default ESLintUtils.RuleCreator.withoutDocs({
|
|
5
|
+
create: function (context) {
|
|
6
|
+
return {
|
|
7
|
+
CallExpression(node) {
|
|
8
|
+
const { callee, arguments: args } = node;
|
|
9
|
+
|
|
10
|
+
if (
|
|
11
|
+
callee.type !== AST_NODE_TYPES.Identifier ||
|
|
12
|
+
callee.name !== 'getMenu' ||
|
|
13
|
+
args.length === 0 ||
|
|
14
|
+
args[0].type !== AST_NODE_TYPES.ObjectExpression
|
|
15
|
+
) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const depthProperty = args[0].properties.find(
|
|
20
|
+
(prop) =>
|
|
21
|
+
prop.type === AST_NODE_TYPES.Property &&
|
|
22
|
+
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
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (depthProperty) {
|
|
30
|
+
context.report({
|
|
31
|
+
node: depthProperty,
|
|
32
|
+
messageId: 'depthMessage'
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
meta: {
|
|
39
|
+
type: 'problem',
|
|
40
|
+
fixable: 'code',
|
|
41
|
+
messages: {
|
|
42
|
+
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.'
|
|
44
|
+
},
|
|
45
|
+
schema: []
|
|
46
|
+
},
|
|
47
|
+
defaultOptions: []
|
|
48
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
2
|
+
|
|
3
|
+
export default ESLintUtils.RuleCreator.withoutDocs({
|
|
4
|
+
create(context) {
|
|
5
|
+
return {
|
|
6
|
+
CallExpression(node: TSESTree.CallExpression) {
|
|
7
|
+
const callee = node.callee as TSESTree.MemberExpression;
|
|
8
|
+
|
|
9
|
+
if (
|
|
10
|
+
callee.object &&
|
|
11
|
+
(callee.object as TSESTree.Identifier).name === 'Sentry' &&
|
|
12
|
+
callee.property &&
|
|
13
|
+
(callee.property as TSESTree.Identifier).name === 'init'
|
|
14
|
+
) {
|
|
15
|
+
const optionsArgument = node
|
|
16
|
+
.arguments[0] as TSESTree.ObjectExpression;
|
|
17
|
+
|
|
18
|
+
if (optionsArgument && optionsArgument.type === 'ObjectExpression') {
|
|
19
|
+
optionsArgument.properties.forEach((property) => {
|
|
20
|
+
if (property.type === 'Property') {
|
|
21
|
+
const key = (property.key as TSESTree.Identifier).name;
|
|
22
|
+
|
|
23
|
+
if (key === 'dsn') {
|
|
24
|
+
const dsnValue = property.value;
|
|
25
|
+
|
|
26
|
+
if (dsnValue.type === 'Literal' && !dsnValue.value) {
|
|
27
|
+
context.report({
|
|
28
|
+
node: property,
|
|
29
|
+
messageId: 'invalidDsn'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (dsnValue.type === 'MemberExpression') {
|
|
34
|
+
const objectName = (dsnValue.object as TSESTree.Identifier)
|
|
35
|
+
.name;
|
|
36
|
+
const propertyName = (
|
|
37
|
+
dsnValue.property as TSESTree.Identifier
|
|
38
|
+
).name;
|
|
39
|
+
|
|
40
|
+
if (objectName === 'process' && propertyName === 'env') {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
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
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
meta: {
|
|
63
|
+
messages: {
|
|
64
|
+
invalidDsn: 'Sentry DSN should not be empty.',
|
|
65
|
+
incorrectTraceRate: 'Sentry tracesSampleRate should be set to 1.0.'
|
|
66
|
+
},
|
|
67
|
+
type: 'problem',
|
|
68
|
+
fixable: 'code',
|
|
69
|
+
schema: []
|
|
70
|
+
},
|
|
71
|
+
defaultOptions: []
|
|
72
|
+
});
|
package/rules/index.ts
CHANGED
|
@@ -8,6 +8,9 @@ import metaDataImport from './meta-data-import';
|
|
|
8
8
|
import checkMiddlewareOrder from './check-middleware-order';
|
|
9
9
|
import urlsWithoutSlash from './urls-without-slash';
|
|
10
10
|
import invalidImports from './invalid-imports';
|
|
11
|
+
import checkMenuDepth from './check-menu-depth';
|
|
12
|
+
import caseWarning from './case-warning';
|
|
13
|
+
import checkSentryOptions from './check-sentry-options';
|
|
11
14
|
|
|
12
15
|
const rules = {
|
|
13
16
|
'client-url': clientUrl,
|
|
@@ -19,7 +22,10 @@ const rules = {
|
|
|
19
22
|
'meta-data-import': metaDataImport,
|
|
20
23
|
'check-middleware-order': checkMiddlewareOrder,
|
|
21
24
|
'urls-without-slash': urlsWithoutSlash,
|
|
22
|
-
'invalid-imports': invalidImports
|
|
25
|
+
'invalid-imports': invalidImports,
|
|
26
|
+
'check-menu-depth': checkMenuDepth,
|
|
27
|
+
'case-warning': caseWarning,
|
|
28
|
+
'check-sentry-options': checkSentryOptions
|
|
23
29
|
};
|
|
24
30
|
|
|
25
31
|
export { rules };
|