@atlaskit/eslint-plugin-platform 0.10.1 → 0.12.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 +17 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/rules/ensure-valid-platform-yarn-protocol-usage/index.js +91 -0
- package/dist/es2019/index.js +2 -2
- package/dist/es2019/rules/ensure-valid-platform-yarn-protocol-usage/index.js +74 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/rules/ensure-valid-platform-yarn-protocol-usage/index.js +87 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/index.tsx +2 -2
- package/src/rules/{ensure-valid-workspace-protocol-usage → ensure-valid-platform-yarn-protocol-usage}/__tests__/unit/rule.test.ts +103 -3
- package/src/rules/ensure-valid-platform-yarn-protocol-usage/index.ts +79 -0
- package/dist/cjs/rules/ensure-valid-workspace-protocol-usage/index.js +0 -65
- package/dist/es2019/rules/ensure-valid-workspace-protocol-usage/index.js +0 -59
- package/dist/esm/rules/ensure-valid-workspace-protocol-usage/index.js +0 -59
- package/src/rules/ensure-valid-workspace-protocol-usage/index.ts +0 -67
- /package/dist/types/rules/{ensure-valid-workspace-protocol-usage → ensure-valid-platform-yarn-protocol-usage}/index.d.ts +0 -0
- /package/dist/types-ts4.5/rules/{ensure-valid-workspace-protocol-usage → ensure-valid-platform-yarn-protocol-usage}/index.d.ts +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#157394](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/157394)
|
|
8
|
+
[`aba8228458905`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/aba8228458905) -
|
|
9
|
+
Renamed `ensure-valid-yarn-protocol-usage` to `ensure-valid-plaform-yarn-protocol-usage`
|
|
10
|
+
|
|
11
|
+
## 0.11.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#157006](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/157006)
|
|
16
|
+
[`cfd78f9ae1e67`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/cfd78f9ae1e67) -
|
|
17
|
+
Renamed `ensure-valid-workspace-protocol-usage` to `ensure-valid-yarn-protocol-usage` and updated
|
|
18
|
+
the rule to error if the root custom yarn protocol is used in any platform package.
|
|
19
|
+
|
|
3
20
|
## 0.10.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -15,7 +15,7 @@ var _noDuplicateDependencies = _interopRequireDefault(require("./rules/no-duplic
|
|
|
15
15
|
var _noInvalidFeatureFlagUsage = _interopRequireDefault(require("./rules/no-invalid-feature-flag-usage"));
|
|
16
16
|
var _ensureFeatureFlagPrefix = _interopRequireDefault(require("./rules/ensure-feature-flag-prefix"));
|
|
17
17
|
var _ensureCriticalDependencyResolutions = _interopRequireDefault(require("./rules/ensure-critical-dependency-resolutions"));
|
|
18
|
-
var
|
|
18
|
+
var _ensureValidPlatformYarnProtocolUsage = _interopRequireDefault(require("./rules/ensure-valid-platform-yarn-protocol-usage"));
|
|
19
19
|
var _ensureValidBinValues = _interopRequireDefault(require("./rules/ensure-valid-bin-values"));
|
|
20
20
|
var _noInvalidStorybookDecoratorUsage = _interopRequireDefault(require("./rules/no-invalid-storybook-decorator-usage"));
|
|
21
21
|
var _ensurePublishValid = _interopRequireDefault(require("./rules/ensure-publish-valid"));
|
|
@@ -38,7 +38,7 @@ var rules = exports.rules = {
|
|
|
38
38
|
'ensure-test-runner-nested-count': _ensureTestRunnerNestedCount.default,
|
|
39
39
|
'ensure-atlassian-team': _ensureAtlassianTeam.default,
|
|
40
40
|
'ensure-critical-dependency-resolutions': _ensureCriticalDependencyResolutions.default,
|
|
41
|
-
'ensure-valid-
|
|
41
|
+
'ensure-valid-platform-yarn-protocol-usage': _ensureValidPlatformYarnProtocolUsage.default,
|
|
42
42
|
'ensure-valid-bin-values': _ensureValidBinValues.default,
|
|
43
43
|
'no-duplicate-dependencies': _noDuplicateDependencies.default,
|
|
44
44
|
'no-invalid-feature-flag-usage': _noInvalidFeatureFlagUsage.default,
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _handleAstObject = require("../util/handle-ast-object");
|
|
8
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } // eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
|
+
var workspaceProtocolRegex = /^workspace:[\^~\*]$/;
|
|
12
|
+
var rootProtocolRegex = /^root:[\^~\*]$/;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks if the 'workspace:' and 'root:' protocol are used as either dependencies or devDependencies
|
|
16
|
+
*/
|
|
17
|
+
function getYarnProtocolsUsed(node) {
|
|
18
|
+
var protocolsUsed = {
|
|
19
|
+
workspace: false,
|
|
20
|
+
root: false
|
|
21
|
+
};
|
|
22
|
+
var dependencies = (0, _handleAstObject.getObjectPropertyAsObject)(node, 'dependencies');
|
|
23
|
+
var devDependencies = (0, _handleAstObject.getObjectPropertyAsObject)(node, 'devDependencies');
|
|
24
|
+
for (var _i = 0, _arr = [dependencies, devDependencies]; _i < _arr.length; _i++) {
|
|
25
|
+
var obj = _arr[_i];
|
|
26
|
+
var _iterator = _createForOfIteratorHelper((obj === null || obj === void 0 ? void 0 : obj.properties) || []),
|
|
27
|
+
_step;
|
|
28
|
+
try {
|
|
29
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
30
|
+
var p = _step.value;
|
|
31
|
+
if (p.type === 'Property' && p.value.type === 'Literal') {
|
|
32
|
+
if (typeof p.value.value === 'string') {
|
|
33
|
+
if (workspaceProtocolRegex.test(p.value.value)) {
|
|
34
|
+
protocolsUsed.workspace = true;
|
|
35
|
+
}
|
|
36
|
+
if (rootProtocolRegex.test(p.value.value)) {
|
|
37
|
+
protocolsUsed.root = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
_iterator.e(err);
|
|
44
|
+
} finally {
|
|
45
|
+
_iterator.f();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return protocolsUsed;
|
|
49
|
+
}
|
|
50
|
+
var rule = {
|
|
51
|
+
meta: {
|
|
52
|
+
type: 'problem',
|
|
53
|
+
docs: {
|
|
54
|
+
description: "Ensures that yarn protocols 'workspace:' and 'root:' are used correctly.",
|
|
55
|
+
recommended: true
|
|
56
|
+
},
|
|
57
|
+
hasSuggestions: false,
|
|
58
|
+
messages: {
|
|
59
|
+
invalidWorkspaceProtocolUsage: "The 'workspace:' protocol is not allowed in public packages. To resolve this error, either set the package to private or replace the 'workspace:' protocol with specific package versions (e.g. '^1.0.0').",
|
|
60
|
+
invalidRootProtocolUsage: "The 'root:' protocol is not allowed in platform packages. To resolve this error, replace the 'root:' protocol with specific package versions (e.g. '^1.0.0')."
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
create: function create(context) {
|
|
64
|
+
return {
|
|
65
|
+
ObjectExpression: function ObjectExpression(node) {
|
|
66
|
+
if (!context.filename.endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var yarnProtocolsUsed = getYarnProtocolsUsed(node);
|
|
70
|
+
|
|
71
|
+
// The 'root:' protocol can not be used in any platform packages
|
|
72
|
+
if (yarnProtocolsUsed.root) {
|
|
73
|
+
context.report({
|
|
74
|
+
node: node,
|
|
75
|
+
messageId: 'invalidRootProtocolUsage'
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// The 'workspace:' protocol can not be used in public packages
|
|
80
|
+
var isPrivatePackage = (0, _handleAstObject.getObjectPropertyAsLiteral)(node, 'private') === true;
|
|
81
|
+
if (!isPrivatePackage && yarnProtocolsUsed.workspace) {
|
|
82
|
+
context.report({
|
|
83
|
+
node: node,
|
|
84
|
+
messageId: 'invalidWorkspaceProtocolUsage'
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
var _default = exports.default = rule;
|
package/dist/es2019/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import noDuplicateDependencies from './rules/no-duplicate-dependencies';
|
|
|
9
9
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
10
10
|
import ensureFeatureFlagPrefix from './rules/ensure-feature-flag-prefix';
|
|
11
11
|
import ensureCriticalDependencyResolutions from './rules/ensure-critical-dependency-resolutions';
|
|
12
|
-
import
|
|
12
|
+
import ensureValidPlatformYarnProtocolUsage from './rules/ensure-valid-platform-yarn-protocol-usage';
|
|
13
13
|
import ensureValidBinValues from './rules/ensure-valid-bin-values';
|
|
14
14
|
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
15
15
|
import ensurePublishValid from './rules/ensure-publish-valid';
|
|
@@ -30,7 +30,7 @@ export const rules = {
|
|
|
30
30
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
31
31
|
'ensure-atlassian-team': ensureAtlassianTeam,
|
|
32
32
|
'ensure-critical-dependency-resolutions': ensureCriticalDependencyResolutions,
|
|
33
|
-
'ensure-valid-
|
|
33
|
+
'ensure-valid-platform-yarn-protocol-usage': ensureValidPlatformYarnProtocolUsage,
|
|
34
34
|
'ensure-valid-bin-values': ensureValidBinValues,
|
|
35
35
|
'no-duplicate-dependencies': noDuplicateDependencies,
|
|
36
36
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
|
|
3
|
+
import { getObjectPropertyAsObject, getObjectPropertyAsLiteral } from '../util/handle-ast-object';
|
|
4
|
+
const workspaceProtocolRegex = /^workspace:[\^~\*]$/;
|
|
5
|
+
const rootProtocolRegex = /^root:[\^~\*]$/;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Checks if the 'workspace:' and 'root:' protocol are used as either dependencies or devDependencies
|
|
9
|
+
*/
|
|
10
|
+
function getYarnProtocolsUsed(node) {
|
|
11
|
+
const protocolsUsed = {
|
|
12
|
+
workspace: false,
|
|
13
|
+
root: false
|
|
14
|
+
};
|
|
15
|
+
const dependencies = getObjectPropertyAsObject(node, 'dependencies');
|
|
16
|
+
const devDependencies = getObjectPropertyAsObject(node, 'devDependencies');
|
|
17
|
+
for (const obj of [dependencies, devDependencies]) {
|
|
18
|
+
for (const p of (obj === null || obj === void 0 ? void 0 : obj.properties) || []) {
|
|
19
|
+
if (p.type === 'Property' && p.value.type === 'Literal') {
|
|
20
|
+
if (typeof p.value.value === 'string') {
|
|
21
|
+
if (workspaceProtocolRegex.test(p.value.value)) {
|
|
22
|
+
protocolsUsed.workspace = true;
|
|
23
|
+
}
|
|
24
|
+
if (rootProtocolRegex.test(p.value.value)) {
|
|
25
|
+
protocolsUsed.root = true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return protocolsUsed;
|
|
32
|
+
}
|
|
33
|
+
const rule = {
|
|
34
|
+
meta: {
|
|
35
|
+
type: 'problem',
|
|
36
|
+
docs: {
|
|
37
|
+
description: `Ensures that yarn protocols 'workspace:' and 'root:' are used correctly.`,
|
|
38
|
+
recommended: true
|
|
39
|
+
},
|
|
40
|
+
hasSuggestions: false,
|
|
41
|
+
messages: {
|
|
42
|
+
invalidWorkspaceProtocolUsage: `The 'workspace:' protocol is not allowed in public packages. To resolve this error, either set the package to private or replace the 'workspace:' protocol with specific package versions (e.g. '^1.0.0').`,
|
|
43
|
+
invalidRootProtocolUsage: `The 'root:' protocol is not allowed in platform packages. To resolve this error, replace the 'root:' protocol with specific package versions (e.g. '^1.0.0').`
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
create(context) {
|
|
47
|
+
return {
|
|
48
|
+
ObjectExpression: node => {
|
|
49
|
+
if (!context.filename.endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const yarnProtocolsUsed = getYarnProtocolsUsed(node);
|
|
53
|
+
|
|
54
|
+
// The 'root:' protocol can not be used in any platform packages
|
|
55
|
+
if (yarnProtocolsUsed.root) {
|
|
56
|
+
context.report({
|
|
57
|
+
node,
|
|
58
|
+
messageId: 'invalidRootProtocolUsage'
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// The 'workspace:' protocol can not be used in public packages
|
|
63
|
+
const isPrivatePackage = getObjectPropertyAsLiteral(node, 'private') === true;
|
|
64
|
+
if (!isPrivatePackage && yarnProtocolsUsed.workspace) {
|
|
65
|
+
context.report({
|
|
66
|
+
node,
|
|
67
|
+
messageId: 'invalidWorkspaceProtocolUsage'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
export default rule;
|
package/dist/esm/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import noDuplicateDependencies from './rules/no-duplicate-dependencies';
|
|
|
12
12
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
13
13
|
import ensureFeatureFlagPrefix from './rules/ensure-feature-flag-prefix';
|
|
14
14
|
import ensureCriticalDependencyResolutions from './rules/ensure-critical-dependency-resolutions';
|
|
15
|
-
import
|
|
15
|
+
import ensureValidPlatformYarnProtocolUsage from './rules/ensure-valid-platform-yarn-protocol-usage';
|
|
16
16
|
import ensureValidBinValues from './rules/ensure-valid-bin-values';
|
|
17
17
|
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
18
18
|
import ensurePublishValid from './rules/ensure-publish-valid';
|
|
@@ -33,7 +33,7 @@ export var rules = {
|
|
|
33
33
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
34
34
|
'ensure-atlassian-team': ensureAtlassianTeam,
|
|
35
35
|
'ensure-critical-dependency-resolutions': ensureCriticalDependencyResolutions,
|
|
36
|
-
'ensure-valid-
|
|
36
|
+
'ensure-valid-platform-yarn-protocol-usage': ensureValidPlatformYarnProtocolUsage,
|
|
37
37
|
'ensure-valid-bin-values': ensureValidBinValues,
|
|
38
38
|
'no-duplicate-dependencies': noDuplicateDependencies,
|
|
39
39
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
5
|
+
|
|
6
|
+
import { getObjectPropertyAsObject, getObjectPropertyAsLiteral } from '../util/handle-ast-object';
|
|
7
|
+
var workspaceProtocolRegex = /^workspace:[\^~\*]$/;
|
|
8
|
+
var rootProtocolRegex = /^root:[\^~\*]$/;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the 'workspace:' and 'root:' protocol are used as either dependencies or devDependencies
|
|
12
|
+
*/
|
|
13
|
+
function getYarnProtocolsUsed(node) {
|
|
14
|
+
var protocolsUsed = {
|
|
15
|
+
workspace: false,
|
|
16
|
+
root: false
|
|
17
|
+
};
|
|
18
|
+
var dependencies = getObjectPropertyAsObject(node, 'dependencies');
|
|
19
|
+
var devDependencies = getObjectPropertyAsObject(node, 'devDependencies');
|
|
20
|
+
for (var _i = 0, _arr = [dependencies, devDependencies]; _i < _arr.length; _i++) {
|
|
21
|
+
var obj = _arr[_i];
|
|
22
|
+
var _iterator = _createForOfIteratorHelper((obj === null || obj === void 0 ? void 0 : obj.properties) || []),
|
|
23
|
+
_step;
|
|
24
|
+
try {
|
|
25
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
26
|
+
var p = _step.value;
|
|
27
|
+
if (p.type === 'Property' && p.value.type === 'Literal') {
|
|
28
|
+
if (typeof p.value.value === 'string') {
|
|
29
|
+
if (workspaceProtocolRegex.test(p.value.value)) {
|
|
30
|
+
protocolsUsed.workspace = true;
|
|
31
|
+
}
|
|
32
|
+
if (rootProtocolRegex.test(p.value.value)) {
|
|
33
|
+
protocolsUsed.root = true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch (err) {
|
|
39
|
+
_iterator.e(err);
|
|
40
|
+
} finally {
|
|
41
|
+
_iterator.f();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return protocolsUsed;
|
|
45
|
+
}
|
|
46
|
+
var rule = {
|
|
47
|
+
meta: {
|
|
48
|
+
type: 'problem',
|
|
49
|
+
docs: {
|
|
50
|
+
description: "Ensures that yarn protocols 'workspace:' and 'root:' are used correctly.",
|
|
51
|
+
recommended: true
|
|
52
|
+
},
|
|
53
|
+
hasSuggestions: false,
|
|
54
|
+
messages: {
|
|
55
|
+
invalidWorkspaceProtocolUsage: "The 'workspace:' protocol is not allowed in public packages. To resolve this error, either set the package to private or replace the 'workspace:' protocol with specific package versions (e.g. '^1.0.0').",
|
|
56
|
+
invalidRootProtocolUsage: "The 'root:' protocol is not allowed in platform packages. To resolve this error, replace the 'root:' protocol with specific package versions (e.g. '^1.0.0')."
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
create: function create(context) {
|
|
60
|
+
return {
|
|
61
|
+
ObjectExpression: function ObjectExpression(node) {
|
|
62
|
+
if (!context.filename.endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
var yarnProtocolsUsed = getYarnProtocolsUsed(node);
|
|
66
|
+
|
|
67
|
+
// The 'root:' protocol can not be used in any platform packages
|
|
68
|
+
if (yarnProtocolsUsed.root) {
|
|
69
|
+
context.report({
|
|
70
|
+
node: node,
|
|
71
|
+
messageId: 'invalidRootProtocolUsage'
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The 'workspace:' protocol can not be used in public packages
|
|
76
|
+
var isPrivatePackage = getObjectPropertyAsLiteral(node, 'private') === true;
|
|
77
|
+
if (!isPrivatePackage && yarnProtocolsUsed.workspace) {
|
|
78
|
+
context.report({
|
|
79
|
+
node: node,
|
|
80
|
+
messageId: 'invalidWorkspaceProtocolUsage'
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export default rule;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const rules: {
|
|
|
6
6
|
'ensure-test-runner-nested-count': import("eslint").Rule.RuleModule;
|
|
7
7
|
'ensure-atlassian-team': import("eslint").Rule.RuleModule;
|
|
8
8
|
'ensure-critical-dependency-resolutions': import("eslint").Rule.RuleModule;
|
|
9
|
-
'ensure-valid-
|
|
9
|
+
'ensure-valid-platform-yarn-protocol-usage': import("eslint").Rule.RuleModule;
|
|
10
10
|
'ensure-valid-bin-values': import("eslint").Rule.RuleModule;
|
|
11
11
|
'no-duplicate-dependencies': import("eslint").Rule.RuleModule;
|
|
12
12
|
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
|
@@ -6,7 +6,7 @@ export declare const rules: {
|
|
|
6
6
|
'ensure-test-runner-nested-count': import("eslint").Rule.RuleModule;
|
|
7
7
|
'ensure-atlassian-team': import("eslint").Rule.RuleModule;
|
|
8
8
|
'ensure-critical-dependency-resolutions': import("eslint").Rule.RuleModule;
|
|
9
|
-
'ensure-valid-
|
|
9
|
+
'ensure-valid-platform-yarn-protocol-usage': import("eslint").Rule.RuleModule;
|
|
10
10
|
'ensure-valid-bin-values': import("eslint").Rule.RuleModule;
|
|
11
11
|
'no-duplicate-dependencies': import("eslint").Rule.RuleModule;
|
|
12
12
|
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import noDuplicateDependencies from './rules/no-duplicate-dependencies';
|
|
|
9
9
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
10
10
|
import ensureFeatureFlagPrefix from './rules/ensure-feature-flag-prefix';
|
|
11
11
|
import ensureCriticalDependencyResolutions from './rules/ensure-critical-dependency-resolutions';
|
|
12
|
-
import
|
|
12
|
+
import ensureValidPlatformYarnProtocolUsage from './rules/ensure-valid-platform-yarn-protocol-usage';
|
|
13
13
|
import ensureValidBinValues from './rules/ensure-valid-bin-values';
|
|
14
14
|
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
15
15
|
import ensurePublishValid from './rules/ensure-publish-valid';
|
|
@@ -31,7 +31,7 @@ export const rules = {
|
|
|
31
31
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
32
32
|
'ensure-atlassian-team': ensureAtlassianTeam,
|
|
33
33
|
'ensure-critical-dependency-resolutions': ensureCriticalDependencyResolutions,
|
|
34
|
-
'ensure-valid-
|
|
34
|
+
'ensure-valid-platform-yarn-protocol-usage': ensureValidPlatformYarnProtocolUsage,
|
|
35
35
|
'ensure-valid-bin-values': ensureValidBinValues,
|
|
36
36
|
'no-duplicate-dependencies': noDuplicateDependencies,
|
|
37
37
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
@@ -3,10 +3,10 @@ import rule from '../../index';
|
|
|
3
3
|
|
|
4
4
|
const cwd = process.cwd();
|
|
5
5
|
|
|
6
|
-
describe('test ensure-valid-
|
|
7
|
-
tester.run('
|
|
8
|
-
// Workspace protocol is allowed in private packages as dependencies
|
|
6
|
+
describe('test ensure-valid-platform-yarn-protocol-usage rule', () => {
|
|
7
|
+
tester.run('workspace protocol', rule, {
|
|
9
8
|
valid: [
|
|
9
|
+
// Workspace protocol is allowed in private packages as dependencies
|
|
10
10
|
{
|
|
11
11
|
code: `const foo = {
|
|
12
12
|
"private": true,
|
|
@@ -96,4 +96,104 @@ describe('test ensure-valid-workspace-protocol-usage rule', () => {
|
|
|
96
96
|
},
|
|
97
97
|
],
|
|
98
98
|
});
|
|
99
|
+
|
|
100
|
+
tester.run('root: protocol', rule, {
|
|
101
|
+
// 'root:' protocol is not allowed in any platform package
|
|
102
|
+
valid: [],
|
|
103
|
+
invalid: [
|
|
104
|
+
// 'root:' protocol is not allowed in packages as dependencies
|
|
105
|
+
{
|
|
106
|
+
code: `const foo = {
|
|
107
|
+
"dependencies": {
|
|
108
|
+
"react": "root:*",
|
|
109
|
+
}
|
|
110
|
+
}`,
|
|
111
|
+
filename: `${cwd}/packages/foo/package.json`,
|
|
112
|
+
errors: [
|
|
113
|
+
{
|
|
114
|
+
messageId: 'invalidRootProtocolUsage',
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
// 'root:' protocol is not allowed in private packages as dependencies
|
|
119
|
+
{
|
|
120
|
+
code: `const foo = {
|
|
121
|
+
"private": true,
|
|
122
|
+
"dependencies": {
|
|
123
|
+
"react": "root:*",
|
|
124
|
+
}
|
|
125
|
+
}`,
|
|
126
|
+
filename: `${cwd}/packages/foo/package.json`,
|
|
127
|
+
errors: [
|
|
128
|
+
{
|
|
129
|
+
messageId: 'invalidRootProtocolUsage',
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
// 'root:' protocol is not allowed in public packages as devDependencies
|
|
134
|
+
{
|
|
135
|
+
code: `const foo = {
|
|
136
|
+
"devDependencies": {
|
|
137
|
+
"react": "root:*",
|
|
138
|
+
}
|
|
139
|
+
}`,
|
|
140
|
+
filename: `${cwd}/packages/foo/package.json`,
|
|
141
|
+
errors: [
|
|
142
|
+
{
|
|
143
|
+
messageId: 'invalidRootProtocolUsage',
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
// 'root:' protocol is not allowed in private packages as devDependencies
|
|
148
|
+
{
|
|
149
|
+
code: `const foo = {
|
|
150
|
+
"private": true,
|
|
151
|
+
"devDependencies": {
|
|
152
|
+
"react": "root:*",
|
|
153
|
+
}
|
|
154
|
+
}`,
|
|
155
|
+
filename: `${cwd}/packages/foo/package.json`,
|
|
156
|
+
errors: [
|
|
157
|
+
{
|
|
158
|
+
messageId: 'invalidRootProtocolUsage',
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
// 'root:' protocol is not allowed in public packages as dependencies and devDependencies
|
|
163
|
+
{
|
|
164
|
+
code: `const foo = {
|
|
165
|
+
"dependencies": {
|
|
166
|
+
"lodash": "root:*"
|
|
167
|
+
},
|
|
168
|
+
"devDependencies": {
|
|
169
|
+
"react": "root:*"
|
|
170
|
+
}
|
|
171
|
+
}`,
|
|
172
|
+
filename: `${cwd}/packages/foo/package.json`,
|
|
173
|
+
errors: [
|
|
174
|
+
{
|
|
175
|
+
messageId: 'invalidRootProtocolUsage',
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
// 'root:' protocol is not allowed in private packages as dependencies and devDependencies
|
|
180
|
+
{
|
|
181
|
+
code: `const foo = {
|
|
182
|
+
"private": true,
|
|
183
|
+
"dependencies": {
|
|
184
|
+
"lodash": "root:*"
|
|
185
|
+
},
|
|
186
|
+
"devDependencies": {
|
|
187
|
+
"react": "root:*"
|
|
188
|
+
}
|
|
189
|
+
}`,
|
|
190
|
+
filename: `${cwd}/packages/foo/package.json`,
|
|
191
|
+
errors: [
|
|
192
|
+
{
|
|
193
|
+
messageId: 'invalidRootProtocolUsage',
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
});
|
|
99
199
|
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import type { Rule } from 'eslint';
|
|
3
|
+
import type { ObjectExpression } from 'estree';
|
|
4
|
+
import { getObjectPropertyAsObject, getObjectPropertyAsLiteral } from '../util/handle-ast-object';
|
|
5
|
+
|
|
6
|
+
const workspaceProtocolRegex = /^workspace:[\^~\*]$/;
|
|
7
|
+
const rootProtocolRegex = /^root:[\^~\*]$/;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the 'workspace:' and 'root:' protocol are used as either dependencies or devDependencies
|
|
11
|
+
*/
|
|
12
|
+
function getYarnProtocolsUsed(node: ObjectExpression) {
|
|
13
|
+
const protocolsUsed = { workspace: false, root: false };
|
|
14
|
+
|
|
15
|
+
const dependencies = getObjectPropertyAsObject(node, 'dependencies');
|
|
16
|
+
const devDependencies = getObjectPropertyAsObject(node, 'devDependencies');
|
|
17
|
+
|
|
18
|
+
for (const obj of [dependencies, devDependencies]) {
|
|
19
|
+
for (const p of obj?.properties || []) {
|
|
20
|
+
if (p.type === 'Property' && p.value.type === 'Literal') {
|
|
21
|
+
if (typeof p.value.value === 'string') {
|
|
22
|
+
if (workspaceProtocolRegex.test(p.value.value)) {
|
|
23
|
+
protocolsUsed.workspace = true;
|
|
24
|
+
}
|
|
25
|
+
if (rootProtocolRegex.test(p.value.value)) {
|
|
26
|
+
protocolsUsed.root = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return protocolsUsed;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const rule: Rule.RuleModule = {
|
|
37
|
+
meta: {
|
|
38
|
+
type: 'problem',
|
|
39
|
+
docs: {
|
|
40
|
+
description: `Ensures that yarn protocols 'workspace:' and 'root:' are used correctly.`,
|
|
41
|
+
recommended: true,
|
|
42
|
+
},
|
|
43
|
+
hasSuggestions: false,
|
|
44
|
+
messages: {
|
|
45
|
+
invalidWorkspaceProtocolUsage: `The 'workspace:' protocol is not allowed in public packages. To resolve this error, either set the package to private or replace the 'workspace:' protocol with specific package versions (e.g. '^1.0.0').`,
|
|
46
|
+
invalidRootProtocolUsage: `The 'root:' protocol is not allowed in platform packages. To resolve this error, replace the 'root:' protocol with specific package versions (e.g. '^1.0.0').`,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
create(context) {
|
|
50
|
+
return {
|
|
51
|
+
ObjectExpression: (node: Rule.Node) => {
|
|
52
|
+
if (!context.filename.endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const yarnProtocolsUsed = getYarnProtocolsUsed(node);
|
|
57
|
+
|
|
58
|
+
// The 'root:' protocol can not be used in any platform packages
|
|
59
|
+
if (yarnProtocolsUsed.root) {
|
|
60
|
+
context.report({
|
|
61
|
+
node,
|
|
62
|
+
messageId: 'invalidRootProtocolUsage',
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The 'workspace:' protocol can not be used in public packages
|
|
67
|
+
const isPrivatePackage = getObjectPropertyAsLiteral(node, 'private') === true;
|
|
68
|
+
if (!isPrivatePackage && yarnProtocolsUsed.workspace) {
|
|
69
|
+
context.report({
|
|
70
|
+
node,
|
|
71
|
+
messageId: 'invalidWorkspaceProtocolUsage',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default rule;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _handleAstObject = require("../util/handle-ast-object");
|
|
8
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
9
|
-
|
|
10
|
-
var workspaceProtocolRegex = /^workspace:[\^~\*]$/;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Checks if the workspace protocol is used in either dependencies or devDependencies
|
|
14
|
-
*/
|
|
15
|
-
function checkIsWorkspaceProtocolUsed(node) {
|
|
16
|
-
var dependencies = (0, _handleAstObject.getObjectPropertyAsObject)(node, 'dependencies');
|
|
17
|
-
var devDependencies = (0, _handleAstObject.getObjectPropertyAsObject)(node, 'devDependencies');
|
|
18
|
-
return [dependencies, devDependencies].some(function (obj) {
|
|
19
|
-
return obj !== null && obj.properties.some(function (p) {
|
|
20
|
-
if (p.type === 'Property' && p.value.type === 'Literal') {
|
|
21
|
-
return typeof p.value.value === 'string' && workspaceProtocolRegex.test(p.value.value);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
var rule = {
|
|
27
|
-
meta: {
|
|
28
|
-
type: 'problem',
|
|
29
|
-
docs: {
|
|
30
|
-
description: "Ensures the workspace protocol is only used in private packages.",
|
|
31
|
-
recommended: true
|
|
32
|
-
},
|
|
33
|
-
hasSuggestions: false,
|
|
34
|
-
messages: {
|
|
35
|
-
invalidWorkspaceProtocolUsage: "The workspace protocol is not allowed in public packages. To resolve this error, either set the package to private or replace the workspace protocol with specific package versions (e.g. \"^1.0.0\")."
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
create: function create(context) {
|
|
39
|
-
var fileName = context.getFilename();
|
|
40
|
-
return {
|
|
41
|
-
ObjectExpression: function ObjectExpression(node) {
|
|
42
|
-
if (!fileName.endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Exit early if we are linting a private package
|
|
47
|
-
var isPrivatePackage = (0, _handleAstObject.getObjectPropertyAsLiteral)(node, 'private') === true;
|
|
48
|
-
if (isPrivatePackage) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Check if the workspace protocol is used in either dependencies or devDependencies
|
|
53
|
-
var isWorkspaceProtocolused = checkIsWorkspaceProtocolUsed(node);
|
|
54
|
-
if (!isWorkspaceProtocolused) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
return context.report({
|
|
58
|
-
node: node,
|
|
59
|
-
messageId: 'invalidWorkspaceProtocolUsage'
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
var _default = exports.default = rule;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
|
|
3
|
-
import { getObjectPropertyAsObject, getObjectPropertyAsLiteral } from '../util/handle-ast-object';
|
|
4
|
-
const workspaceProtocolRegex = /^workspace:[\^~\*]$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Checks if the workspace protocol is used in either dependencies or devDependencies
|
|
8
|
-
*/
|
|
9
|
-
function checkIsWorkspaceProtocolUsed(node) {
|
|
10
|
-
const dependencies = getObjectPropertyAsObject(node, 'dependencies');
|
|
11
|
-
const devDependencies = getObjectPropertyAsObject(node, 'devDependencies');
|
|
12
|
-
return [dependencies, devDependencies].some(obj => {
|
|
13
|
-
return obj !== null && obj.properties.some(p => {
|
|
14
|
-
if (p.type === 'Property' && p.value.type === 'Literal') {
|
|
15
|
-
return typeof p.value.value === 'string' && workspaceProtocolRegex.test(p.value.value);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
const rule = {
|
|
21
|
-
meta: {
|
|
22
|
-
type: 'problem',
|
|
23
|
-
docs: {
|
|
24
|
-
description: `Ensures the workspace protocol is only used in private packages.`,
|
|
25
|
-
recommended: true
|
|
26
|
-
},
|
|
27
|
-
hasSuggestions: false,
|
|
28
|
-
messages: {
|
|
29
|
-
invalidWorkspaceProtocolUsage: `The workspace protocol is not allowed in public packages. To resolve this error, either set the package to private or replace the workspace protocol with specific package versions (e.g. "^1.0.0").`
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
create(context) {
|
|
33
|
-
const fileName = context.getFilename();
|
|
34
|
-
return {
|
|
35
|
-
ObjectExpression: node => {
|
|
36
|
-
if (!fileName.endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Exit early if we are linting a private package
|
|
41
|
-
const isPrivatePackage = getObjectPropertyAsLiteral(node, 'private') === true;
|
|
42
|
-
if (isPrivatePackage) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Check if the workspace protocol is used in either dependencies or devDependencies
|
|
47
|
-
const isWorkspaceProtocolused = checkIsWorkspaceProtocolUsed(node);
|
|
48
|
-
if (!isWorkspaceProtocolused) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
return context.report({
|
|
52
|
-
node,
|
|
53
|
-
messageId: 'invalidWorkspaceProtocolUsage'
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
export default rule;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
|
|
3
|
-
import { getObjectPropertyAsObject, getObjectPropertyAsLiteral } from '../util/handle-ast-object';
|
|
4
|
-
var workspaceProtocolRegex = /^workspace:[\^~\*]$/;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Checks if the workspace protocol is used in either dependencies or devDependencies
|
|
8
|
-
*/
|
|
9
|
-
function checkIsWorkspaceProtocolUsed(node) {
|
|
10
|
-
var dependencies = getObjectPropertyAsObject(node, 'dependencies');
|
|
11
|
-
var devDependencies = getObjectPropertyAsObject(node, 'devDependencies');
|
|
12
|
-
return [dependencies, devDependencies].some(function (obj) {
|
|
13
|
-
return obj !== null && obj.properties.some(function (p) {
|
|
14
|
-
if (p.type === 'Property' && p.value.type === 'Literal') {
|
|
15
|
-
return typeof p.value.value === 'string' && workspaceProtocolRegex.test(p.value.value);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
var rule = {
|
|
21
|
-
meta: {
|
|
22
|
-
type: 'problem',
|
|
23
|
-
docs: {
|
|
24
|
-
description: "Ensures the workspace protocol is only used in private packages.",
|
|
25
|
-
recommended: true
|
|
26
|
-
},
|
|
27
|
-
hasSuggestions: false,
|
|
28
|
-
messages: {
|
|
29
|
-
invalidWorkspaceProtocolUsage: "The workspace protocol is not allowed in public packages. To resolve this error, either set the package to private or replace the workspace protocol with specific package versions (e.g. \"^1.0.0\")."
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
create: function create(context) {
|
|
33
|
-
var fileName = context.getFilename();
|
|
34
|
-
return {
|
|
35
|
-
ObjectExpression: function ObjectExpression(node) {
|
|
36
|
-
if (!fileName.endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Exit early if we are linting a private package
|
|
41
|
-
var isPrivatePackage = getObjectPropertyAsLiteral(node, 'private') === true;
|
|
42
|
-
if (isPrivatePackage) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Check if the workspace protocol is used in either dependencies or devDependencies
|
|
47
|
-
var isWorkspaceProtocolused = checkIsWorkspaceProtocolUsed(node);
|
|
48
|
-
if (!isWorkspaceProtocolused) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
return context.report({
|
|
52
|
-
node: node,
|
|
53
|
-
messageId: 'invalidWorkspaceProtocolUsage'
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
export default rule;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
import type { Rule } from 'eslint';
|
|
3
|
-
import type { ObjectExpression } from 'estree';
|
|
4
|
-
import { getObjectPropertyAsObject, getObjectPropertyAsLiteral } from '../util/handle-ast-object';
|
|
5
|
-
|
|
6
|
-
const workspaceProtocolRegex = /^workspace:[\^~\*]$/;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Checks if the workspace protocol is used in either dependencies or devDependencies
|
|
10
|
-
*/
|
|
11
|
-
function checkIsWorkspaceProtocolUsed(node: ObjectExpression) {
|
|
12
|
-
const dependencies = getObjectPropertyAsObject(node, 'dependencies');
|
|
13
|
-
const devDependencies = getObjectPropertyAsObject(node, 'devDependencies');
|
|
14
|
-
return [dependencies, devDependencies].some((obj) => {
|
|
15
|
-
return (
|
|
16
|
-
obj !== null &&
|
|
17
|
-
obj.properties.some((p) => {
|
|
18
|
-
if (p.type === 'Property' && p.value.type === 'Literal') {
|
|
19
|
-
return typeof p.value.value === 'string' && workspaceProtocolRegex.test(p.value.value);
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const rule: Rule.RuleModule = {
|
|
27
|
-
meta: {
|
|
28
|
-
type: 'problem',
|
|
29
|
-
docs: {
|
|
30
|
-
description: `Ensures the workspace protocol is only used in private packages.`,
|
|
31
|
-
recommended: true,
|
|
32
|
-
},
|
|
33
|
-
hasSuggestions: false,
|
|
34
|
-
messages: {
|
|
35
|
-
invalidWorkspaceProtocolUsage: `The workspace protocol is not allowed in public packages. To resolve this error, either set the package to private or replace the workspace protocol with specific package versions (e.g. "^1.0.0").`,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
create(context) {
|
|
39
|
-
const fileName = context.getFilename();
|
|
40
|
-
return {
|
|
41
|
-
ObjectExpression: (node: Rule.Node) => {
|
|
42
|
-
if (!fileName.endsWith('package.json') || node.type !== 'ObjectExpression') {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Exit early if we are linting a private package
|
|
47
|
-
const isPrivatePackage = getObjectPropertyAsLiteral(node, 'private') === true;
|
|
48
|
-
if (isPrivatePackage) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Check if the workspace protocol is used in either dependencies or devDependencies
|
|
53
|
-
const isWorkspaceProtocolused = checkIsWorkspaceProtocolUsed(node);
|
|
54
|
-
if (!isWorkspaceProtocolused) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return context.report({
|
|
59
|
-
node,
|
|
60
|
-
messageId: 'invalidWorkspaceProtocolUsage',
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export default rule;
|
|
File without changes
|