@atlaskit/eslint-plugin-platform 0.2.4 → 0.2.5
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/cjs/index.js +3 -1
- package/dist/cjs/rules/ensure-publish-valid/index.js +99 -0
- package/dist/es2019/index.js +3 -1
- package/dist/es2019/rules/ensure-publish-valid/index.js +87 -0
- package/dist/esm/index.js +3 -1
- package/dist/esm/rules/ensure-publish-valid/index.js +92 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/rules/ensure-publish-valid/index.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/rules/ensure-publish-valid/index.d.ts +3 -0
- package/package.json +1 -1
- package/report.api.md +1 -0
- package/src/index.tsx +2 -0
- package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +41 -0
- package/src/rules/ensure-publish-valid/index.ts +134 -0
- package/tmp/api-report-tmp.d.ts +1 -0
- package/dist/cjs/version.json +0 -5
- package/dist/es2019/version.json +0 -5
- package/dist/esm/version.json +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 0.2.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`e5f52093b2a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e5f52093b2a) - Add a rule to ensure that publish config is correct for packages
|
|
8
|
+
|
|
3
9
|
## 0.2.4
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var _ensureAtlassianTeam = _interopRequireDefault(require("./rules/ensure-atlass
|
|
|
13
13
|
var _noInvalidFeatureFlagUsage = _interopRequireDefault(require("./rules/no-invalid-feature-flag-usage"));
|
|
14
14
|
var _ensureFeatureFlagPrefix = _interopRequireDefault(require("./rules/ensure-feature-flag-prefix"));
|
|
15
15
|
var _noInvalidStorybookDecoratorUsage = _interopRequireDefault(require("./rules/no-invalid-storybook-decorator-usage"));
|
|
16
|
+
var _ensurePublishValid = _interopRequireDefault(require("./rules/ensure-publish-valid"));
|
|
16
17
|
var rules = {
|
|
17
18
|
'ensure-feature-flag-registration': _ensureFeatureFlagRegistration.default,
|
|
18
19
|
'ensure-feature-flag-prefix': _ensureFeatureFlagPrefix.default,
|
|
@@ -21,7 +22,8 @@ var rules = {
|
|
|
21
22
|
'ensure-atlassian-team': _ensureAtlassianTeam.default,
|
|
22
23
|
'no-invalid-feature-flag-usage': _noInvalidFeatureFlagUsage.default,
|
|
23
24
|
'no-pre-post-install-scripts': _noPrePostInstalls.default,
|
|
24
|
-
'no-invalid-storybook-decorator-usage': _noInvalidStorybookDecoratorUsage.default
|
|
25
|
+
'no-invalid-storybook-decorator-usage': _noInvalidStorybookDecoratorUsage.default,
|
|
26
|
+
'ensure-publish-valid': _ensurePublishValid.default
|
|
25
27
|
};
|
|
26
28
|
exports.rules = rules;
|
|
27
29
|
var configs = {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var getObjectPropertyAsLiteral = function getObjectPropertyAsLiteral(node, property) {
|
|
8
|
+
var prop = node.properties.find(function (p) {
|
|
9
|
+
return p.type === 'Property' && p.key.type === 'Literal' && p.key.value === property;
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// double check for property is to make typescript happy
|
|
13
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'Property' && (prop === null || prop === void 0 ? void 0 : prop.value.type) === 'Literal') {
|
|
14
|
+
var _prop$value$value;
|
|
15
|
+
return (_prop$value$value = prop.value.value) !== null && _prop$value$value !== void 0 ? _prop$value$value : null;
|
|
16
|
+
}
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
19
|
+
var getObjectPropertyAsObject = function getObjectPropertyAsObject(node, property) {
|
|
20
|
+
var prop = node.properties.find(function (p) {
|
|
21
|
+
return p.type === 'Property' && p.key.type === 'Literal' && p.key.value === property;
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// double check for property is to make typescript happy
|
|
25
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'Property' && (prop === null || prop === void 0 ? void 0 : prop.value.type) === 'ObjectExpression') {
|
|
26
|
+
var _prop$value;
|
|
27
|
+
return (_prop$value = prop.value) !== null && _prop$value !== void 0 ? _prop$value : null;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
var rule = {
|
|
32
|
+
meta: {
|
|
33
|
+
type: 'problem',
|
|
34
|
+
docs: {
|
|
35
|
+
description: 'This rule ensures that the package.json for your packages are set up correctly for publishing depending on the package name prefix',
|
|
36
|
+
recommended: true
|
|
37
|
+
},
|
|
38
|
+
hasSuggestions: false,
|
|
39
|
+
schema: [{
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
exceptions: {
|
|
43
|
+
type: 'array',
|
|
44
|
+
items: [{
|
|
45
|
+
type: 'string'
|
|
46
|
+
}]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}],
|
|
50
|
+
messages: {
|
|
51
|
+
publishConfigRequired: '@atlaskit prefix is public! You have to specify a `publishConfig`, (package {{packageName}}) see https://go.atlassian.com/package-namespace',
|
|
52
|
+
noPrivate: 'setting private to true prevents publishing, your package prefix implies you want to publish! (package {{packageName}}) see https://go.atlassian.com/package-namespace'
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
create: function create(context) {
|
|
56
|
+
var _ref2, _context$options;
|
|
57
|
+
var _ref = (_ref2 = (_context$options = context.options) === null || _context$options === void 0 ? void 0 : _context$options[0]) !== null && _ref2 !== void 0 ? _ref2 : {},
|
|
58
|
+
exceptions = _ref.exceptions;
|
|
59
|
+
return {
|
|
60
|
+
ObjectExpression: function ObjectExpression(node) {
|
|
61
|
+
if (!context.getFilename().endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var packageName = getObjectPropertyAsLiteral(node, 'name');
|
|
65
|
+
var packagePrivate = getObjectPropertyAsLiteral(node, 'private');
|
|
66
|
+
var packagePublishConfig = getObjectPropertyAsObject(node, 'publishConfig');
|
|
67
|
+
|
|
68
|
+
// exit if package is on known exception list
|
|
69
|
+
if (exceptions && exceptions.findIndex(function (name) {
|
|
70
|
+
return name === packageName;
|
|
71
|
+
}) !== -1) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (typeof packageName === 'string' && packageName.startsWith('@atlaskit')) {
|
|
75
|
+
if (typeof packagePrivate === 'boolean' && packagePrivate) {
|
|
76
|
+
return context.report({
|
|
77
|
+
node: node,
|
|
78
|
+
messageId: 'noPrivate',
|
|
79
|
+
data: {
|
|
80
|
+
packageName: packageName
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (packagePublishConfig === null) {
|
|
85
|
+
return context.report({
|
|
86
|
+
node: node,
|
|
87
|
+
messageId: 'publishConfigRequired',
|
|
88
|
+
data: {
|
|
89
|
+
packageName: packageName
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
var _default = rule;
|
|
99
|
+
exports.default = _default;
|
package/dist/es2019/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import ensureAtlassianTeam from './rules/ensure-atlassian-team';
|
|
|
6
6
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
7
7
|
import ensureFeatureFlagPrefix from './rules/ensure-feature-flag-prefix';
|
|
8
8
|
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
9
|
+
import ensurePublishValid from './rules/ensure-publish-valid';
|
|
9
10
|
export const rules = {
|
|
10
11
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
11
12
|
'ensure-feature-flag-prefix': ensureFeatureFlagPrefix,
|
|
@@ -14,7 +15,8 @@ export const rules = {
|
|
|
14
15
|
'ensure-atlassian-team': ensureAtlassianTeam,
|
|
15
16
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
16
17
|
'no-pre-post-install-scripts': noPreAndPostInstallScripts,
|
|
17
|
-
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage
|
|
18
|
+
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage,
|
|
19
|
+
'ensure-publish-valid': ensurePublishValid
|
|
18
20
|
};
|
|
19
21
|
export const configs = {
|
|
20
22
|
recommended: {
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const getObjectPropertyAsLiteral = (node, property) => {
|
|
2
|
+
const prop = node.properties.find(p => p.type === 'Property' && p.key.type === 'Literal' && p.key.value === property);
|
|
3
|
+
|
|
4
|
+
// double check for property is to make typescript happy
|
|
5
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'Property' && (prop === null || prop === void 0 ? void 0 : prop.value.type) === 'Literal') {
|
|
6
|
+
var _prop$value$value;
|
|
7
|
+
return (_prop$value$value = prop.value.value) !== null && _prop$value$value !== void 0 ? _prop$value$value : null;
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
};
|
|
11
|
+
const getObjectPropertyAsObject = (node, property) => {
|
|
12
|
+
const prop = node.properties.find(p => p.type === 'Property' && p.key.type === 'Literal' && p.key.value === property);
|
|
13
|
+
|
|
14
|
+
// double check for property is to make typescript happy
|
|
15
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'Property' && (prop === null || prop === void 0 ? void 0 : prop.value.type) === 'ObjectExpression') {
|
|
16
|
+
var _prop$value;
|
|
17
|
+
return (_prop$value = prop.value) !== null && _prop$value !== void 0 ? _prop$value : null;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
const rule = {
|
|
22
|
+
meta: {
|
|
23
|
+
type: 'problem',
|
|
24
|
+
docs: {
|
|
25
|
+
description: 'This rule ensures that the package.json for your packages are set up correctly for publishing depending on the package name prefix',
|
|
26
|
+
recommended: true
|
|
27
|
+
},
|
|
28
|
+
hasSuggestions: false,
|
|
29
|
+
schema: [{
|
|
30
|
+
type: 'object',
|
|
31
|
+
properties: {
|
|
32
|
+
exceptions: {
|
|
33
|
+
type: 'array',
|
|
34
|
+
items: [{
|
|
35
|
+
type: 'string'
|
|
36
|
+
}]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}],
|
|
40
|
+
messages: {
|
|
41
|
+
publishConfigRequired: '@atlaskit prefix is public! You have to specify a `publishConfig`, (package {{packageName}}) see https://go.atlassian.com/package-namespace',
|
|
42
|
+
noPrivate: 'setting private to true prevents publishing, your package prefix implies you want to publish! (package {{packageName}}) see https://go.atlassian.com/package-namespace'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
create(context) {
|
|
46
|
+
var _ref, _context$options;
|
|
47
|
+
const {
|
|
48
|
+
exceptions
|
|
49
|
+
} = (_ref = (_context$options = context.options) === null || _context$options === void 0 ? void 0 : _context$options[0]) !== null && _ref !== void 0 ? _ref : {};
|
|
50
|
+
return {
|
|
51
|
+
ObjectExpression: node => {
|
|
52
|
+
if (!context.getFilename().endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const packageName = getObjectPropertyAsLiteral(node, 'name');
|
|
56
|
+
const packagePrivate = getObjectPropertyAsLiteral(node, 'private');
|
|
57
|
+
const packagePublishConfig = getObjectPropertyAsObject(node, 'publishConfig');
|
|
58
|
+
|
|
59
|
+
// exit if package is on known exception list
|
|
60
|
+
if (exceptions && exceptions.findIndex(name => name === packageName) !== -1) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof packageName === 'string' && packageName.startsWith('@atlaskit')) {
|
|
64
|
+
if (typeof packagePrivate === 'boolean' && packagePrivate) {
|
|
65
|
+
return context.report({
|
|
66
|
+
node,
|
|
67
|
+
messageId: 'noPrivate',
|
|
68
|
+
data: {
|
|
69
|
+
packageName
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (packagePublishConfig === null) {
|
|
74
|
+
return context.report({
|
|
75
|
+
node,
|
|
76
|
+
messageId: 'publishConfigRequired',
|
|
77
|
+
data: {
|
|
78
|
+
packageName
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export default rule;
|
package/dist/esm/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import ensureAtlassianTeam from './rules/ensure-atlassian-team';
|
|
|
6
6
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
7
7
|
import ensureFeatureFlagPrefix from './rules/ensure-feature-flag-prefix';
|
|
8
8
|
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
9
|
+
import ensurePublishValid from './rules/ensure-publish-valid';
|
|
9
10
|
export var rules = {
|
|
10
11
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
11
12
|
'ensure-feature-flag-prefix': ensureFeatureFlagPrefix,
|
|
@@ -14,7 +15,8 @@ export var rules = {
|
|
|
14
15
|
'ensure-atlassian-team': ensureAtlassianTeam,
|
|
15
16
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
16
17
|
'no-pre-post-install-scripts': noPreAndPostInstallScripts,
|
|
17
|
-
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage
|
|
18
|
+
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage,
|
|
19
|
+
'ensure-publish-valid': ensurePublishValid
|
|
18
20
|
};
|
|
19
21
|
export var configs = {
|
|
20
22
|
recommended: {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var getObjectPropertyAsLiteral = function getObjectPropertyAsLiteral(node, property) {
|
|
2
|
+
var prop = node.properties.find(function (p) {
|
|
3
|
+
return p.type === 'Property' && p.key.type === 'Literal' && p.key.value === property;
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
// double check for property is to make typescript happy
|
|
7
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'Property' && (prop === null || prop === void 0 ? void 0 : prop.value.type) === 'Literal') {
|
|
8
|
+
var _prop$value$value;
|
|
9
|
+
return (_prop$value$value = prop.value.value) !== null && _prop$value$value !== void 0 ? _prop$value$value : null;
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
var getObjectPropertyAsObject = function getObjectPropertyAsObject(node, property) {
|
|
14
|
+
var prop = node.properties.find(function (p) {
|
|
15
|
+
return p.type === 'Property' && p.key.type === 'Literal' && p.key.value === property;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// double check for property is to make typescript happy
|
|
19
|
+
if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'Property' && (prop === null || prop === void 0 ? void 0 : prop.value.type) === 'ObjectExpression') {
|
|
20
|
+
var _prop$value;
|
|
21
|
+
return (_prop$value = prop.value) !== null && _prop$value !== void 0 ? _prop$value : null;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
};
|
|
25
|
+
var rule = {
|
|
26
|
+
meta: {
|
|
27
|
+
type: 'problem',
|
|
28
|
+
docs: {
|
|
29
|
+
description: 'This rule ensures that the package.json for your packages are set up correctly for publishing depending on the package name prefix',
|
|
30
|
+
recommended: true
|
|
31
|
+
},
|
|
32
|
+
hasSuggestions: false,
|
|
33
|
+
schema: [{
|
|
34
|
+
type: 'object',
|
|
35
|
+
properties: {
|
|
36
|
+
exceptions: {
|
|
37
|
+
type: 'array',
|
|
38
|
+
items: [{
|
|
39
|
+
type: 'string'
|
|
40
|
+
}]
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}],
|
|
44
|
+
messages: {
|
|
45
|
+
publishConfigRequired: '@atlaskit prefix is public! You have to specify a `publishConfig`, (package {{packageName}}) see https://go.atlassian.com/package-namespace',
|
|
46
|
+
noPrivate: 'setting private to true prevents publishing, your package prefix implies you want to publish! (package {{packageName}}) see https://go.atlassian.com/package-namespace'
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
create: function create(context) {
|
|
50
|
+
var _ref2, _context$options;
|
|
51
|
+
var _ref = (_ref2 = (_context$options = context.options) === null || _context$options === void 0 ? void 0 : _context$options[0]) !== null && _ref2 !== void 0 ? _ref2 : {},
|
|
52
|
+
exceptions = _ref.exceptions;
|
|
53
|
+
return {
|
|
54
|
+
ObjectExpression: function ObjectExpression(node) {
|
|
55
|
+
if (!context.getFilename().endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
var packageName = getObjectPropertyAsLiteral(node, 'name');
|
|
59
|
+
var packagePrivate = getObjectPropertyAsLiteral(node, 'private');
|
|
60
|
+
var packagePublishConfig = getObjectPropertyAsObject(node, 'publishConfig');
|
|
61
|
+
|
|
62
|
+
// exit if package is on known exception list
|
|
63
|
+
if (exceptions && exceptions.findIndex(function (name) {
|
|
64
|
+
return name === packageName;
|
|
65
|
+
}) !== -1) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (typeof packageName === 'string' && packageName.startsWith('@atlaskit')) {
|
|
69
|
+
if (typeof packagePrivate === 'boolean' && packagePrivate) {
|
|
70
|
+
return context.report({
|
|
71
|
+
node: node,
|
|
72
|
+
messageId: 'noPrivate',
|
|
73
|
+
data: {
|
|
74
|
+
packageName: packageName
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (packagePublishConfig === null) {
|
|
79
|
+
return context.report({
|
|
80
|
+
node: node,
|
|
81
|
+
messageId: 'publishConfigRequired',
|
|
82
|
+
data: {
|
|
83
|
+
packageName: packageName
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
export default rule;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const rules: {
|
|
|
8
8
|
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
|
9
9
|
'no-pre-post-install-scripts': import("eslint").Rule.RuleModule;
|
|
10
10
|
'no-invalid-storybook-decorator-usage': import("eslint").Rule.RuleModule;
|
|
11
|
+
'ensure-publish-valid': import("eslint").Rule.RuleModule;
|
|
11
12
|
};
|
|
12
13
|
export declare const configs: {
|
|
13
14
|
recommended: {
|
|
@@ -8,6 +8,7 @@ export declare const rules: {
|
|
|
8
8
|
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
|
9
9
|
'no-pre-post-install-scripts': import("eslint").Rule.RuleModule;
|
|
10
10
|
'no-invalid-storybook-decorator-usage': import("eslint").Rule.RuleModule;
|
|
11
|
+
'ensure-publish-valid': import("eslint").Rule.RuleModule;
|
|
11
12
|
};
|
|
12
13
|
export declare const configs: {
|
|
13
14
|
recommended: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-platform",
|
|
3
3
|
"description": "The essential plugin for use with Atlassian frontend platform tools",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.5",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
package/report.api.md
CHANGED
|
@@ -54,6 +54,7 @@ export const rules: {
|
|
|
54
54
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
55
55
|
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
56
56
|
'no-invalid-storybook-decorator-usage': Rule.RuleModule;
|
|
57
|
+
'ensure-publish-valid': Rule.RuleModule;
|
|
57
58
|
};
|
|
58
59
|
|
|
59
60
|
// (No @packageDocumentation comment for this package)
|
package/src/index.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import ensureAtlassianTeam from './rules/ensure-atlassian-team';
|
|
|
7
7
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
8
8
|
import ensureFeatureFlagPrefix from './rules/ensure-feature-flag-prefix';
|
|
9
9
|
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
10
|
+
import ensurePublishValid from './rules/ensure-publish-valid';
|
|
10
11
|
|
|
11
12
|
export const rules = {
|
|
12
13
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
@@ -17,6 +18,7 @@ export const rules = {
|
|
|
17
18
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
18
19
|
'no-pre-post-install-scripts': noPreAndPostInstallScripts,
|
|
19
20
|
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage,
|
|
21
|
+
'ensure-publish-valid': ensurePublishValid,
|
|
20
22
|
};
|
|
21
23
|
|
|
22
24
|
export const configs = {
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { tester } from '../../../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../../index';
|
|
3
|
+
|
|
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
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type {
|
|
3
|
+
ObjectExpression,
|
|
4
|
+
SimpleLiteral,
|
|
5
|
+
RegExpLiteral,
|
|
6
|
+
BigIntLiteral,
|
|
7
|
+
} from 'estree';
|
|
8
|
+
const getObjectPropertyAsLiteral = (
|
|
9
|
+
node: ObjectExpression,
|
|
10
|
+
property: string,
|
|
11
|
+
): SimpleLiteral['value'] | RegExpLiteral['value'] | BigIntLiteral['value'] => {
|
|
12
|
+
const prop = node.properties.find(
|
|
13
|
+
(p) =>
|
|
14
|
+
p.type === 'Property' &&
|
|
15
|
+
p.key.type === 'Literal' &&
|
|
16
|
+
p.key.value === property,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
// double check for property is to make typescript happy
|
|
20
|
+
if (prop?.type === 'Property' && prop?.value.type === 'Literal') {
|
|
21
|
+
return prop.value.value ?? null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const getObjectPropertyAsObject = (
|
|
28
|
+
node: ObjectExpression,
|
|
29
|
+
property: string,
|
|
30
|
+
): ObjectExpression | null => {
|
|
31
|
+
const prop = node.properties.find(
|
|
32
|
+
(p) =>
|
|
33
|
+
p.type === 'Property' &&
|
|
34
|
+
p.key.type === 'Literal' &&
|
|
35
|
+
p.key.value === property,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// double check for property is to make typescript happy
|
|
39
|
+
if (prop?.type === 'Property' && prop?.value.type === 'ObjectExpression') {
|
|
40
|
+
return prop.value ?? null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type RuleOptions = {
|
|
47
|
+
// exceptions to this rule, will be ignored
|
|
48
|
+
exceptions?: string[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const rule: Rule.RuleModule = {
|
|
52
|
+
meta: {
|
|
53
|
+
type: 'problem',
|
|
54
|
+
docs: {
|
|
55
|
+
description:
|
|
56
|
+
'This rule ensures that the package.json for your packages are set up correctly for publishing depending on the package name prefix',
|
|
57
|
+
recommended: true,
|
|
58
|
+
},
|
|
59
|
+
hasSuggestions: false,
|
|
60
|
+
schema: [
|
|
61
|
+
{
|
|
62
|
+
type: 'object',
|
|
63
|
+
properties: {
|
|
64
|
+
exceptions: {
|
|
65
|
+
type: 'array',
|
|
66
|
+
items: [{ type: 'string' }],
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
messages: {
|
|
72
|
+
publishConfigRequired:
|
|
73
|
+
'@atlaskit prefix is public! You have to specify a `publishConfig`, (package {{packageName}}) see https://go.atlassian.com/package-namespace',
|
|
74
|
+
noPrivate:
|
|
75
|
+
'setting private to true prevents publishing, your package prefix implies you want to publish! (package {{packageName}}) see https://go.atlassian.com/package-namespace',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
create(context) {
|
|
79
|
+
const { exceptions } = (context.options?.[0] as RuleOptions) ?? {};
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
ObjectExpression: (node: Rule.Node) => {
|
|
83
|
+
if (
|
|
84
|
+
!context.getFilename().endsWith('package.json') ||
|
|
85
|
+
node.type !== 'ObjectExpression'
|
|
86
|
+
) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const packageName = getObjectPropertyAsLiteral(node, 'name');
|
|
91
|
+
const packagePrivate = getObjectPropertyAsLiteral(node, 'private');
|
|
92
|
+
const packagePublishConfig = getObjectPropertyAsObject(
|
|
93
|
+
node,
|
|
94
|
+
'publishConfig',
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// exit if package is on known exception list
|
|
98
|
+
if (
|
|
99
|
+
exceptions &&
|
|
100
|
+
exceptions.findIndex((name) => name === packageName) !== -1
|
|
101
|
+
) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (
|
|
106
|
+
typeof packageName === 'string' &&
|
|
107
|
+
packageName.startsWith('@atlaskit')
|
|
108
|
+
) {
|
|
109
|
+
if (typeof packagePrivate === 'boolean' && packagePrivate) {
|
|
110
|
+
return context.report({
|
|
111
|
+
node,
|
|
112
|
+
messageId: 'noPrivate',
|
|
113
|
+
data: {
|
|
114
|
+
packageName,
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (packagePublishConfig === null) {
|
|
120
|
+
return context.report({
|
|
121
|
+
node,
|
|
122
|
+
messageId: 'publishConfigRequired',
|
|
123
|
+
data: {
|
|
124
|
+
packageName,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export default rule;
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export const rules: {
|
|
|
40
40
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
41
41
|
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
42
42
|
'no-invalid-storybook-decorator-usage': Rule.RuleModule;
|
|
43
|
+
'ensure-publish-valid': Rule.RuleModule;
|
|
43
44
|
};
|
|
44
45
|
|
|
45
46
|
// (No @packageDocumentation comment for this package)
|
package/dist/cjs/version.json
DELETED
package/dist/es2019/version.json
DELETED