@atlaskit/eslint-plugin-platform 0.0.3 → 0.0.4
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/rules/ensure-feature-flag-registration/index.js +37 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/rules/ensure-feature-flag-registration/index.js +37 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/rules/ensure-feature-flag-registration/index.js +37 -1
- package/dist/esm/version.json +1 -1
- package/package.json +1 -1
- package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +14 -0
- package/src/rules/ensure-feature-flag-registration/index.tsx +53 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 0.0.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`cd5b194f403`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cd5b194f403) - Add check to ensure that there is only one feature flag call per expression
|
|
8
|
+
|
|
3
9
|
## 0.0.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -31,6 +31,34 @@ var getPackageJsonForFileName = function getPackageJsonForFileName(filename) {
|
|
|
31
31
|
pkgJsonCache.set(pkgJsonPath, packageJson);
|
|
32
32
|
return packageJson;
|
|
33
33
|
};
|
|
34
|
+
var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression(root, ignoredNode) {
|
|
35
|
+
switch (root.type) {
|
|
36
|
+
case 'IfStatement':
|
|
37
|
+
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
38
|
+
case 'CallExpression':
|
|
39
|
+
if (root === ignoredNode) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return !(root.callee.type === 'Identifier' && root.callee.name === 'getBooleanFF');
|
|
43
|
+
|
|
44
|
+
// shouldn't ever get here but just in case
|
|
45
|
+
case 'Identifier':
|
|
46
|
+
return root.name !== 'getBooleanFF';
|
|
47
|
+
case 'BinaryExpression':
|
|
48
|
+
case 'LogicalExpression':
|
|
49
|
+
return __isOnlyOneFlagCheckInExpression(root.left, ignoredNode) && __isOnlyOneFlagCheckInExpression(root.right, ignoredNode);
|
|
50
|
+
default:
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var isOnlyOneFlagCheckInExpression = function isOnlyOneFlagCheckInExpression(node) {
|
|
55
|
+
var root = node.parent;
|
|
56
|
+
// find the root node of the expression
|
|
57
|
+
while (root.type === 'LogicalExpression') {
|
|
58
|
+
root = root.parent;
|
|
59
|
+
}
|
|
60
|
+
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
61
|
+
};
|
|
34
62
|
var rule = {
|
|
35
63
|
meta: {
|
|
36
64
|
hasSuggestions: false,
|
|
@@ -42,7 +70,8 @@ var rule = {
|
|
|
42
70
|
onlyInlineIf: "Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
43
71
|
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
44
72
|
registrationSectionMissing: 'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
45
|
-
featureFlagMissing: "Please add a \"{{ featureFlag }}\" section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details"
|
|
73
|
+
featureFlagMissing: "Please add a \"{{ featureFlag }}\" section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details",
|
|
74
|
+
multipleFlagCheckInExpression: "Only check one flag per expression! See http://go/pff-eslint for more details"
|
|
46
75
|
}
|
|
47
76
|
},
|
|
48
77
|
create: function create(context) {
|
|
@@ -61,7 +90,14 @@ var rule = {
|
|
|
61
90
|
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
62
91
|
case 'IfStatement':
|
|
63
92
|
case 'ConditionalExpression':
|
|
93
|
+
break;
|
|
64
94
|
case 'LogicalExpression':
|
|
95
|
+
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
96
|
+
context.report({
|
|
97
|
+
node: node,
|
|
98
|
+
messageId: 'multipleFlagCheckInExpression'
|
|
99
|
+
});
|
|
100
|
+
}
|
|
65
101
|
break;
|
|
66
102
|
default:
|
|
67
103
|
return context.report({
|
package/dist/cjs/version.json
CHANGED
|
@@ -24,6 +24,34 @@ const getPackageJsonForFileName = filename => {
|
|
|
24
24
|
pkgJsonCache.set(pkgJsonPath, packageJson);
|
|
25
25
|
return packageJson;
|
|
26
26
|
};
|
|
27
|
+
const __isOnlyOneFlagCheckInExpression = (root, ignoredNode) => {
|
|
28
|
+
switch (root.type) {
|
|
29
|
+
case 'IfStatement':
|
|
30
|
+
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
31
|
+
case 'CallExpression':
|
|
32
|
+
if (root === ignoredNode) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return !(root.callee.type === 'Identifier' && root.callee.name === 'getBooleanFF');
|
|
36
|
+
|
|
37
|
+
// shouldn't ever get here but just in case
|
|
38
|
+
case 'Identifier':
|
|
39
|
+
return root.name !== 'getBooleanFF';
|
|
40
|
+
case 'BinaryExpression':
|
|
41
|
+
case 'LogicalExpression':
|
|
42
|
+
return __isOnlyOneFlagCheckInExpression(root.left, ignoredNode) && __isOnlyOneFlagCheckInExpression(root.right, ignoredNode);
|
|
43
|
+
default:
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const isOnlyOneFlagCheckInExpression = node => {
|
|
48
|
+
let root = node.parent;
|
|
49
|
+
// find the root node of the expression
|
|
50
|
+
while (root.type === 'LogicalExpression') {
|
|
51
|
+
root = root.parent;
|
|
52
|
+
}
|
|
53
|
+
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
54
|
+
};
|
|
27
55
|
const rule = {
|
|
28
56
|
meta: {
|
|
29
57
|
hasSuggestions: false,
|
|
@@ -35,7 +63,8 @@ const rule = {
|
|
|
35
63
|
onlyInlineIf: "Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
36
64
|
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
37
65
|
registrationSectionMissing: 'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
38
|
-
featureFlagMissing: `Please add a "{{ featureFlag }}" section to the "platform-feature-flags" section in your package.json. See http://go/pff-eslint for more details
|
|
66
|
+
featureFlagMissing: `Please add a "{{ featureFlag }}" section to the "platform-feature-flags" section in your package.json. See http://go/pff-eslint for more details`,
|
|
67
|
+
multipleFlagCheckInExpression: `Only check one flag per expression! See http://go/pff-eslint for more details`
|
|
39
68
|
}
|
|
40
69
|
},
|
|
41
70
|
create(context) {
|
|
@@ -54,7 +83,14 @@ const rule = {
|
|
|
54
83
|
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
55
84
|
case 'IfStatement':
|
|
56
85
|
case 'ConditionalExpression':
|
|
86
|
+
break;
|
|
57
87
|
case 'LogicalExpression':
|
|
88
|
+
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
89
|
+
context.report({
|
|
90
|
+
node,
|
|
91
|
+
messageId: 'multipleFlagCheckInExpression'
|
|
92
|
+
});
|
|
93
|
+
}
|
|
58
94
|
break;
|
|
59
95
|
default:
|
|
60
96
|
return context.report({
|
package/dist/es2019/version.json
CHANGED
|
@@ -24,6 +24,34 @@ var getPackageJsonForFileName = function getPackageJsonForFileName(filename) {
|
|
|
24
24
|
pkgJsonCache.set(pkgJsonPath, packageJson);
|
|
25
25
|
return packageJson;
|
|
26
26
|
};
|
|
27
|
+
var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression(root, ignoredNode) {
|
|
28
|
+
switch (root.type) {
|
|
29
|
+
case 'IfStatement':
|
|
30
|
+
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
31
|
+
case 'CallExpression':
|
|
32
|
+
if (root === ignoredNode) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return !(root.callee.type === 'Identifier' && root.callee.name === 'getBooleanFF');
|
|
36
|
+
|
|
37
|
+
// shouldn't ever get here but just in case
|
|
38
|
+
case 'Identifier':
|
|
39
|
+
return root.name !== 'getBooleanFF';
|
|
40
|
+
case 'BinaryExpression':
|
|
41
|
+
case 'LogicalExpression':
|
|
42
|
+
return __isOnlyOneFlagCheckInExpression(root.left, ignoredNode) && __isOnlyOneFlagCheckInExpression(root.right, ignoredNode);
|
|
43
|
+
default:
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var isOnlyOneFlagCheckInExpression = function isOnlyOneFlagCheckInExpression(node) {
|
|
48
|
+
var root = node.parent;
|
|
49
|
+
// find the root node of the expression
|
|
50
|
+
while (root.type === 'LogicalExpression') {
|
|
51
|
+
root = root.parent;
|
|
52
|
+
}
|
|
53
|
+
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
54
|
+
};
|
|
27
55
|
var rule = {
|
|
28
56
|
meta: {
|
|
29
57
|
hasSuggestions: false,
|
|
@@ -35,7 +63,8 @@ var rule = {
|
|
|
35
63
|
onlyInlineIf: "Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
36
64
|
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
37
65
|
registrationSectionMissing: 'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
38
|
-
featureFlagMissing: "Please add a \"{{ featureFlag }}\" section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details"
|
|
66
|
+
featureFlagMissing: "Please add a \"{{ featureFlag }}\" section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details",
|
|
67
|
+
multipleFlagCheckInExpression: "Only check one flag per expression! See http://go/pff-eslint for more details"
|
|
39
68
|
}
|
|
40
69
|
},
|
|
41
70
|
create: function create(context) {
|
|
@@ -54,7 +83,14 @@ var rule = {
|
|
|
54
83
|
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
55
84
|
case 'IfStatement':
|
|
56
85
|
case 'ConditionalExpression':
|
|
86
|
+
break;
|
|
57
87
|
case 'LogicalExpression':
|
|
88
|
+
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
89
|
+
context.report({
|
|
90
|
+
node: node,
|
|
91
|
+
messageId: 'multipleFlagCheckInExpression'
|
|
92
|
+
});
|
|
93
|
+
}
|
|
58
94
|
break;
|
|
59
95
|
default:
|
|
60
96
|
return context.report({
|
package/dist/esm/version.json
CHANGED
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.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
|
@@ -63,6 +63,20 @@ describe('with existing platform-feature-flags section', () => {
|
|
|
63
63
|
code: `const ff = "test-flag"; if(getBooleanFF(ff)) { }`,
|
|
64
64
|
errors: [{ messageId: 'onlyStringLiteral' }],
|
|
65
65
|
},
|
|
66
|
+
{
|
|
67
|
+
code: `if(getBooleanFF('test-flag') && getBooleanFF('test-flag')) { }`,
|
|
68
|
+
errors: [
|
|
69
|
+
{ messageId: 'multipleFlagCheckInExpression' },
|
|
70
|
+
{ messageId: 'multipleFlagCheckInExpression' },
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
code: `if((getBooleanFF('test-flag') || 1 == true) && getBooleanFF('test-flag')) { }`,
|
|
75
|
+
errors: [
|
|
76
|
+
{ messageId: 'multipleFlagCheckInExpression' },
|
|
77
|
+
{ messageId: 'multipleFlagCheckInExpression' },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
66
80
|
],
|
|
67
81
|
});
|
|
68
82
|
});
|
|
@@ -33,6 +33,51 @@ const getPackageJsonForFileName = (filename: string): readPkgUp.PackageJson => {
|
|
|
33
33
|
return packageJson;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
const __isOnlyOneFlagCheckInExpression = (
|
|
37
|
+
root: Rule.Node,
|
|
38
|
+
ignoredNode: Rule.Node,
|
|
39
|
+
): boolean => {
|
|
40
|
+
switch (root.type) {
|
|
41
|
+
case 'IfStatement':
|
|
42
|
+
return __isOnlyOneFlagCheckInExpression(
|
|
43
|
+
root.test as Rule.Node,
|
|
44
|
+
ignoredNode,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
case 'CallExpression':
|
|
48
|
+
if (root === ignoredNode) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
return !(
|
|
52
|
+
root.callee.type === 'Identifier' && root.callee.name === 'getBooleanFF'
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
// shouldn't ever get here but just in case
|
|
56
|
+
case 'Identifier':
|
|
57
|
+
return root.name !== 'getBooleanFF';
|
|
58
|
+
|
|
59
|
+
case 'BinaryExpression':
|
|
60
|
+
case 'LogicalExpression':
|
|
61
|
+
return (
|
|
62
|
+
__isOnlyOneFlagCheckInExpression(root.left as Rule.Node, ignoredNode) &&
|
|
63
|
+
__isOnlyOneFlagCheckInExpression(root.right as Rule.Node, ignoredNode)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
default:
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const isOnlyOneFlagCheckInExpression = (node: Rule.Node): boolean => {
|
|
72
|
+
let root = node.parent;
|
|
73
|
+
// find the root node of the expression
|
|
74
|
+
while (root.type === 'LogicalExpression') {
|
|
75
|
+
root = root.parent;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
79
|
+
};
|
|
80
|
+
|
|
36
81
|
const rule: Rule.RuleModule = {
|
|
37
82
|
meta: {
|
|
38
83
|
hasSuggestions: false,
|
|
@@ -48,6 +93,7 @@ const rule: Rule.RuleModule = {
|
|
|
48
93
|
registrationSectionMissing:
|
|
49
94
|
'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
50
95
|
featureFlagMissing: `Please add a "{{ featureFlag }}" section to the "platform-feature-flags" section in your package.json. See http://go/pff-eslint for more details`,
|
|
96
|
+
multipleFlagCheckInExpression: `Only check one flag per expression! See http://go/pff-eslint for more details`,
|
|
51
97
|
},
|
|
52
98
|
},
|
|
53
99
|
create(context) {
|
|
@@ -67,7 +113,14 @@ const rule: Rule.RuleModule = {
|
|
|
67
113
|
switch (node.parent?.type) {
|
|
68
114
|
case 'IfStatement':
|
|
69
115
|
case 'ConditionalExpression':
|
|
116
|
+
break;
|
|
70
117
|
case 'LogicalExpression':
|
|
118
|
+
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
119
|
+
context.report({
|
|
120
|
+
node,
|
|
121
|
+
messageId: 'multipleFlagCheckInExpression',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
71
124
|
break;
|
|
72
125
|
default:
|
|
73
126
|
return context.report({
|