@atlaskit/eslint-plugin-platform 0.6.1 → 0.7.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.
Files changed (126) hide show
  1. package/CHANGELOG.md +103 -28
  2. package/afm-jira/tsconfig.json +20 -0
  3. package/dist/cjs/index.js +48 -2
  4. package/dist/cjs/rules/constants.js +11 -0
  5. package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +54 -6
  6. package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +16 -7
  7. package/dist/cjs/rules/ensure-valid-emotion-css-prop/index.js +91 -0
  8. package/dist/cjs/rules/inline-usage/index.js +94 -0
  9. package/dist/cjs/rules/no-alias/index.js +64 -0
  10. package/dist/cjs/rules/no-module-level-eval/index.js +45 -0
  11. package/dist/cjs/rules/no-preconditioning/index.js +108 -0
  12. package/dist/cjs/rules/prefer-fg/index.js +106 -0
  13. package/dist/cjs/rules/static-feature-flags/index.js +63 -0
  14. package/dist/cjs/rules/use-recommended-utils/index.js +47 -0
  15. package/dist/cjs/rules/util/registration-utils.js +2 -1
  16. package/dist/cjs/rules/utils.js +53 -0
  17. package/dist/es2019/index.js +52 -2
  18. package/dist/es2019/rules/constants.js +5 -0
  19. package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +52 -6
  20. package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +15 -7
  21. package/dist/es2019/rules/ensure-valid-emotion-css-prop/index.js +87 -0
  22. package/dist/es2019/rules/inline-usage/index.js +90 -0
  23. package/dist/es2019/rules/no-alias/index.js +58 -0
  24. package/dist/es2019/rules/no-module-level-eval/index.js +39 -0
  25. package/dist/es2019/rules/no-preconditioning/index.js +105 -0
  26. package/dist/es2019/rules/prefer-fg/index.js +81 -0
  27. package/dist/es2019/rules/static-feature-flags/index.js +54 -0
  28. package/dist/es2019/rules/use-recommended-utils/index.js +41 -0
  29. package/dist/es2019/rules/util/registration-utils.js +2 -1
  30. package/dist/es2019/rules/utils.js +29 -0
  31. package/dist/esm/index.js +48 -2
  32. package/dist/esm/rules/constants.js +5 -0
  33. package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +54 -6
  34. package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +16 -7
  35. package/dist/esm/rules/ensure-valid-emotion-css-prop/index.js +85 -0
  36. package/dist/esm/rules/inline-usage/index.js +87 -0
  37. package/dist/esm/rules/no-alias/index.js +57 -0
  38. package/dist/esm/rules/no-module-level-eval/index.js +39 -0
  39. package/dist/esm/rules/no-preconditioning/index.js +102 -0
  40. package/dist/esm/rules/prefer-fg/index.js +99 -0
  41. package/dist/esm/rules/static-feature-flags/index.js +56 -0
  42. package/dist/esm/rules/use-recommended-utils/index.js +41 -0
  43. package/dist/esm/rules/util/registration-utils.js +2 -1
  44. package/dist/esm/rules/utils.js +45 -0
  45. package/dist/types/index.d.ts +15 -0
  46. package/dist/types/rules/constants.d.ts +3 -0
  47. package/dist/types/rules/ensure-valid-emotion-css-prop/index.d.ts +3 -0
  48. package/dist/types/rules/inline-usage/index.d.ts +3 -0
  49. package/dist/types/rules/no-alias/index.d.ts +3 -0
  50. package/dist/types/rules/no-module-level-eval/index.d.ts +3 -0
  51. package/dist/types/rules/no-preconditioning/index.d.ts +3 -0
  52. package/dist/types/rules/prefer-fg/index.d.ts +3 -0
  53. package/dist/types/rules/static-feature-flags/index.d.ts +3 -0
  54. package/dist/types/rules/use-recommended-utils/index.d.ts +3 -0
  55. package/dist/types/rules/util/registration-utils.d.ts +1 -0
  56. package/dist/types/rules/utils.d.ts +7 -0
  57. package/dist/types-ts4.5/index.d.ts +15 -0
  58. package/dist/types-ts4.5/rules/constants.d.ts +3 -0
  59. package/dist/types-ts4.5/rules/ensure-valid-emotion-css-prop/index.d.ts +3 -0
  60. package/dist/types-ts4.5/rules/inline-usage/index.d.ts +3 -0
  61. package/dist/types-ts4.5/rules/no-alias/index.d.ts +3 -0
  62. package/dist/types-ts4.5/rules/no-module-level-eval/index.d.ts +3 -0
  63. package/dist/types-ts4.5/rules/no-preconditioning/index.d.ts +3 -0
  64. package/dist/types-ts4.5/rules/prefer-fg/index.d.ts +3 -0
  65. package/dist/types-ts4.5/rules/static-feature-flags/index.d.ts +3 -0
  66. package/dist/types-ts4.5/rules/use-recommended-utils/index.d.ts +3 -0
  67. package/dist/types-ts4.5/rules/util/registration-utils.d.ts +1 -0
  68. package/dist/types-ts4.5/rules/utils.d.ts +7 -0
  69. package/index.js +9 -9
  70. package/package.json +43 -44
  71. package/report.api.md +31 -30
  72. package/src/__tests__/utils/_tester.tsx +16 -16
  73. package/src/index.tsx +102 -51
  74. package/src/rules/constants.tsx +20 -0
  75. package/src/rules/ensure-atlassian-team/__tests__/unit/rule.test.ts +19 -19
  76. package/src/rules/ensure-atlassian-team/index.ts +39 -52
  77. package/src/rules/ensure-critical-dependency-resolutions/__test__/unit/rule.test.tsx +146 -81
  78. package/src/rules/ensure-critical-dependency-resolutions/index.tsx +152 -97
  79. package/src/rules/ensure-feature-flag-prefix/__tests__/unit/rule.test.tsx +51 -51
  80. package/src/rules/ensure-feature-flag-prefix/index.tsx +65 -80
  81. package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +97 -97
  82. package/src/rules/ensure-feature-flag-registration/index.tsx +88 -105
  83. package/src/rules/ensure-native-and-af-exports-synced/__tests__/unit/rule.test.tsx +180 -180
  84. package/src/rules/ensure-native-and-af-exports-synced/index.tsx +162 -168
  85. package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +34 -36
  86. package/src/rules/ensure-publish-valid/index.ts +66 -81
  87. package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +93 -93
  88. package/src/rules/ensure-test-runner-arguments/index.tsx +107 -121
  89. package/src/rules/ensure-test-runner-nested-count/__tests__/unit/rule.test.tsx +43 -43
  90. package/src/rules/ensure-test-runner-nested-count/index.tsx +68 -70
  91. package/src/rules/ensure-valid-emotion-css-prop/__tests__/unit/rule.test.ts +142 -0
  92. package/src/rules/ensure-valid-emotion-css-prop/index.ts +96 -0
  93. package/src/rules/inline-usage/README.md +53 -0
  94. package/src/rules/inline-usage/__tests__/rule.test.tsx +106 -0
  95. package/src/rules/inline-usage/index.tsx +130 -0
  96. package/src/rules/no-alias/README.md +29 -0
  97. package/src/rules/no-alias/__tests__/rule.test.tsx +76 -0
  98. package/src/rules/no-alias/index.tsx +75 -0
  99. package/src/rules/no-duplicate-dependencies/__tests__/unit/rule.test.ts +44 -44
  100. package/src/rules/no-duplicate-dependencies/index.ts +68 -73
  101. package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +64 -64
  102. package/src/rules/no-invalid-feature-flag-usage/index.tsx +105 -112
  103. package/src/rules/no-invalid-storybook-decorator-usage/__tests__/unit/rule.test.tsx +13 -13
  104. package/src/rules/no-invalid-storybook-decorator-usage/index.tsx +28 -30
  105. package/src/rules/no-module-level-eval/README.md +53 -0
  106. package/src/rules/no-module-level-eval/__tests__/test.tsx +133 -0
  107. package/src/rules/no-module-level-eval/index.tsx +52 -0
  108. package/src/rules/no-pre-post-installs/__tests__/unit/rule.test.ts +36 -36
  109. package/src/rules/no-pre-post-installs/index.ts +27 -27
  110. package/src/rules/no-preconditioning/README.md +69 -0
  111. package/src/rules/no-preconditioning/__tests__/rule.test.tsx +164 -0
  112. package/src/rules/no-preconditioning/index.tsx +138 -0
  113. package/src/rules/prefer-fg/README.md +3 -0
  114. package/src/rules/prefer-fg/__tests__/rule.test.tsx +83 -0
  115. package/src/rules/prefer-fg/index.tsx +108 -0
  116. package/src/rules/static-feature-flags/README.md +3 -0
  117. package/src/rules/static-feature-flags/__tests__/test.tsx +135 -0
  118. package/src/rules/static-feature-flags/index.tsx +103 -0
  119. package/src/rules/use-recommended-utils/README.md +67 -0
  120. package/src/rules/use-recommended-utils/__tests__/rule.test.tsx +78 -0
  121. package/src/rules/use-recommended-utils/index.tsx +57 -0
  122. package/src/rules/util/handle-ast-object.ts +21 -32
  123. package/src/rules/util/registration-utils.ts +31 -30
  124. package/src/rules/utils.tsx +46 -0
  125. package/tsconfig.app.json +35 -35
  126. package/tsconfig.dev.json +39 -39
@@ -4,188 +4,182 @@ import path from 'path';
4
4
  import { getMetadataForFilename } from '../util/registration-utils';
5
5
 
6
6
  interface ExportsValidationExceptions {
7
- [key: string]: { ignoredAfExportKeys: string[] };
7
+ [key: string]: { ignoredAfExportKeys: string[] };
8
8
  }
9
9
 
10
10
  const exportsValidationExceptions: ExportsValidationExceptions = {
11
- '@atlassian/sizemap': {
12
- ignoredAfExportKeys: ['.', './lmdb-cache-manager'],
13
- },
14
- '@atlaskit/tokens': {
15
- ignoredAfExportKeys: ['./babel-plugin'],
16
- },
11
+ '@atlassian/sizemap': {
12
+ ignoredAfExportKeys: ['.', './lmdb-cache-manager'],
13
+ },
14
+ '@atlaskit/tokens': {
15
+ ignoredAfExportKeys: ['./babel-plugin'],
16
+ },
17
17
  };
18
18
 
19
19
  const rule: Rule.RuleModule = {
20
- meta: {
21
- docs: {
22
- recommended: false,
23
- },
24
- type: 'problem',
25
- messages: {
26
- missingExportsProperty: `The exports property must be defined for {{pkgName}}; it most likely can just be a duplicate of the "af:exports" property. See http://go/eslint-exports for details`,
27
- missingExportsKey: `Missing package.json exports key "{{expectedKey}}" in {{pkgName}}. The exports entry should be "{{expectedKey}}": "{{expectedValue}}". See http://go/eslint-exports for details`,
28
- unexpectedExportsKey: `Unexpected package.json exports key "{{key}}" in {{pkgName}}. The exports entry should be "{{expectedKey}}": "{{expectedValue}}". See http://go/eslint-exports for details`,
29
- unexpectedExportsValue: `Unexpected package.json exports value in {{pkgName}} for the "{{key}}" key. The exports entry should be "{{key}}": "{{expectedValue}}". See http://go/eslint-exports for details`,
30
- },
31
- },
32
-
33
- create(context) {
34
- const fileName = context.getFilename();
35
-
36
- if (!fileName.endsWith('package.json')) {
37
- return {};
38
- }
39
-
40
- const { pkgJson: packageJson } = getMetadataForFilename(fileName);
41
-
42
- const pkgName = packageJson.name;
43
-
44
- if (!pkgName || !packageJson['af:exports']) {
45
- return {};
46
- }
47
-
48
- if (!packageJson['exports']) {
49
- context.report({
50
- node: context.getSourceCode().ast,
51
- messageId: 'missingExportsProperty',
52
- data: { pkgName },
53
- });
54
- return {};
55
- }
56
-
57
- const afExports: { [key: string]: any } = packageJson['af:exports'];
58
- const nativeExports: { [key: string]: any } = packageJson['exports'];
59
-
60
- return {
61
- Program(node) {
62
- for (const [afExportsKey, afExportsValue] of Object.entries(
63
- afExports,
64
- )) {
65
- if (
66
- exportsValidationExceptions[pkgName]?.ignoredAfExportKeys.includes(
67
- afExportsKey,
68
- )
69
- ) {
70
- continue;
71
- }
72
-
73
- const exportKeyViolations = getExportKeyViolation(
74
- afExportsKey,
75
- afExportsValue,
76
- nativeExports,
77
- );
78
-
79
- if (exportKeyViolations) {
80
- context.report({
81
- data: { ...exportKeyViolations, key: afExportsKey, pkgName },
82
- node,
83
- messageId: exportKeyViolations.messageId,
84
- });
85
-
86
- continue;
87
- }
88
-
89
- const exportValueViolations = getExportValueViolation(
90
- pkgName,
91
- afExportsKey,
92
- afExportsValue,
93
- nativeExports,
94
- );
95
-
96
- if (exportValueViolations) {
97
- context.report({
98
- data: { ...exportValueViolations, pkgName },
99
- node,
100
- messageId: 'unexpectedExportsValue',
101
- });
102
-
103
- continue;
104
- }
105
- }
106
- },
107
- };
108
- },
20
+ meta: {
21
+ docs: {
22
+ recommended: false,
23
+ },
24
+ type: 'problem',
25
+ messages: {
26
+ missingExportsProperty: `The exports property must be defined for {{pkgName}}; it most likely can just be a duplicate of the "af:exports" property. See http://go/eslint-exports for details`,
27
+ missingExportsKey: `Missing package.json exports key "{{expectedKey}}" in {{pkgName}}. The exports entry should be "{{expectedKey}}": "{{expectedValue}}". See http://go/eslint-exports for details`,
28
+ unexpectedExportsKey: `Unexpected package.json exports key "{{key}}" in {{pkgName}}. The exports entry should be "{{expectedKey}}": "{{expectedValue}}". See http://go/eslint-exports for details`,
29
+ unexpectedExportsValue: `Unexpected package.json exports value in {{pkgName}} for the "{{key}}" key. The exports entry should be "{{key}}": "{{expectedValue}}". See http://go/eslint-exports for details`,
30
+ },
31
+ },
32
+
33
+ create(context) {
34
+ const fileName = context.getFilename();
35
+
36
+ if (!fileName.endsWith('package.json')) {
37
+ return {};
38
+ }
39
+
40
+ const { pkgJson: packageJson } = getMetadataForFilename(fileName);
41
+
42
+ const pkgName = packageJson.name;
43
+
44
+ if (!pkgName || !packageJson['af:exports']) {
45
+ return {};
46
+ }
47
+
48
+ if (!packageJson['exports']) {
49
+ context.report({
50
+ node: context.getSourceCode().ast,
51
+ messageId: 'missingExportsProperty',
52
+ data: { pkgName },
53
+ });
54
+ return {};
55
+ }
56
+
57
+ const afExports: { [key: string]: any } = packageJson['af:exports'];
58
+ const nativeExports: { [key: string]: any } = packageJson['exports'];
59
+
60
+ return {
61
+ Program(node) {
62
+ for (const [afExportsKey, afExportsValue] of Object.entries(afExports)) {
63
+ if (exportsValidationExceptions[pkgName]?.ignoredAfExportKeys.includes(afExportsKey)) {
64
+ continue;
65
+ }
66
+
67
+ const exportKeyViolations = getExportKeyViolation(
68
+ afExportsKey,
69
+ afExportsValue,
70
+ nativeExports,
71
+ );
72
+
73
+ if (exportKeyViolations) {
74
+ context.report({
75
+ data: { ...exportKeyViolations, key: afExportsKey, pkgName },
76
+ node,
77
+ messageId: exportKeyViolations.messageId,
78
+ });
79
+
80
+ continue;
81
+ }
82
+
83
+ const exportValueViolations = getExportValueViolation(
84
+ afExportsKey,
85
+ afExportsValue,
86
+ nativeExports,
87
+ );
88
+
89
+ if (exportValueViolations) {
90
+ context.report({
91
+ data: { ...exportValueViolations, pkgName },
92
+ node,
93
+ messageId: 'unexpectedExportsValue',
94
+ });
95
+
96
+ continue;
97
+ }
98
+ }
99
+ },
100
+ };
101
+ },
109
102
  };
110
103
 
111
104
  function getExportKeyViolation(
112
- afExportsKey: string,
113
- afExportsValue: string,
114
- nativeExports: { [key: string]: any },
105
+ afExportsKey: string,
106
+ afExportsValue: string,
107
+ nativeExports: { [key: string]: any },
115
108
  ) {
116
- const afExportsValueHasExtension = path.extname(afExportsValue);
117
-
118
- if (
119
- afExportsValueHasExtension &&
120
- !nativeExports.hasOwnProperty(afExportsKey)
121
- ) {
122
- return {
123
- messageId: 'missingExportsKey',
124
- expectedKey: afExportsKey,
125
- expectedValue: afExportsValue,
126
- };
127
- }
128
-
129
- if (
130
- !afExportsValueHasExtension &&
131
- nativeExports.hasOwnProperty(afExportsKey)
132
- ) {
133
- return {
134
- messageId: 'unexpectedExportsKey',
135
- expectedKey: `${afExportsKey}/*`,
136
- expectedValue: `${afExportsValue}/*`,
137
- };
138
- }
139
-
140
- if (
141
- !afExportsValueHasExtension &&
142
- !nativeExports.hasOwnProperty(`${afExportsKey}/*`)
143
- ) {
144
- return {
145
- messageId: 'missingExportsKey',
146
- expectedKey: `${afExportsKey}/*`,
147
- expectedValue: `${afExportsValue}/*`,
148
- };
149
- }
109
+ const afExportsValueHasExtension = path.extname(afExportsValue) !== '';
110
+
111
+ if (afExportsValueHasExtension && !nativeExports.hasOwnProperty(afExportsKey)) {
112
+ return {
113
+ messageId: 'missingExportsKey',
114
+ expectedKey: afExportsKey,
115
+ expectedValue: afExportsValue,
116
+ };
117
+ }
118
+
119
+ if (!afExportsValueHasExtension && nativeExports.hasOwnProperty(afExportsKey)) {
120
+ return {
121
+ messageId: 'unexpectedExportsKey',
122
+ expectedKey: `${afExportsKey}/*`,
123
+ expectedValue: `${afExportsValue}/*`,
124
+ };
125
+ }
126
+
127
+ if (!afExportsValueHasExtension && !nativeExports.hasOwnProperty(`${afExportsKey}/*`)) {
128
+ return {
129
+ messageId: 'missingExportsKey',
130
+ expectedKey: `${afExportsKey}/*`,
131
+ expectedValue: `${afExportsValue}/*`,
132
+ };
133
+ }
134
+ }
135
+
136
+ function getNativeExportsValue(
137
+ afExportsKey: string,
138
+ afExportsValueHasExtension: boolean,
139
+ nativeExports: { [key: string]: any },
140
+ ) {
141
+ const nativeExportsKey = afExportsValueHasExtension ? afExportsKey : `${afExportsKey}/*`;
142
+
143
+ if (typeof nativeExports[nativeExportsKey] === 'object') {
144
+ return nativeExports[nativeExportsKey].default;
145
+ }
146
+
147
+ return nativeExports[nativeExportsKey];
150
148
  }
151
149
 
152
150
  function getExportValueViolation(
153
- pkgName: string,
154
- afExportsKey: string,
155
- afExportsValue: string,
156
- nativeExports: { [key: string]: any },
151
+ afExportsKey: string,
152
+ afExportsValue: string,
153
+ nativeExports: { [key: string]: any },
157
154
  ) {
158
- const afExportsValueHasExtension = path.extname(afExportsValue);
159
-
160
- // Some entrypoints have been updated to an index.js file that registers ts-node
161
- // Use path.basename to get the file name to see if it is equal to 'index.js'
162
- if (
163
- afExportsValueHasExtension &&
164
- path.basename(nativeExports[afExportsKey]) === 'index.js'
165
- ) {
166
- return;
167
- }
168
-
169
- if (
170
- afExportsValueHasExtension &&
171
- nativeExports[afExportsKey] !== afExportsValue
172
- ) {
173
- return {
174
- key: afExportsKey,
175
- expectedValue: afExportsValue,
176
- };
177
- }
178
-
179
- // af:exports entrypoints without a file extension export the whole directory so check to ensure the exports value includes the wildcard
180
- if (
181
- !afExportsValueHasExtension &&
182
- !nativeExports[`${afExportsKey}/*`].startsWith(`${afExportsValue}/*`)
183
- ) {
184
- return {
185
- key: `${afExportsKey}/*`,
186
- expectedValue: `${afExportsValue}/*`,
187
- };
188
- }
155
+ const afExportsValueHasExtension = path.extname(afExportsValue) !== '';
156
+
157
+ const nativeExportsValue = getNativeExportsValue(
158
+ afExportsKey,
159
+ afExportsValueHasExtension,
160
+ nativeExports,
161
+ );
162
+
163
+ // Some entrypoints have been updated to an index.js file that registers ts-node
164
+ // Use path.basename to get the file name to see if it is equal to 'index.js'
165
+ if (afExportsValueHasExtension && path.basename(nativeExportsValue) === 'index.js') {
166
+ return;
167
+ }
168
+
169
+ if (afExportsValueHasExtension && nativeExportsValue !== afExportsValue) {
170
+ return {
171
+ key: afExportsKey,
172
+ expectedValue: afExportsValue,
173
+ };
174
+ }
175
+
176
+ // af:exports entrypoints without a file extension export the whole directory so check to ensure the exports value includes the wildcard
177
+ if (!afExportsValueHasExtension && !nativeExportsValue.startsWith(`${afExportsValue}/*`)) {
178
+ return {
179
+ key: `${afExportsKey}/*`,
180
+ expectedValue: `${afExportsValue}/*`,
181
+ };
182
+ }
189
183
  }
190
184
 
191
185
  export default rule;
@@ -2,40 +2,38 @@ import { tester } from '../../../../__tests__/utils/_tester';
2
2
  import rule from '../../index';
3
3
 
4
4
  describe('test ensure-publish-valid-rule', () => {
5
- tester.run('ensure-publish-valid', rule, {
6
- valid: [
7
- {
8
- code: `const foo = { "name": "@af/test" }`,
9
- filename: 'package.json',
10
- },
11
- {
12
- options: [{ exceptions: ['@atlaskit/test'] }],
13
- code: `const foo = { "name": "@atlaskit/test" }`,
14
- filename: 'package.json',
15
- },
16
- {
17
- code: `const foo = { "name": "@atlaskit/test", "private": false, "publishConfig": { "registry": "https://registry.npmjs.org/" } }`,
18
- filename: 'foo/package.json',
19
- },
20
- ],
21
- invalid: [
22
- {
23
- code: `const foo = { "name": "@atlaskit/test" }`,
24
- filename: 'foo/package.json',
25
- errors: [
26
- {
27
- messageId: 'publishConfigRequired',
28
- data: { packageName: '@atlaskit/test' },
29
- },
30
- ],
31
- },
32
- {
33
- code: `const foo = { "name": "@atlaskit/test", "private": true, "publishConfig": { "registry": "https://registry.npmjs.org/" } }`,
34
- filename: 'foo/package.json',
35
- errors: [
36
- { messageId: 'noPrivate', data: { packageName: '@atlaskit/test' } },
37
- ],
38
- },
39
- ],
40
- });
5
+ tester.run('ensure-publish-valid', rule, {
6
+ valid: [
7
+ {
8
+ code: `const foo = { "name": "@af/test" }`,
9
+ filename: 'package.json',
10
+ },
11
+ {
12
+ options: [{ exceptions: ['@atlaskit/test'] }],
13
+ code: `const foo = { "name": "@atlaskit/test" }`,
14
+ filename: 'package.json',
15
+ },
16
+ {
17
+ code: `const foo = { "name": "@atlaskit/test", "private": false, "publishConfig": { "registry": "https://registry.npmjs.org/" } }`,
18
+ filename: 'foo/package.json',
19
+ },
20
+ ],
21
+ invalid: [
22
+ {
23
+ code: `const foo = { "name": "@atlaskit/test" }`,
24
+ filename: 'foo/package.json',
25
+ errors: [
26
+ {
27
+ messageId: 'publishConfigRequired',
28
+ data: { packageName: '@atlaskit/test' },
29
+ },
30
+ ],
31
+ },
32
+ {
33
+ code: `const foo = { "name": "@atlaskit/test", "private": true, "publishConfig": { "registry": "https://registry.npmjs.org/" } }`,
34
+ filename: 'foo/package.json',
35
+ errors: [{ messageId: 'noPrivate', data: { packageName: '@atlaskit/test' } }],
36
+ },
37
+ ],
38
+ });
41
39
  });
@@ -1,96 +1,81 @@
1
1
  // eslint-disable-next-line import/no-extraneous-dependencies
2
2
  import type { Rule } from 'eslint';
3
- import {
4
- getObjectPropertyAsLiteral,
5
- getObjectPropertyAsObject,
6
- } from '../util/handle-ast-object';
3
+ import { getObjectPropertyAsLiteral, getObjectPropertyAsObject } from '../util/handle-ast-object';
7
4
 
8
5
  type RuleOptions = {
9
- // exceptions to this rule, will be ignored
10
- exceptions?: string[];
6
+ // exceptions to this rule, will be ignored
7
+ exceptions?: string[];
11
8
  };
12
9
 
13
10
  const rule: Rule.RuleModule = {
14
- meta: {
15
- type: 'problem',
16
- docs: {
17
- description:
18
- 'This rule ensures that the package.json for your packages are set up correctly for publishing depending on the package name prefix',
19
- recommended: true,
20
- },
21
- hasSuggestions: false,
22
- schema: [
23
- {
24
- type: 'object',
25
- properties: {
26
- exceptions: {
27
- type: 'array',
28
- items: [{ type: 'string' }],
29
- },
30
- },
31
- },
32
- ],
33
- messages: {
34
- publishConfigRequired:
35
- '@atlaskit prefix is public! You have to specify a `publishConfig`, (package {{packageName}}) see https://go.atlassian.com/package-namespace',
36
- noPrivate:
37
- 'setting private to true prevents publishing, your package prefix implies you want to publish! (package {{packageName}}) see https://go.atlassian.com/package-namespace',
38
- },
39
- },
40
- create(context) {
41
- const { exceptions } = (context.options?.[0] as RuleOptions) ?? {};
11
+ meta: {
12
+ type: 'problem',
13
+ docs: {
14
+ description:
15
+ 'This rule ensures that the package.json for your packages are set up correctly for publishing depending on the package name prefix',
16
+ recommended: true,
17
+ },
18
+ hasSuggestions: false,
19
+ schema: [
20
+ {
21
+ type: 'object',
22
+ properties: {
23
+ exceptions: {
24
+ type: 'array',
25
+ items: [{ type: 'string' }],
26
+ },
27
+ },
28
+ },
29
+ ],
30
+ messages: {
31
+ publishConfigRequired:
32
+ '@atlaskit prefix is public! You have to specify a `publishConfig`, (package {{packageName}}) see https://go.atlassian.com/package-namespace',
33
+ noPrivate:
34
+ 'setting private to true prevents publishing, your package prefix implies you want to publish! (package {{packageName}}) see https://go.atlassian.com/package-namespace',
35
+ },
36
+ },
37
+ create(context) {
38
+ const { exceptions } = (context.options?.[0] as RuleOptions) ?? {};
42
39
 
43
- return {
44
- ObjectExpression: (node: Rule.Node) => {
45
- if (
46
- !context.getFilename().endsWith('package.json') ||
47
- node.type !== 'ObjectExpression'
48
- ) {
49
- return;
50
- }
40
+ return {
41
+ ObjectExpression: (node: Rule.Node) => {
42
+ if (!context.getFilename().endsWith('package.json') || node.type !== 'ObjectExpression') {
43
+ return;
44
+ }
51
45
 
52
- const packageName = getObjectPropertyAsLiteral(node, 'name');
53
- const packagePrivate = getObjectPropertyAsLiteral(node, 'private');
54
- const packagePublishConfig = getObjectPropertyAsObject(
55
- node,
56
- 'publishConfig',
57
- );
46
+ const packageName = getObjectPropertyAsLiteral(node, 'name');
47
+ const packagePrivate = getObjectPropertyAsLiteral(node, 'private');
48
+ const packagePublishConfig = getObjectPropertyAsObject(node, 'publishConfig');
58
49
 
59
- // exit if package is on known exception list
60
- if (
61
- exceptions &&
62
- exceptions.findIndex((name) => name === packageName) !== -1
63
- ) {
64
- return;
65
- }
50
+ // exit if package is on known exception list
51
+ if (exceptions && exceptions.findIndex((name) => name === packageName) !== -1) {
52
+ return;
53
+ }
66
54
 
67
- if (
68
- typeof packageName === 'string' &&
69
- packageName.startsWith('@atlaskit')
70
- ) {
71
- if (typeof packagePrivate === 'boolean' && packagePrivate) {
72
- return context.report({
73
- node,
74
- messageId: 'noPrivate',
75
- data: {
76
- packageName,
77
- },
78
- });
79
- }
55
+ if (typeof packageName === 'string' && packageName.startsWith('@atlaskit')) {
56
+ if (typeof packagePrivate === 'boolean' && packagePrivate) {
57
+ return context.report({
58
+ node,
59
+ messageId: 'noPrivate',
60
+ data: {
61
+ packageName,
62
+ },
63
+ });
64
+ }
80
65
 
81
- if (packagePublishConfig === null) {
82
- return context.report({
83
- node,
84
- messageId: 'publishConfigRequired',
85
- data: {
86
- packageName,
87
- },
88
- });
89
- }
90
- }
91
- },
92
- };
93
- },
66
+ if (packagePublishConfig === null) {
67
+ return context.report({
68
+ node,
69
+ messageId: 'publishConfigRequired',
70
+ data: {
71
+ packageName,
72
+ },
73
+ });
74
+ }
75
+ }
76
+ },
77
+ };
78
+ },
94
79
  };
95
80
 
96
81
  export default rule;