@atlaskit/eslint-plugin-platform 0.2.4 → 0.2.6
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 +12 -0
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +87 -0
- package/dist/cjs/rules/ensure-feature-flag-registration/index.js +2 -2
- package/dist/cjs/rules/ensure-publish-valid/index.js +76 -0
- package/dist/cjs/rules/ensure-test-runner-nested-count/index.js +2 -2
- package/dist/cjs/rules/util/handle-ast-object.js +32 -0
- package/dist/es2019/index.js +5 -1
- package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +64 -0
- package/dist/es2019/rules/ensure-publish-valid/index.js +68 -0
- package/dist/es2019/rules/util/handle-ast-object.js +20 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +80 -0
- package/dist/esm/rules/ensure-feature-flag-registration/index.js +2 -2
- package/dist/esm/rules/ensure-publish-valid/index.js +69 -0
- package/dist/esm/rules/ensure-test-runner-nested-count/index.js +2 -2
- package/dist/esm/rules/util/handle-ast-object.js +24 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/rules/ensure-critical-dependency-resolutions/index.d.ts +3 -0
- package/dist/types/rules/ensure-publish-valid/index.d.ts +3 -0
- package/dist/types/rules/util/handle-ast-object.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/ensure-critical-dependency-resolutions/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/ensure-publish-valid/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/util/handle-ast-object.d.ts +3 -0
- package/package.json +2 -1
- package/report.api.md +2 -0
- package/src/index.tsx +4 -0
- package/src/rules/ensure-critical-dependency-resolutions/__test__/unit/rule.test.tsx +125 -0
- package/src/rules/ensure-critical-dependency-resolutions/index.tsx +113 -0
- package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +41 -0
- package/src/rules/ensure-publish-valid/index.ts +95 -0
- package/src/rules/util/handle-ast-object.ts +44 -0
- package/tmp/api-report-tmp.d.ts +2 -0
- package/tsconfig.app.json +36 -0
- package/tsconfig.dev.json +40 -0
- package/dist/cjs/version.json +0 -5
- package/dist/es2019/version.json +0 -5
- package/dist/esm/version.json +0 -5
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export 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
|
+
export 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
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export declare const rules: {
|
|
|
5
5
|
'ensure-test-runner-arguments': import("eslint").Rule.RuleModule;
|
|
6
6
|
'ensure-test-runner-nested-count': import("eslint").Rule.RuleModule;
|
|
7
7
|
'ensure-atlassian-team': import("eslint").Rule.RuleModule;
|
|
8
|
+
'ensure-critical-dependency-resolutions': import("eslint").Rule.RuleModule;
|
|
8
9
|
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
|
9
10
|
'no-pre-post-install-scripts': import("eslint").Rule.RuleModule;
|
|
10
11
|
'no-invalid-storybook-decorator-usage': import("eslint").Rule.RuleModule;
|
|
12
|
+
'ensure-publish-valid': import("eslint").Rule.RuleModule;
|
|
11
13
|
};
|
|
12
14
|
export declare const configs: {
|
|
13
15
|
recommended: {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ObjectExpression, SimpleLiteral, RegExpLiteral, BigIntLiteral } from 'estree';
|
|
2
|
+
export declare const getObjectPropertyAsLiteral: (node: ObjectExpression, property: string) => SimpleLiteral['value'] | RegExpLiteral['value'] | BigIntLiteral['value'];
|
|
3
|
+
export declare const getObjectPropertyAsObject: (node: ObjectExpression, property: string) => ObjectExpression | null;
|
|
@@ -5,9 +5,11 @@ export declare const rules: {
|
|
|
5
5
|
'ensure-test-runner-arguments': import("eslint").Rule.RuleModule;
|
|
6
6
|
'ensure-test-runner-nested-count': import("eslint").Rule.RuleModule;
|
|
7
7
|
'ensure-atlassian-team': import("eslint").Rule.RuleModule;
|
|
8
|
+
'ensure-critical-dependency-resolutions': import("eslint").Rule.RuleModule;
|
|
8
9
|
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
|
9
10
|
'no-pre-post-install-scripts': import("eslint").Rule.RuleModule;
|
|
10
11
|
'no-invalid-storybook-decorator-usage': import("eslint").Rule.RuleModule;
|
|
12
|
+
'ensure-publish-valid': import("eslint").Rule.RuleModule;
|
|
11
13
|
};
|
|
12
14
|
export declare const configs: {
|
|
13
15
|
recommended: {
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ObjectExpression, SimpleLiteral, RegExpLiteral, BigIntLiteral } from 'estree';
|
|
2
|
+
export declare const getObjectPropertyAsLiteral: (node: ObjectExpression, property: string) => SimpleLiteral['value'] | RegExpLiteral['value'] | BigIntLiteral['value'];
|
|
3
|
+
export declare const getObjectPropertyAsObject: (node: ObjectExpression, property: string) => ObjectExpression | null;
|
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.6",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.0.0",
|
|
34
|
+
"@manypkg/find-root": "^1.1.0",
|
|
34
35
|
"fuse.js": "^6.6.2",
|
|
35
36
|
"read-pkg-up": "^7.0.1"
|
|
36
37
|
},
|
package/report.api.md
CHANGED
|
@@ -51,9 +51,11 @@ export const rules: {
|
|
|
51
51
|
'ensure-test-runner-arguments': Rule.RuleModule;
|
|
52
52
|
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
53
53
|
'ensure-atlassian-team': Rule.RuleModule;
|
|
54
|
+
'ensure-critical-dependency-resolutions': Rule.RuleModule;
|
|
54
55
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
55
56
|
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
56
57
|
'no-invalid-storybook-decorator-usage': Rule.RuleModule;
|
|
58
|
+
'ensure-publish-valid': Rule.RuleModule;
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
// (No @packageDocumentation comment for this package)
|
package/src/index.tsx
CHANGED
|
@@ -6,7 +6,9 @@ import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count
|
|
|
6
6
|
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
|
+
import ensureCriticalDependencyResolutions from './rules/ensure-critical-dependency-resolutions';
|
|
9
10
|
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
11
|
+
import ensurePublishValid from './rules/ensure-publish-valid';
|
|
10
12
|
|
|
11
13
|
export const rules = {
|
|
12
14
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
@@ -14,9 +16,11 @@ export const rules = {
|
|
|
14
16
|
'ensure-test-runner-arguments': ensureTestRunnerArguments,
|
|
15
17
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
16
18
|
'ensure-atlassian-team': ensureAtlassianTeam,
|
|
19
|
+
'ensure-critical-dependency-resolutions': ensureCriticalDependencyResolutions,
|
|
17
20
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
18
21
|
'no-pre-post-install-scripts': noPreAndPostInstallScripts,
|
|
19
22
|
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage,
|
|
23
|
+
'ensure-publish-valid': ensurePublishValid,
|
|
20
24
|
};
|
|
21
25
|
|
|
22
26
|
export const configs = {
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { tester } from '../../../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../../index';
|
|
3
|
+
|
|
4
|
+
const cwd = process.cwd();
|
|
5
|
+
|
|
6
|
+
describe('test ensure-critical-dependency-resolutions rule', () => {
|
|
7
|
+
tester.run('ensure-critical-dependency-resolutions', rule, {
|
|
8
|
+
valid: [
|
|
9
|
+
// Root package.json, have all of the correct resolutions
|
|
10
|
+
{
|
|
11
|
+
code: `const foo = {
|
|
12
|
+
"resolutions": {
|
|
13
|
+
"@types/react": "16.14.15",
|
|
14
|
+
"typescript": "4.9.5",
|
|
15
|
+
}
|
|
16
|
+
}`,
|
|
17
|
+
filename: `${cwd}/package.json`,
|
|
18
|
+
},
|
|
19
|
+
// Root package.json, have all of the correct resolutions with ~
|
|
20
|
+
{
|
|
21
|
+
code: `const foo = {
|
|
22
|
+
"resolutions": {
|
|
23
|
+
"@types/react": "~16.14.25",
|
|
24
|
+
"typescript": "~4.9.8",
|
|
25
|
+
}
|
|
26
|
+
}`,
|
|
27
|
+
filename: `${cwd}/package.json`,
|
|
28
|
+
},
|
|
29
|
+
// Individual package's package.json. Have part of correct resolutions
|
|
30
|
+
{
|
|
31
|
+
code: `const foo = {
|
|
32
|
+
"resolutions": {
|
|
33
|
+
"@types/react": "16.14.15",
|
|
34
|
+
}
|
|
35
|
+
}`,
|
|
36
|
+
filename: `${cwd}/package/name/package.json`,
|
|
37
|
+
},
|
|
38
|
+
// Individual package's package.json. Not have relevant package resolutions
|
|
39
|
+
{
|
|
40
|
+
code: `const foo = {
|
|
41
|
+
"resolutions": {
|
|
42
|
+
"@types/abcd": "1.2.3",
|
|
43
|
+
}
|
|
44
|
+
}`,
|
|
45
|
+
filename: `${cwd}/package/name/package.json`,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
invalid: [
|
|
49
|
+
// Root package.json. One package is correct, the other is missing
|
|
50
|
+
{
|
|
51
|
+
code: `const foo = {
|
|
52
|
+
"resolutions": {
|
|
53
|
+
"typescript": "~4.9.8",
|
|
54
|
+
}
|
|
55
|
+
}`,
|
|
56
|
+
filename: `${cwd}/package.json`,
|
|
57
|
+
errors: [
|
|
58
|
+
{
|
|
59
|
+
messageId: 'invalidPackageResolution',
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
// Root package.json. Both packages have the wrong version ranges
|
|
64
|
+
{
|
|
65
|
+
code: `const foo = {
|
|
66
|
+
"resolutions": {
|
|
67
|
+
"@types/react": "16.8.25",
|
|
68
|
+
"typescript": "4.5.8",
|
|
69
|
+
}
|
|
70
|
+
}`,
|
|
71
|
+
filename: `${cwd}/package.json`,
|
|
72
|
+
errors: [
|
|
73
|
+
{
|
|
74
|
+
messageId: 'invalidPackageResolution',
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
// Root package.json. One package is correct, the other has wrong version range
|
|
79
|
+
{
|
|
80
|
+
code: `const foo = {
|
|
81
|
+
"resolutions": {
|
|
82
|
+
"@types/react": "~16.14.25",
|
|
83
|
+
"typescript": "~4.5.8",
|
|
84
|
+
}
|
|
85
|
+
}`,
|
|
86
|
+
filename: `${cwd}/package.json`,
|
|
87
|
+
errors: [
|
|
88
|
+
{
|
|
89
|
+
messageId: 'invalidPackageResolution',
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
// Root package.json. One package is correct, the other has ^ in its version
|
|
94
|
+
{
|
|
95
|
+
code: `const foo = {
|
|
96
|
+
"resolutions": {
|
|
97
|
+
"@types/react": "~16.14.25",
|
|
98
|
+
"typescript": "^4.9.5",
|
|
99
|
+
}
|
|
100
|
+
}`,
|
|
101
|
+
filename: `${cwd}/package.json`,
|
|
102
|
+
errors: [
|
|
103
|
+
{
|
|
104
|
+
messageId: 'invalidPackageResolution',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
// Individual package's package.json. One package is correct, the other is wrong
|
|
109
|
+
{
|
|
110
|
+
code: `const foo = {
|
|
111
|
+
"resolutions": {
|
|
112
|
+
"@types/react": "16.14.15",
|
|
113
|
+
"typescript": "4.5.8",
|
|
114
|
+
}
|
|
115
|
+
}`,
|
|
116
|
+
filename: `${cwd}/packages/packge/directory/package.json`,
|
|
117
|
+
errors: [
|
|
118
|
+
{
|
|
119
|
+
messageId: 'invalidPackageResolution',
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { findRootSync } from '@manypkg/find-root';
|
|
2
|
+
import type { Rule } from 'eslint';
|
|
3
|
+
import type { ObjectExpression } from 'estree';
|
|
4
|
+
import { getObjectPropertyAsObject } from '../util/handle-ast-object';
|
|
5
|
+
|
|
6
|
+
// Here we only need to specify the major and minor versions
|
|
7
|
+
// In matchMinorVersion, we will check if the versions in resolutions fall in the right ranges.
|
|
8
|
+
const DESIRED_PKG_VERSIONS: Record<string, string> = {
|
|
9
|
+
typescript: '4.9',
|
|
10
|
+
'@types/react': '16.14',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const matchMinorVersion = (
|
|
14
|
+
desiredVersion: string,
|
|
15
|
+
versionInResolutions: string,
|
|
16
|
+
): boolean => {
|
|
17
|
+
const firstChar = versionInResolutions[0];
|
|
18
|
+
// The version is invalid if it doesn't start with a number or ~
|
|
19
|
+
if (!/^\d$/.test(firstChar) && firstChar !== '~') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
versionInResolutions.startsWith(desiredVersion) ||
|
|
25
|
+
versionInResolutions.startsWith('~' + desiredVersion)
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const verifyResolutionFromObject = (
|
|
30
|
+
node: ObjectExpression,
|
|
31
|
+
pkg: string,
|
|
32
|
+
version: string,
|
|
33
|
+
optional: boolean,
|
|
34
|
+
): boolean => {
|
|
35
|
+
// For root package.json, we require the critical packages' resolutions exist and with matching version
|
|
36
|
+
// For individual package's package.json, it's ok if resolutions don't exist. But if they do, the version should match
|
|
37
|
+
const resolutionExist = node.properties.some(
|
|
38
|
+
(p) =>
|
|
39
|
+
p.type === 'Property' && p.key.type === 'Literal' && p.key.value === pkg,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (!resolutionExist) {
|
|
43
|
+
return optional;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const resolutionExistAndMatch = node.properties.some(
|
|
47
|
+
(p) =>
|
|
48
|
+
p.type === 'Property' &&
|
|
49
|
+
p.key.type === 'Literal' &&
|
|
50
|
+
p.key.value === pkg &&
|
|
51
|
+
p.value.type === 'Literal' &&
|
|
52
|
+
matchMinorVersion(version, p.value.value as string),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return resolutionExistAndMatch;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const rule: Rule.RuleModule = {
|
|
59
|
+
meta: {
|
|
60
|
+
type: 'problem',
|
|
61
|
+
docs: {
|
|
62
|
+
description:
|
|
63
|
+
'Enforce the versions of critical packages are within desired ranges by checking resolutions section in package.json',
|
|
64
|
+
recommended: true,
|
|
65
|
+
},
|
|
66
|
+
hasSuggestions: false,
|
|
67
|
+
messages: {
|
|
68
|
+
invalidPackageResolution: `Make sure the resolutions for the following packages match major and minor version ranges ${JSON.stringify(
|
|
69
|
+
DESIRED_PKG_VERSIONS,
|
|
70
|
+
)}`,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
create(context) {
|
|
74
|
+
const fileName = context.getFilename();
|
|
75
|
+
return {
|
|
76
|
+
ObjectExpression: (node: Rule.Node) => {
|
|
77
|
+
if (
|
|
78
|
+
!fileName.endsWith('package.json') ||
|
|
79
|
+
node.type !== 'ObjectExpression'
|
|
80
|
+
) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const packageResolutions = getObjectPropertyAsObject(
|
|
85
|
+
node,
|
|
86
|
+
'resolutions',
|
|
87
|
+
);
|
|
88
|
+
const rootDir = findRootSync(process.cwd());
|
|
89
|
+
const isRootPackageJson = fileName.endsWith(`${rootDir}/package.json`);
|
|
90
|
+
|
|
91
|
+
if (packageResolutions !== null) {
|
|
92
|
+
for (const [key, value] of Object.entries(DESIRED_PKG_VERSIONS)) {
|
|
93
|
+
if (
|
|
94
|
+
!verifyResolutionFromObject(
|
|
95
|
+
packageResolutions as ObjectExpression,
|
|
96
|
+
key,
|
|
97
|
+
value,
|
|
98
|
+
!isRootPackageJson,
|
|
99
|
+
)
|
|
100
|
+
) {
|
|
101
|
+
return context.report({
|
|
102
|
+
node,
|
|
103
|
+
messageId: 'invalidPackageResolution',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export default rule;
|
|
@@ -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,95 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import {
|
|
3
|
+
getObjectPropertyAsLiteral,
|
|
4
|
+
getObjectPropertyAsObject,
|
|
5
|
+
} from '../util/handle-ast-object';
|
|
6
|
+
|
|
7
|
+
type RuleOptions = {
|
|
8
|
+
// exceptions to this rule, will be ignored
|
|
9
|
+
exceptions?: string[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const rule: Rule.RuleModule = {
|
|
13
|
+
meta: {
|
|
14
|
+
type: 'problem',
|
|
15
|
+
docs: {
|
|
16
|
+
description:
|
|
17
|
+
'This rule ensures that the package.json for your packages are set up correctly for publishing depending on the package name prefix',
|
|
18
|
+
recommended: true,
|
|
19
|
+
},
|
|
20
|
+
hasSuggestions: false,
|
|
21
|
+
schema: [
|
|
22
|
+
{
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
exceptions: {
|
|
26
|
+
type: 'array',
|
|
27
|
+
items: [{ type: 'string' }],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
messages: {
|
|
33
|
+
publishConfigRequired:
|
|
34
|
+
'@atlaskit prefix is public! You have to specify a `publishConfig`, (package {{packageName}}) see https://go.atlassian.com/package-namespace',
|
|
35
|
+
noPrivate:
|
|
36
|
+
'setting private to true prevents publishing, your package prefix implies you want to publish! (package {{packageName}}) see https://go.atlassian.com/package-namespace',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
create(context) {
|
|
40
|
+
const { exceptions } = (context.options?.[0] as RuleOptions) ?? {};
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
ObjectExpression: (node: Rule.Node) => {
|
|
44
|
+
if (
|
|
45
|
+
!context.getFilename().endsWith('package.json') ||
|
|
46
|
+
node.type !== 'ObjectExpression'
|
|
47
|
+
) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const packageName = getObjectPropertyAsLiteral(node, 'name');
|
|
52
|
+
const packagePrivate = getObjectPropertyAsLiteral(node, 'private');
|
|
53
|
+
const packagePublishConfig = getObjectPropertyAsObject(
|
|
54
|
+
node,
|
|
55
|
+
'publishConfig',
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// exit if package is on known exception list
|
|
59
|
+
if (
|
|
60
|
+
exceptions &&
|
|
61
|
+
exceptions.findIndex((name) => name === packageName) !== -1
|
|
62
|
+
) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (
|
|
67
|
+
typeof packageName === 'string' &&
|
|
68
|
+
packageName.startsWith('@atlaskit')
|
|
69
|
+
) {
|
|
70
|
+
if (typeof packagePrivate === 'boolean' && packagePrivate) {
|
|
71
|
+
return context.report({
|
|
72
|
+
node,
|
|
73
|
+
messageId: 'noPrivate',
|
|
74
|
+
data: {
|
|
75
|
+
packageName,
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (packagePublishConfig === null) {
|
|
81
|
+
return context.report({
|
|
82
|
+
node,
|
|
83
|
+
messageId: 'publishConfigRequired',
|
|
84
|
+
data: {
|
|
85
|
+
packageName,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export default rule;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ObjectExpression,
|
|
3
|
+
SimpleLiteral,
|
|
4
|
+
RegExpLiteral,
|
|
5
|
+
BigIntLiteral,
|
|
6
|
+
} from 'estree';
|
|
7
|
+
|
|
8
|
+
export 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
|
+
export 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
|
+
};
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -37,9 +37,11 @@ export const rules: {
|
|
|
37
37
|
'ensure-test-runner-arguments': Rule.RuleModule;
|
|
38
38
|
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
39
39
|
'ensure-atlassian-team': Rule.RuleModule;
|
|
40
|
+
'ensure-critical-dependency-resolutions': Rule.RuleModule;
|
|
40
41
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
41
42
|
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
42
43
|
'no-invalid-storybook-decorator-usage': Rule.RuleModule;
|
|
44
|
+
'ensure-publish-valid': Rule.RuleModule;
|
|
43
45
|
};
|
|
44
46
|
|
|
45
47
|
// (No @packageDocumentation comment for this package)
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.node.json",
|
|
3
|
+
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
|
|
4
|
+
"exclude": [
|
|
5
|
+
"**/docs/**/*",
|
|
6
|
+
"**/__tests__/**/*",
|
|
7
|
+
"**/vr-tests/**/*",
|
|
8
|
+
"**/__perf__/**/*",
|
|
9
|
+
"**/*.test.*",
|
|
10
|
+
"**/test.*",
|
|
11
|
+
"**/test-*",
|
|
12
|
+
"**/examples.ts",
|
|
13
|
+
"**/examples.tsx",
|
|
14
|
+
"**/examples/*.ts",
|
|
15
|
+
"**/examples/*.tsx",
|
|
16
|
+
"**/examples/**/*.ts",
|
|
17
|
+
"**/examples/**/*.tsx",
|
|
18
|
+
"**/storybook/**/*",
|
|
19
|
+
"**/constellation/**/*",
|
|
20
|
+
".storybook/*",
|
|
21
|
+
"./__fixtures__/**/*",
|
|
22
|
+
"./__generated__/**/*",
|
|
23
|
+
"./mocks/**/*",
|
|
24
|
+
"./__mocks__/**/*",
|
|
25
|
+
"**/mock.*",
|
|
26
|
+
"**/codemods/**/*.ts",
|
|
27
|
+
"**/codemods/**/*.tsx"
|
|
28
|
+
],
|
|
29
|
+
"compilerOptions": {
|
|
30
|
+
"baseUrl": "./",
|
|
31
|
+
"lib": ["ES2021.String"],
|
|
32
|
+
"composite": true,
|
|
33
|
+
"outDir": "../../../tsDist/@atlaskit__eslint-plugin-platform/app"
|
|
34
|
+
},
|
|
35
|
+
"references": []
|
|
36
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.node.json",
|
|
3
|
+
"include": [
|
|
4
|
+
"**/docs/**/*",
|
|
5
|
+
"**/__tests__/**/*",
|
|
6
|
+
"**/vr-tests/**/*",
|
|
7
|
+
"**/__perf__/**/*",
|
|
8
|
+
"**/*.test.*",
|
|
9
|
+
"**/test.*",
|
|
10
|
+
"**/test-*",
|
|
11
|
+
"**/examples.ts",
|
|
12
|
+
"**/examples.tsx",
|
|
13
|
+
"**/examples/*.ts",
|
|
14
|
+
"**/examples/*.tsx",
|
|
15
|
+
"**/examples/**/*.ts",
|
|
16
|
+
"**/examples/**/*.tsx",
|
|
17
|
+
"**/storybook/**/*",
|
|
18
|
+
"**/constellation/**/*",
|
|
19
|
+
".storybook/*",
|
|
20
|
+
"./__fixtures__/**/*",
|
|
21
|
+
"./__generated__/**/*",
|
|
22
|
+
"./mocks/**/*",
|
|
23
|
+
"./__mocks__/**/*",
|
|
24
|
+
"**/mock.*",
|
|
25
|
+
"**/codemods/**/*.ts",
|
|
26
|
+
"**/codemods/**/*.tsx"
|
|
27
|
+
],
|
|
28
|
+
"exclude": ["./dist/**/*", "./build/**/*", "./node_modules/**/*"],
|
|
29
|
+
"compilerOptions": {
|
|
30
|
+
"baseUrl": "./",
|
|
31
|
+
"lib": ["ES2021.String"],
|
|
32
|
+
"composite": true,
|
|
33
|
+
"outDir": "../../../tsDist/@atlaskit__eslint-plugin-platform/dev"
|
|
34
|
+
},
|
|
35
|
+
"references": [
|
|
36
|
+
{
|
|
37
|
+
"path": "tsconfig.app.json"
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
package/dist/cjs/version.json
DELETED
package/dist/es2019/version.json
DELETED