@akinon/eslint-plugin-projectzero 1.47.0-rc.2 → 1.47.0-rc.4

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,13 @@
1
1
  # @akinon/eslint-plugin-projectzero
2
2
 
3
+ ## 1.47.0-rc.4
4
+
5
+ ## 1.47.0-rc.3
6
+
7
+ ### Minor Changes
8
+
9
+ - 4d64ef7: ZERO-2611: Add check-sentry-options rule to eslint-plugin-projectzero
10
+
3
11
  ## 1.47.0-rc.2
4
12
 
5
13
  ## 1.47.0-rc.1
package/configs/core.ts CHANGED
@@ -11,6 +11,7 @@ export default {
11
11
  '@akinon/projectzero/invalid-imports': 'error',
12
12
  '@akinon/projectzero/check-menu-depth': 'error',
13
13
  '@akinon/projectzero/case-warning': 'warn',
14
+ '@akinon/projectzero/check-sentry-options': 'error',
14
15
  'no-restricted-syntax': [
15
16
  'error',
16
17
  {
@@ -1,24 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', { value: true });
3
3
  exports.default = {
4
- rules: {
5
- '@akinon/projectzero/image-import': 'error',
6
- '@akinon/projectzero/client-url': 'error',
7
- '@akinon/projectzero/link-import': 'error',
8
- '@akinon/projectzero/router-import': 'error',
9
- '@akinon/projectzero/skip-trailing-slash-redirect': 'error',
10
- '@akinon/projectzero/check-locale': 'error',
11
- '@akinon/projectzero/meta-data-import': 'error',
12
- '@akinon/projectzero/urls-without-slash': 'error',
13
- '@akinon/projectzero/invalid-imports': 'error',
14
- '@akinon/projectzero/check-menu-depth': 'error',
15
- '@akinon/projectzero/case-warning': 'warn',
16
- 'no-restricted-syntax': [
17
- 'error',
18
- {
19
- selector: "MemberExpression[property.name='COMMERCE_URL'][object.property.name='env'][object.object.name='process']",
20
- message: "You should use it as 'Settings.commerceUrl'"
21
- }
22
- ]
23
- }
4
+ rules: {
5
+ '@akinon/projectzero/image-import': 'error',
6
+ '@akinon/projectzero/client-url': 'error',
7
+ '@akinon/projectzero/link-import': 'error',
8
+ '@akinon/projectzero/router-import': 'error',
9
+ '@akinon/projectzero/skip-trailing-slash-redirect': 'error',
10
+ '@akinon/projectzero/check-locale': 'error',
11
+ '@akinon/projectzero/meta-data-import': 'error',
12
+ '@akinon/projectzero/urls-without-slash': 'error',
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',
17
+ 'no-restricted-syntax': [
18
+ 'error',
19
+ {
20
+ selector:
21
+ "MemberExpression[property.name='COMMERCE_URL'][object.property.name='env'][object.object.name='process']",
22
+ message: "You should use it as 'Settings.commerceUrl'"
23
+ }
24
+ ]
25
+ }
24
26
  };
@@ -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
+ });
@@ -1,33 +1,43 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ 'use strict';
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, '__esModule', { value: true });
6
8
  exports.rules = void 0;
7
- const client_url_1 = __importDefault(require("./client-url"));
8
- const image_import_1 = __importDefault(require("./image-import"));
9
- const link_import_1 = __importDefault(require("./link-import"));
10
- const router_import_1 = __importDefault(require("./router-import"));
11
- const skip_trailing_slash_redirect_1 = __importDefault(require("./skip-trailing-slash-redirect"));
12
- const check_locale_1 = __importDefault(require("./check-locale"));
13
- const meta_data_import_1 = __importDefault(require("./meta-data-import"));
14
- const check_middleware_order_1 = __importDefault(require("./check-middleware-order"));
15
- const urls_without_slash_1 = __importDefault(require("./urls-without-slash"));
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"));
9
+ const client_url_1 = __importDefault(require('./client-url'));
10
+ const image_import_1 = __importDefault(require('./image-import'));
11
+ const link_import_1 = __importDefault(require('./link-import'));
12
+ const router_import_1 = __importDefault(require('./router-import'));
13
+ const skip_trailing_slash_redirect_1 = __importDefault(
14
+ require('./skip-trailing-slash-redirect')
15
+ );
16
+ const check_locale_1 = __importDefault(require('./check-locale'));
17
+ const meta_data_import_1 = __importDefault(require('./meta-data-import'));
18
+ const check_middleware_order_1 = __importDefault(
19
+ require('./check-middleware-order')
20
+ );
21
+ const urls_without_slash_1 = __importDefault(require('./urls-without-slash'));
22
+ const invalid_imports_1 = __importDefault(require('./invalid-imports'));
23
+ const check_menu_depth_1 = __importDefault(require('./check-menu-depth'));
24
+ const case_warning_1 = __importDefault(require('./case-warning'));
25
+ const check_sentry_options_1 = __importDefault(
26
+ require('./check-sentry-options')
27
+ );
19
28
  const rules = {
20
- 'client-url': client_url_1.default,
21
- 'image-import': image_import_1.default,
22
- 'link-import': link_import_1.default,
23
- 'router-import': router_import_1.default,
24
- 'skip-trailing-slash-redirect': skip_trailing_slash_redirect_1.default,
25
- 'check-locale': check_locale_1.default,
26
- 'meta-data-import': meta_data_import_1.default,
27
- 'check-middleware-order': check_middleware_order_1.default,
28
- 'urls-without-slash': urls_without_slash_1.default,
29
- 'invalid-imports': invalid_imports_1.default,
30
- 'check-menu-depth': check_menu_depth_1.default,
31
- 'case-warning': case_warning_1.default
29
+ 'client-url': client_url_1.default,
30
+ 'image-import': image_import_1.default,
31
+ 'link-import': link_import_1.default,
32
+ 'router-import': router_import_1.default,
33
+ 'skip-trailing-slash-redirect': skip_trailing_slash_redirect_1.default,
34
+ 'check-locale': check_locale_1.default,
35
+ 'meta-data-import': meta_data_import_1.default,
36
+ 'check-middleware-order': check_middleware_order_1.default,
37
+ 'urls-without-slash': urls_without_slash_1.default,
38
+ 'invalid-imports': invalid_imports_1.default,
39
+ 'check-menu-depth': check_menu_depth_1.default,
40
+ 'case-warning': case_warning_1.default,
41
+ 'check-sentry-options': check_sentry_options_1.default
32
42
  };
33
43
  exports.rules = rules;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/eslint-plugin-projectzero",
3
- "version": "1.47.0-rc.2",
3
+ "version": "1.47.0-rc.4",
4
4
  "private": false,
5
5
  "description": "ESLint plugin for Project Zero Next",
6
6
  "main": "dist/index.js",
@@ -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
@@ -10,6 +10,7 @@ import urlsWithoutSlash from './urls-without-slash';
10
10
  import invalidImports from './invalid-imports';
11
11
  import checkMenuDepth from './check-menu-depth';
12
12
  import caseWarning from './case-warning';
13
+ import checkSentryOptions from './check-sentry-options';
13
14
 
14
15
  const rules = {
15
16
  'client-url': clientUrl,
@@ -23,7 +24,8 @@ const rules = {
23
24
  'urls-without-slash': urlsWithoutSlash,
24
25
  'invalid-imports': invalidImports,
25
26
  'check-menu-depth': checkMenuDepth,
26
- 'case-warning': caseWarning
27
+ 'case-warning': caseWarning,
28
+ 'check-sentry-options': checkSentryOptions
27
29
  };
28
30
 
29
31
  export { rules };