@atlaskit/eslint-plugin-platform 0.2.2 → 0.2.3
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/no-invalid-feature-flag-usage/index.js +5 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/rules/no-invalid-feature-flag-usage/index.js +5 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/rules/no-invalid-feature-flag-usage/index.js +5 -1
- package/dist/esm/version.json +1 -1
- package/package.json +1 -1
- package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +12 -1
- package/src/rules/no-invalid-feature-flag-usage/index.tsx +11 -9
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,8 @@ var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression
|
|
|
11
11
|
switch (root.type) {
|
|
12
12
|
case 'IfStatement':
|
|
13
13
|
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
14
|
+
case 'UnaryExpression':
|
|
15
|
+
return __isOnlyOneFlagCheckInExpression(root.argument, ignoredNode);
|
|
14
16
|
case 'CallExpression':
|
|
15
17
|
if (root === ignoredNode) {
|
|
16
18
|
return true;
|
|
@@ -30,7 +32,8 @@ var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression
|
|
|
30
32
|
var isOnlyOneFlagCheckInExpression = function isOnlyOneFlagCheckInExpression(node) {
|
|
31
33
|
var root = node.parent;
|
|
32
34
|
// find the root node of the expression
|
|
33
|
-
|
|
35
|
+
// NOTE: This is not an exhaustive check for all ESTree.Expression types but is good enough
|
|
36
|
+
while (root.type.endsWith('Expression')) {
|
|
34
37
|
root = root.parent;
|
|
35
38
|
}
|
|
36
39
|
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
@@ -64,6 +67,7 @@ var rule = {
|
|
|
64
67
|
case 'IfStatement':
|
|
65
68
|
case 'ConditionalExpression':
|
|
66
69
|
break;
|
|
70
|
+
case 'UnaryExpression':
|
|
67
71
|
case 'LogicalExpression':
|
|
68
72
|
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
69
73
|
context.report({
|
package/dist/cjs/version.json
CHANGED
|
@@ -3,6 +3,8 @@ const __isOnlyOneFlagCheckInExpression = (root, ignoredNode) => {
|
|
|
3
3
|
switch (root.type) {
|
|
4
4
|
case 'IfStatement':
|
|
5
5
|
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
6
|
+
case 'UnaryExpression':
|
|
7
|
+
return __isOnlyOneFlagCheckInExpression(root.argument, ignoredNode);
|
|
6
8
|
case 'CallExpression':
|
|
7
9
|
if (root === ignoredNode) {
|
|
8
10
|
return true;
|
|
@@ -22,7 +24,8 @@ const __isOnlyOneFlagCheckInExpression = (root, ignoredNode) => {
|
|
|
22
24
|
const isOnlyOneFlagCheckInExpression = node => {
|
|
23
25
|
let root = node.parent;
|
|
24
26
|
// find the root node of the expression
|
|
25
|
-
|
|
27
|
+
// NOTE: This is not an exhaustive check for all ESTree.Expression types but is good enough
|
|
28
|
+
while (root.type.endsWith('Expression')) {
|
|
26
29
|
root = root.parent;
|
|
27
30
|
}
|
|
28
31
|
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
@@ -57,6 +60,7 @@ const rule = {
|
|
|
57
60
|
case 'IfStatement':
|
|
58
61
|
case 'ConditionalExpression':
|
|
59
62
|
break;
|
|
63
|
+
case 'UnaryExpression':
|
|
60
64
|
case 'LogicalExpression':
|
|
61
65
|
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
62
66
|
context.report({
|
package/dist/es2019/version.json
CHANGED
|
@@ -4,6 +4,8 @@ var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression
|
|
|
4
4
|
switch (root.type) {
|
|
5
5
|
case 'IfStatement':
|
|
6
6
|
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
7
|
+
case 'UnaryExpression':
|
|
8
|
+
return __isOnlyOneFlagCheckInExpression(root.argument, ignoredNode);
|
|
7
9
|
case 'CallExpression':
|
|
8
10
|
if (root === ignoredNode) {
|
|
9
11
|
return true;
|
|
@@ -23,7 +25,8 @@ var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression
|
|
|
23
25
|
var isOnlyOneFlagCheckInExpression = function isOnlyOneFlagCheckInExpression(node) {
|
|
24
26
|
var root = node.parent;
|
|
25
27
|
// find the root node of the expression
|
|
26
|
-
|
|
28
|
+
// NOTE: This is not an exhaustive check for all ESTree.Expression types but is good enough
|
|
29
|
+
while (root.type.endsWith('Expression')) {
|
|
27
30
|
root = root.parent;
|
|
28
31
|
}
|
|
29
32
|
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
@@ -57,6 +60,7 @@ var rule = {
|
|
|
57
60
|
case 'IfStatement':
|
|
58
61
|
case 'ConditionalExpression':
|
|
59
62
|
break;
|
|
63
|
+
case 'UnaryExpression':
|
|
60
64
|
case 'LogicalExpression':
|
|
61
65
|
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
62
66
|
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.2.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
|
@@ -8,6 +8,10 @@ describe('enforce-feature-flag-usage-structure tests', () => {
|
|
|
8
8
|
// IfStatement
|
|
9
9
|
code: `if(getBooleanFF('test-flag')) { }`,
|
|
10
10
|
},
|
|
11
|
+
{
|
|
12
|
+
// negated IfStatement
|
|
13
|
+
code: `if(!getBooleanFF('test-flag')) { }`,
|
|
14
|
+
},
|
|
11
15
|
{
|
|
12
16
|
// ConditionalExpression
|
|
13
17
|
code: `const val = getBooleanFF('test-flag') ? 'yay' : 'no';`,
|
|
@@ -38,7 +42,14 @@ describe('enforce-feature-flag-usage-structure tests', () => {
|
|
|
38
42
|
],
|
|
39
43
|
},
|
|
40
44
|
{
|
|
41
|
-
code: `if(
|
|
45
|
+
code: `if(!getBooleanFF('test-flag') && !getBooleanFF('test-flag')) { }`,
|
|
46
|
+
errors: [
|
|
47
|
+
{ messageId: 'multipleFlagCheckInExpression' },
|
|
48
|
+
{ messageId: 'multipleFlagCheckInExpression' },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
code: `if((!getBooleanFF('test-flag') || 1 == true) && getBooleanFF('test-flag')) { }`,
|
|
42
53
|
errors: [
|
|
43
54
|
{ messageId: 'multipleFlagCheckInExpression' },
|
|
44
55
|
{ messageId: 'multipleFlagCheckInExpression' },
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Rule } from 'eslint';
|
|
2
|
+
import type { Node, Expression } from 'estree';
|
|
2
3
|
|
|
3
4
|
const FF_GETTER_BOOLEAN_IDENTIFIER = 'getBooleanFF' as const;
|
|
4
5
|
|
|
5
6
|
const __isOnlyOneFlagCheckInExpression = (
|
|
6
|
-
root:
|
|
7
|
-
ignoredNode:
|
|
7
|
+
root: Node | Expression,
|
|
8
|
+
ignoredNode: Node,
|
|
8
9
|
): boolean => {
|
|
9
10
|
switch (root.type) {
|
|
10
11
|
case 'IfStatement':
|
|
11
|
-
return __isOnlyOneFlagCheckInExpression(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
);
|
|
12
|
+
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
13
|
+
case 'UnaryExpression':
|
|
14
|
+
return __isOnlyOneFlagCheckInExpression(root.argument, ignoredNode);
|
|
15
15
|
|
|
16
16
|
case 'CallExpression':
|
|
17
17
|
if (root === ignoredNode) {
|
|
@@ -29,8 +29,8 @@ const __isOnlyOneFlagCheckInExpression = (
|
|
|
29
29
|
case 'BinaryExpression':
|
|
30
30
|
case 'LogicalExpression':
|
|
31
31
|
return (
|
|
32
|
-
__isOnlyOneFlagCheckInExpression(root.left
|
|
33
|
-
__isOnlyOneFlagCheckInExpression(root.right
|
|
32
|
+
__isOnlyOneFlagCheckInExpression(root.left, ignoredNode) &&
|
|
33
|
+
__isOnlyOneFlagCheckInExpression(root.right, ignoredNode)
|
|
34
34
|
);
|
|
35
35
|
|
|
36
36
|
default:
|
|
@@ -41,7 +41,8 @@ const __isOnlyOneFlagCheckInExpression = (
|
|
|
41
41
|
const isOnlyOneFlagCheckInExpression = (node: Rule.Node): boolean => {
|
|
42
42
|
let root = node.parent;
|
|
43
43
|
// find the root node of the expression
|
|
44
|
-
|
|
44
|
+
// NOTE: This is not an exhaustive check for all ESTree.Expression types but is good enough
|
|
45
|
+
while (root.type.endsWith('Expression')) {
|
|
45
46
|
root = root.parent;
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -83,6 +84,7 @@ const rule: Rule.RuleModule = {
|
|
|
83
84
|
case 'IfStatement':
|
|
84
85
|
case 'ConditionalExpression':
|
|
85
86
|
break;
|
|
87
|
+
case 'UnaryExpression':
|
|
86
88
|
case 'LogicalExpression':
|
|
87
89
|
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
88
90
|
context.report({
|