@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.
- package/CHANGELOG.md +103 -28
- package/afm-jira/tsconfig.json +20 -0
- package/dist/cjs/index.js +48 -2
- package/dist/cjs/rules/constants.js +11 -0
- package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +54 -6
- package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +16 -7
- package/dist/cjs/rules/ensure-valid-emotion-css-prop/index.js +91 -0
- package/dist/cjs/rules/inline-usage/index.js +94 -0
- package/dist/cjs/rules/no-alias/index.js +64 -0
- package/dist/cjs/rules/no-module-level-eval/index.js +45 -0
- package/dist/cjs/rules/no-preconditioning/index.js +108 -0
- package/dist/cjs/rules/prefer-fg/index.js +106 -0
- package/dist/cjs/rules/static-feature-flags/index.js +63 -0
- package/dist/cjs/rules/use-recommended-utils/index.js +47 -0
- package/dist/cjs/rules/util/registration-utils.js +2 -1
- package/dist/cjs/rules/utils.js +53 -0
- package/dist/es2019/index.js +52 -2
- package/dist/es2019/rules/constants.js +5 -0
- package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +52 -6
- package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +15 -7
- package/dist/es2019/rules/ensure-valid-emotion-css-prop/index.js +87 -0
- package/dist/es2019/rules/inline-usage/index.js +90 -0
- package/dist/es2019/rules/no-alias/index.js +58 -0
- package/dist/es2019/rules/no-module-level-eval/index.js +39 -0
- package/dist/es2019/rules/no-preconditioning/index.js +105 -0
- package/dist/es2019/rules/prefer-fg/index.js +81 -0
- package/dist/es2019/rules/static-feature-flags/index.js +54 -0
- package/dist/es2019/rules/use-recommended-utils/index.js +41 -0
- package/dist/es2019/rules/util/registration-utils.js +2 -1
- package/dist/es2019/rules/utils.js +29 -0
- package/dist/esm/index.js +48 -2
- package/dist/esm/rules/constants.js +5 -0
- package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +54 -6
- package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +16 -7
- package/dist/esm/rules/ensure-valid-emotion-css-prop/index.js +85 -0
- package/dist/esm/rules/inline-usage/index.js +87 -0
- package/dist/esm/rules/no-alias/index.js +57 -0
- package/dist/esm/rules/no-module-level-eval/index.js +39 -0
- package/dist/esm/rules/no-preconditioning/index.js +102 -0
- package/dist/esm/rules/prefer-fg/index.js +99 -0
- package/dist/esm/rules/static-feature-flags/index.js +56 -0
- package/dist/esm/rules/use-recommended-utils/index.js +41 -0
- package/dist/esm/rules/util/registration-utils.js +2 -1
- package/dist/esm/rules/utils.js +45 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/rules/constants.d.ts +3 -0
- package/dist/types/rules/ensure-valid-emotion-css-prop/index.d.ts +3 -0
- package/dist/types/rules/inline-usage/index.d.ts +3 -0
- package/dist/types/rules/no-alias/index.d.ts +3 -0
- package/dist/types/rules/no-module-level-eval/index.d.ts +3 -0
- package/dist/types/rules/no-preconditioning/index.d.ts +3 -0
- package/dist/types/rules/prefer-fg/index.d.ts +3 -0
- package/dist/types/rules/static-feature-flags/index.d.ts +3 -0
- package/dist/types/rules/use-recommended-utils/index.d.ts +3 -0
- package/dist/types/rules/util/registration-utils.d.ts +1 -0
- package/dist/types/rules/utils.d.ts +7 -0
- package/dist/types-ts4.5/index.d.ts +15 -0
- package/dist/types-ts4.5/rules/constants.d.ts +3 -0
- package/dist/types-ts4.5/rules/ensure-valid-emotion-css-prop/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/inline-usage/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-alias/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-module-level-eval/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-preconditioning/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/prefer-fg/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/static-feature-flags/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-recommended-utils/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/util/registration-utils.d.ts +1 -0
- package/dist/types-ts4.5/rules/utils.d.ts +7 -0
- package/index.js +9 -9
- package/package.json +43 -44
- package/report.api.md +31 -30
- package/src/__tests__/utils/_tester.tsx +16 -16
- package/src/index.tsx +102 -51
- package/src/rules/constants.tsx +20 -0
- package/src/rules/ensure-atlassian-team/__tests__/unit/rule.test.ts +19 -19
- package/src/rules/ensure-atlassian-team/index.ts +39 -52
- package/src/rules/ensure-critical-dependency-resolutions/__test__/unit/rule.test.tsx +146 -81
- package/src/rules/ensure-critical-dependency-resolutions/index.tsx +152 -97
- package/src/rules/ensure-feature-flag-prefix/__tests__/unit/rule.test.tsx +51 -51
- package/src/rules/ensure-feature-flag-prefix/index.tsx +65 -80
- package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +97 -97
- package/src/rules/ensure-feature-flag-registration/index.tsx +88 -105
- package/src/rules/ensure-native-and-af-exports-synced/__tests__/unit/rule.test.tsx +180 -180
- package/src/rules/ensure-native-and-af-exports-synced/index.tsx +162 -168
- package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +34 -36
- package/src/rules/ensure-publish-valid/index.ts +66 -81
- package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +93 -93
- package/src/rules/ensure-test-runner-arguments/index.tsx +107 -121
- package/src/rules/ensure-test-runner-nested-count/__tests__/unit/rule.test.tsx +43 -43
- package/src/rules/ensure-test-runner-nested-count/index.tsx +68 -70
- package/src/rules/ensure-valid-emotion-css-prop/__tests__/unit/rule.test.ts +142 -0
- package/src/rules/ensure-valid-emotion-css-prop/index.ts +96 -0
- package/src/rules/inline-usage/README.md +53 -0
- package/src/rules/inline-usage/__tests__/rule.test.tsx +106 -0
- package/src/rules/inline-usage/index.tsx +130 -0
- package/src/rules/no-alias/README.md +29 -0
- package/src/rules/no-alias/__tests__/rule.test.tsx +76 -0
- package/src/rules/no-alias/index.tsx +75 -0
- package/src/rules/no-duplicate-dependencies/__tests__/unit/rule.test.ts +44 -44
- package/src/rules/no-duplicate-dependencies/index.ts +68 -73
- package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +64 -64
- package/src/rules/no-invalid-feature-flag-usage/index.tsx +105 -112
- package/src/rules/no-invalid-storybook-decorator-usage/__tests__/unit/rule.test.tsx +13 -13
- package/src/rules/no-invalid-storybook-decorator-usage/index.tsx +28 -30
- package/src/rules/no-module-level-eval/README.md +53 -0
- package/src/rules/no-module-level-eval/__tests__/test.tsx +133 -0
- package/src/rules/no-module-level-eval/index.tsx +52 -0
- package/src/rules/no-pre-post-installs/__tests__/unit/rule.test.ts +36 -36
- package/src/rules/no-pre-post-installs/index.ts +27 -27
- package/src/rules/no-preconditioning/README.md +69 -0
- package/src/rules/no-preconditioning/__tests__/rule.test.tsx +164 -0
- package/src/rules/no-preconditioning/index.tsx +138 -0
- package/src/rules/prefer-fg/README.md +3 -0
- package/src/rules/prefer-fg/__tests__/rule.test.tsx +83 -0
- package/src/rules/prefer-fg/index.tsx +108 -0
- package/src/rules/static-feature-flags/README.md +3 -0
- package/src/rules/static-feature-flags/__tests__/test.tsx +135 -0
- package/src/rules/static-feature-flags/index.tsx +103 -0
- package/src/rules/use-recommended-utils/README.md +67 -0
- package/src/rules/use-recommended-utils/__tests__/rule.test.tsx +78 -0
- package/src/rules/use-recommended-utils/index.tsx +57 -0
- package/src/rules/util/handle-ast-object.ts +21 -32
- package/src/rules/util/registration-utils.ts +31 -30
- package/src/rules/utils.tsx +46 -0
- package/tsconfig.app.json +35 -35
- 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
|
-
|
|
7
|
+
[key: string]: { ignoredAfExportKeys: string[] };
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
const exportsValidationExceptions: ExportsValidationExceptions = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
105
|
+
afExportsKey: string,
|
|
106
|
+
afExportsValue: string,
|
|
107
|
+
nativeExports: { [key: string]: any },
|
|
115
108
|
) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
nativeExports: { [key: string]: any },
|
|
151
|
+
afExportsKey: string,
|
|
152
|
+
afExportsValue: string,
|
|
153
|
+
nativeExports: { [key: string]: any },
|
|
157
154
|
) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
10
|
-
|
|
6
|
+
// exceptions to this rule, will be ignored
|
|
7
|
+
exceptions?: string[];
|
|
11
8
|
};
|
|
12
9
|
|
|
13
10
|
const rule: Rule.RuleModule = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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;
|