@atlaskit/eslint-plugin-platform 0.0.4 → 0.0.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 +11 -2
- package/dist/cjs/rules/ensure-feature-flag-registration/index.js +1 -58
- package/dist/cjs/rules/ensure-test-runner-arguments/index.js +95 -0
- package/dist/cjs/rules/ensure-test-runner-nested-count/index.js +69 -0
- package/dist/cjs/rules/no-invalid-feature-flag-usage/index.js +87 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/index.js +11 -2
- package/dist/es2019/rules/ensure-feature-flag-registration/index.js +1 -58
- package/dist/es2019/rules/ensure-test-runner-arguments/index.js +88 -0
- package/dist/es2019/rules/ensure-test-runner-nested-count/index.js +63 -0
- package/dist/es2019/rules/no-invalid-feature-flag-usage/index.js +80 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/index.js +11 -2
- package/dist/esm/rules/ensure-feature-flag-registration/index.js +1 -58
- package/dist/esm/rules/ensure-test-runner-arguments/index.js +87 -0
- package/dist/esm/rules/ensure-test-runner-nested-count/index.js +61 -0
- package/dist/esm/rules/no-invalid-feature-flag-usage/index.js +79 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/types/rules/ensure-test-runner-arguments/index.d.ts +3 -0
- package/dist/types/rules/ensure-test-runner-nested-count/index.d.ts +3 -0
- package/dist/types/rules/no-invalid-feature-flag-usage/index.d.ts +3 -0
- package/package.json +1 -1
- package/report.api.md +6 -0
- package/src/index.tsx +9 -0
- package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +2 -37
- package/src/rules/ensure-feature-flag-registration/index.tsx +0 -77
- package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +221 -0
- package/src/rules/ensure-test-runner-arguments/index.tsx +110 -0
- package/src/rules/ensure-test-runner-nested-count/__tests__/unit/rule.test.tsx +308 -0
- package/src/rules/ensure-test-runner-nested-count/index.tsx +83 -0
- package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +49 -0
- package/src/rules/no-invalid-feature-flag-usage/index.tsx +108 -0
- package/tmp/api-report-tmp.d.ts +6 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const FF_GETTER_BOOLEAN_IDENTIFIER = 'getBooleanFF';
|
|
2
|
+
const __isOnlyOneFlagCheckInExpression = (root, ignoredNode) => {
|
|
3
|
+
switch (root.type) {
|
|
4
|
+
case 'IfStatement':
|
|
5
|
+
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
6
|
+
case 'CallExpression':
|
|
7
|
+
if (root === ignoredNode) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
return !(root.callee.type === 'Identifier' && root.callee.name === FF_GETTER_BOOLEAN_IDENTIFIER);
|
|
11
|
+
|
|
12
|
+
// shouldn't ever get here but just in case
|
|
13
|
+
case 'Identifier':
|
|
14
|
+
return root.name !== FF_GETTER_BOOLEAN_IDENTIFIER;
|
|
15
|
+
case 'BinaryExpression':
|
|
16
|
+
case 'LogicalExpression':
|
|
17
|
+
return __isOnlyOneFlagCheckInExpression(root.left, ignoredNode) && __isOnlyOneFlagCheckInExpression(root.right, ignoredNode);
|
|
18
|
+
default:
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const isOnlyOneFlagCheckInExpression = node => {
|
|
23
|
+
let root = node.parent;
|
|
24
|
+
// find the root node of the expression
|
|
25
|
+
while (root.type === 'LogicalExpression') {
|
|
26
|
+
root = root.parent;
|
|
27
|
+
}
|
|
28
|
+
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
29
|
+
};
|
|
30
|
+
const rule = {
|
|
31
|
+
meta: {
|
|
32
|
+
hasSuggestions: false,
|
|
33
|
+
docs: {
|
|
34
|
+
recommended: false
|
|
35
|
+
},
|
|
36
|
+
type: 'problem',
|
|
37
|
+
messages: {
|
|
38
|
+
onlyInlineIf: "Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
39
|
+
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
40
|
+
multipleFlagCheckInExpression: `Only check one flag per expression! See http://go/pff-eslint for more details`
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
create(context) {
|
|
44
|
+
return {
|
|
45
|
+
[`CallExpression[callee.name=/${FF_GETTER_BOOLEAN_IDENTIFIER}/]`]: node => {
|
|
46
|
+
// to make typescript happy
|
|
47
|
+
if (node.type === 'CallExpression') {
|
|
48
|
+
var _node$parent;
|
|
49
|
+
const args = node.arguments;
|
|
50
|
+
if (args.length === 1 && args[0].type !== 'Literal') {
|
|
51
|
+
return context.report({
|
|
52
|
+
node,
|
|
53
|
+
messageId: 'onlyStringLiteral'
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
57
|
+
case 'IfStatement':
|
|
58
|
+
case 'ConditionalExpression':
|
|
59
|
+
break;
|
|
60
|
+
case 'LogicalExpression':
|
|
61
|
+
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
62
|
+
context.report({
|
|
63
|
+
node,
|
|
64
|
+
messageId: 'multipleFlagCheckInExpression'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
return context.report({
|
|
70
|
+
node,
|
|
71
|
+
messageId: 'onlyInlineIf'
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
export default rule;
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
import ensureFeatureFlagRegistration from './rules/ensure-feature-flag-registration';
|
|
2
|
+
import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
|
|
3
|
+
import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
|
|
4
|
+
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
2
5
|
export var rules = {
|
|
3
|
-
'ensure-feature-flag-registration': ensureFeatureFlagRegistration
|
|
6
|
+
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
7
|
+
'ensure-test-runner-arguments': ensureTestRunnerArguments,
|
|
8
|
+
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
9
|
+
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage
|
|
4
10
|
};
|
|
5
11
|
export var configs = {
|
|
6
12
|
recommended: {
|
|
7
13
|
plugins: ['@atlaskit/platform'],
|
|
8
14
|
rules: {
|
|
9
|
-
'@atlaskit/platform/ensure-feature-flag-registration': 'error'
|
|
15
|
+
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
16
|
+
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
17
|
+
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
18
|
+
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
|
|
10
19
|
}
|
|
11
20
|
}
|
|
12
21
|
};
|
|
@@ -24,34 +24,6 @@ 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
|
-
};
|
|
55
27
|
var rule = {
|
|
56
28
|
meta: {
|
|
57
29
|
hasSuggestions: false,
|
|
@@ -60,11 +32,8 @@ var rule = {
|
|
|
60
32
|
},
|
|
61
33
|
type: 'problem',
|
|
62
34
|
messages: {
|
|
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",
|
|
64
|
-
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
65
35
|
registrationSectionMissing: 'Please add a "platform-feature-flags" section to 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"
|
|
36
|
+
featureFlagMissing: "Please add a \"{{ featureFlag }}\" section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details"
|
|
68
37
|
}
|
|
69
38
|
},
|
|
70
39
|
create: function create(context) {
|
|
@@ -72,33 +41,7 @@ var rule = {
|
|
|
72
41
|
'CallExpression[callee.name=/getBooleanFF/]': function CallExpressionCalleeNameGetBooleanFF(node) {
|
|
73
42
|
// to make typescript happy
|
|
74
43
|
if (node.type === 'CallExpression') {
|
|
75
|
-
var _node$parent;
|
|
76
44
|
var args = node.arguments;
|
|
77
|
-
if (args.length === 1 && args[0].type !== 'Literal') {
|
|
78
|
-
return context.report({
|
|
79
|
-
node: node,
|
|
80
|
-
messageId: 'onlyStringLiteral'
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
84
|
-
case 'IfStatement':
|
|
85
|
-
case 'ConditionalExpression':
|
|
86
|
-
break;
|
|
87
|
-
case 'LogicalExpression':
|
|
88
|
-
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
89
|
-
context.report({
|
|
90
|
-
node: node,
|
|
91
|
-
messageId: 'multipleFlagCheckInExpression'
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
break;
|
|
95
|
-
default:
|
|
96
|
-
return context.report({
|
|
97
|
-
node: node,
|
|
98
|
-
messageId: 'onlyInlineIf'
|
|
99
|
-
});
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
45
|
var filename = context.getFilename();
|
|
103
46
|
var packageJson = getPackageJsonForFileName(filename);
|
|
104
47
|
var platformFeatureFlags = packageJson['platform-feature-flags'];
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
var TEST_RUNNER_IDENTIFIER = 'ffTest';
|
|
3
|
+
var rule = {
|
|
4
|
+
meta: {
|
|
5
|
+
docs: {
|
|
6
|
+
recommended: false
|
|
7
|
+
},
|
|
8
|
+
type: 'problem',
|
|
9
|
+
messages: {
|
|
10
|
+
onlyInlineFeatureFlag: 'Only pass in feature flag as string literal, please replace {{identifierName}} with its value.',
|
|
11
|
+
onlyInlineTestFunction: 'Only pass in test functions/cases in an inline manner. Test functions/cases should be passed in directly, instead of as variables. Please replace {{identifierName}} with its own definition.',
|
|
12
|
+
passDownExistingFeatureFlagParam: 'Existing feature flags need to be passed down as params when calling nested test runner. See examples in the package which declares this function.',
|
|
13
|
+
passDownExistingFeatureFlagArgument: 'Existing feature flags need to be passed in as argument when calling nested test runner. See examples in the package which declares this function.',
|
|
14
|
+
passDownExistingFeatureFlagNamesMatch: 'Argument names not matching when passing down existing feature flags. See examples in the package which declares this function.'
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
create: function create(context) {
|
|
18
|
+
return _defineProperty({}, "CallExpression[callee.name=/".concat(TEST_RUNNER_IDENTIFIER, "/]"), function CallExpressionCalleeName(node) {
|
|
19
|
+
if (node.type === 'CallExpression') {
|
|
20
|
+
var _node$parent, _node$parent2;
|
|
21
|
+
var args = node.arguments;
|
|
22
|
+
|
|
23
|
+
// Verify FF is passed inline
|
|
24
|
+
if (args[0] && args[0].type !== 'Literal') {
|
|
25
|
+
return context.report({
|
|
26
|
+
node: node,
|
|
27
|
+
messageId: 'onlyInlineFeatureFlag',
|
|
28
|
+
data: {
|
|
29
|
+
identifierName: args[0].type === 'Identifier' ? args[0].name : ''
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Verify test functions/cases are passed inline
|
|
35
|
+
if (args[1] && args[1].type !== 'ArrowFunctionExpression') {
|
|
36
|
+
return context.report({
|
|
37
|
+
node: node,
|
|
38
|
+
messageId: 'onlyInlineTestFunction',
|
|
39
|
+
data: {
|
|
40
|
+
identifierName: args[1].type === 'Identifier' ? args[1].name : ''
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (args[2] && args[2].type !== 'ArrowFunctionExpression') {
|
|
45
|
+
return context.report({
|
|
46
|
+
node: node,
|
|
47
|
+
messageId: 'onlyInlineTestFunction',
|
|
48
|
+
data: {
|
|
49
|
+
identifierName: args[2].type === 'Identifier' ? args[2].name : ''
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Verify existing ff overrides are passed down if test runner is nested
|
|
55
|
+
var upperTestRunner = (_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.parent;
|
|
56
|
+
if ((upperTestRunner === null || upperTestRunner === void 0 ? void 0 : upperTestRunner.type) === 'CallExpression' && (upperTestRunner === null || upperTestRunner === void 0 ? void 0 : upperTestRunner.callee.type) === 'Identifier' && (upperTestRunner === null || upperTestRunner === void 0 ? void 0 : upperTestRunner.callee.name) === TEST_RUNNER_IDENTIFIER && ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.type) === 'ArrowFunctionExpression') {
|
|
57
|
+
// Not pass in ff to the function that calls test runner
|
|
58
|
+
if (!node.parent.params[0] || node.parent.params[0].type !== 'Identifier') {
|
|
59
|
+
return context.report({
|
|
60
|
+
node: node,
|
|
61
|
+
messageId: 'passDownExistingFeatureFlagParam'
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Not pass in ff to test runner as 4th argument
|
|
66
|
+
if (!node.arguments[3] || node.arguments[3].type !== 'Identifier') {
|
|
67
|
+
return context.report({
|
|
68
|
+
node: node,
|
|
69
|
+
messageId: 'passDownExistingFeatureFlagArgument'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
// Pass in the above two, but names don't match
|
|
73
|
+
var paramName = node.parent.params[0].name;
|
|
74
|
+
var arguName = node.arguments[3].name;
|
|
75
|
+
if (paramName !== arguName) {
|
|
76
|
+
return context.report({
|
|
77
|
+
node: node,
|
|
78
|
+
messageId: 'passDownExistingFeatureFlagNamesMatch'
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return {};
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export default rule;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
var NESTED_LIMIT = 4;
|
|
5
|
+
var TEST_RUNNER_IDENTIFIER = 'ffTest';
|
|
6
|
+
var getDepthOfNestedRunner = function getDepthOfNestedRunner(node) {
|
|
7
|
+
// Calculate the depth of a binary tree, using a queue to track path
|
|
8
|
+
var queue = [];
|
|
9
|
+
queue.push(node);
|
|
10
|
+
var depth = 0;
|
|
11
|
+
while (queue.length > 0) {
|
|
12
|
+
var nodeCount = queue.length;
|
|
13
|
+
while (nodeCount > 0) {
|
|
14
|
+
var _currentNode$argument;
|
|
15
|
+
var currentNode = queue.shift();
|
|
16
|
+
if (currentNode.arguments[1].type === 'ArrowFunctionExpression' && currentNode.arguments[1].body.type === 'CallExpression' && currentNode.arguments[1].body.callee.type === 'Identifier' && currentNode.arguments[1].body.callee.name === TEST_RUNNER_IDENTIFIER) {
|
|
17
|
+
queue.push(_objectSpread(_objectSpread({}, currentNode.arguments[1].body), {}, {
|
|
18
|
+
parent: currentNode.parent
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
if (((_currentNode$argument = currentNode.arguments[2]) === null || _currentNode$argument === void 0 ? void 0 : _currentNode$argument.type) === 'ArrowFunctionExpression' && currentNode.arguments[2].body.type === 'CallExpression' && currentNode.arguments[2].body.callee.type === 'Identifier' && currentNode.arguments[2].body.callee.name === TEST_RUNNER_IDENTIFIER) {
|
|
22
|
+
queue.push(_objectSpread(_objectSpread({}, currentNode.arguments[2].body), {}, {
|
|
23
|
+
parent: currentNode.parent
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
nodeCount--;
|
|
27
|
+
}
|
|
28
|
+
depth++;
|
|
29
|
+
}
|
|
30
|
+
return depth;
|
|
31
|
+
};
|
|
32
|
+
var rule = {
|
|
33
|
+
meta: {
|
|
34
|
+
docs: {
|
|
35
|
+
recommended: false
|
|
36
|
+
},
|
|
37
|
+
type: 'problem',
|
|
38
|
+
messages: {
|
|
39
|
+
tooManyNestedTestRunner: '{{nestedTestRunner}} test runners are nested. Feature flags may need a clean-up'
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
create: function create(context) {
|
|
43
|
+
return _defineProperty({}, "Program > * > CallExpression[callee.name=/".concat(TEST_RUNNER_IDENTIFIER, "/], CallExpression[callee.name=/describe/] > * > * > * > CallExpression[callee.name=/").concat(TEST_RUNNER_IDENTIFIER, "/]"), function ProgramCallExpressionCalleeNameCallExpressionCalleeNameDescribeCallExpressionCalleeName(node) {
|
|
44
|
+
if (node.type === 'CallExpression') {
|
|
45
|
+
// Calculate the depth of nested test runners, counting from the most outside
|
|
46
|
+
var depth = getDepthOfNestedRunner(node);
|
|
47
|
+
if (depth > NESTED_LIMIT) {
|
|
48
|
+
return context.report({
|
|
49
|
+
node: node,
|
|
50
|
+
messageId: 'tooManyNestedTestRunner',
|
|
51
|
+
data: {
|
|
52
|
+
nestedTestRunner: depth.toString()
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export default rule;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
var FF_GETTER_BOOLEAN_IDENTIFIER = 'getBooleanFF';
|
|
3
|
+
var __isOnlyOneFlagCheckInExpression = function __isOnlyOneFlagCheckInExpression(root, ignoredNode) {
|
|
4
|
+
switch (root.type) {
|
|
5
|
+
case 'IfStatement':
|
|
6
|
+
return __isOnlyOneFlagCheckInExpression(root.test, ignoredNode);
|
|
7
|
+
case 'CallExpression':
|
|
8
|
+
if (root === ignoredNode) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return !(root.callee.type === 'Identifier' && root.callee.name === FF_GETTER_BOOLEAN_IDENTIFIER);
|
|
12
|
+
|
|
13
|
+
// shouldn't ever get here but just in case
|
|
14
|
+
case 'Identifier':
|
|
15
|
+
return root.name !== FF_GETTER_BOOLEAN_IDENTIFIER;
|
|
16
|
+
case 'BinaryExpression':
|
|
17
|
+
case 'LogicalExpression':
|
|
18
|
+
return __isOnlyOneFlagCheckInExpression(root.left, ignoredNode) && __isOnlyOneFlagCheckInExpression(root.right, ignoredNode);
|
|
19
|
+
default:
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
var isOnlyOneFlagCheckInExpression = function isOnlyOneFlagCheckInExpression(node) {
|
|
24
|
+
var root = node.parent;
|
|
25
|
+
// find the root node of the expression
|
|
26
|
+
while (root.type === 'LogicalExpression') {
|
|
27
|
+
root = root.parent;
|
|
28
|
+
}
|
|
29
|
+
return __isOnlyOneFlagCheckInExpression(root, node);
|
|
30
|
+
};
|
|
31
|
+
var rule = {
|
|
32
|
+
meta: {
|
|
33
|
+
hasSuggestions: false,
|
|
34
|
+
docs: {
|
|
35
|
+
recommended: false
|
|
36
|
+
},
|
|
37
|
+
type: 'problem',
|
|
38
|
+
messages: {
|
|
39
|
+
onlyInlineIf: "Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
40
|
+
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
41
|
+
multipleFlagCheckInExpression: "Only check one flag per expression! See http://go/pff-eslint for more details"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
create: function create(context) {
|
|
45
|
+
return _defineProperty({}, "CallExpression[callee.name=/".concat(FF_GETTER_BOOLEAN_IDENTIFIER, "/]"), function CallExpressionCalleeName(node) {
|
|
46
|
+
// to make typescript happy
|
|
47
|
+
if (node.type === 'CallExpression') {
|
|
48
|
+
var _node$parent;
|
|
49
|
+
var args = node.arguments;
|
|
50
|
+
if (args.length === 1 && args[0].type !== 'Literal') {
|
|
51
|
+
return context.report({
|
|
52
|
+
node: node,
|
|
53
|
+
messageId: 'onlyStringLiteral'
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
57
|
+
case 'IfStatement':
|
|
58
|
+
case 'ConditionalExpression':
|
|
59
|
+
break;
|
|
60
|
+
case 'LogicalExpression':
|
|
61
|
+
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
62
|
+
context.report({
|
|
63
|
+
node: node,
|
|
64
|
+
messageId: 'multipleFlagCheckInExpression'
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
return context.report({
|
|
70
|
+
node: node,
|
|
71
|
+
messageId: 'onlyInlineIf'
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
export default rule;
|
package/dist/esm/version.json
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
export declare const rules: {
|
|
2
2
|
'ensure-feature-flag-registration': import("eslint").Rule.RuleModule;
|
|
3
|
+
'ensure-test-runner-arguments': import("eslint").Rule.RuleModule;
|
|
4
|
+
'ensure-test-runner-nested-count': import("eslint").Rule.RuleModule;
|
|
5
|
+
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
|
3
6
|
};
|
|
4
7
|
export declare const configs: {
|
|
5
8
|
recommended: {
|
|
6
9
|
plugins: string[];
|
|
7
10
|
rules: {
|
|
8
11
|
'@atlaskit/platform/ensure-feature-flag-registration': string;
|
|
12
|
+
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
13
|
+
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
14
|
+
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
9
15
|
};
|
|
10
16
|
};
|
|
11
17
|
};
|
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.6",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
package/report.api.md
CHANGED
|
@@ -23,6 +23,9 @@ export const configs: {
|
|
|
23
23
|
plugins: string[];
|
|
24
24
|
rules: {
|
|
25
25
|
'@atlaskit/platform/ensure-feature-flag-registration': string;
|
|
26
|
+
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
27
|
+
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
28
|
+
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
26
29
|
};
|
|
27
30
|
};
|
|
28
31
|
};
|
|
@@ -30,6 +33,9 @@ export const configs: {
|
|
|
30
33
|
// @public (undocumented)
|
|
31
34
|
export const rules: {
|
|
32
35
|
'ensure-feature-flag-registration': Rule.RuleModule;
|
|
36
|
+
'ensure-test-runner-arguments': Rule.RuleModule;
|
|
37
|
+
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
38
|
+
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
// (No @packageDocumentation comment for this package)
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import ensureFeatureFlagRegistration from './rules/ensure-feature-flag-registration';
|
|
2
|
+
import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
|
|
3
|
+
import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
|
|
4
|
+
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
2
5
|
|
|
3
6
|
export const rules = {
|
|
4
7
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
8
|
+
'ensure-test-runner-arguments': ensureTestRunnerArguments,
|
|
9
|
+
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
10
|
+
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
5
11
|
};
|
|
6
12
|
|
|
7
13
|
export const configs = {
|
|
@@ -9,6 +15,9 @@ export const configs = {
|
|
|
9
15
|
plugins: ['@atlaskit/platform'],
|
|
10
16
|
rules: {
|
|
11
17
|
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
18
|
+
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
19
|
+
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
20
|
+
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
|
|
12
21
|
},
|
|
13
22
|
},
|
|
14
23
|
};
|
|
@@ -34,49 +34,14 @@ describe('with existing platform-feature-flags section', () => {
|
|
|
34
34
|
tester.run('ensure-feature-flag-registration', rule, {
|
|
35
35
|
valid: [
|
|
36
36
|
{
|
|
37
|
-
|
|
38
|
-
code: `if(getBooleanFF('test-flag')) { }`,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
// ConditionalExpression
|
|
42
|
-
code: `const val = getBooleanFF('test-flag') ? 'yay' : 'no';`,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
// LogicalExpression
|
|
46
|
-
code: `const val = 100 + (getBooleanFF('test-flag') && 50 || 10);`,
|
|
37
|
+
code: `getBooleanFF('test-flag')`,
|
|
47
38
|
},
|
|
48
39
|
],
|
|
49
40
|
invalid: [
|
|
50
41
|
{
|
|
51
|
-
code: `getBooleanFF('
|
|
52
|
-
errors: [{ messageId: 'onlyInlineIf' }],
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
code: `const val = getBooleanFF('test-flag')`,
|
|
56
|
-
errors: [{ messageId: 'onlyInlineIf' }],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
code: `if(getBooleanFF('invalid-flag')) { }`,
|
|
42
|
+
code: `getBooleanFF('invalid-flag')`,
|
|
60
43
|
errors: [{ messageId: 'featureFlagMissing' }],
|
|
61
44
|
},
|
|
62
|
-
{
|
|
63
|
-
code: `const ff = "test-flag"; if(getBooleanFF(ff)) { }`,
|
|
64
|
-
errors: [{ messageId: 'onlyStringLiteral' }],
|
|
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
|
-
},
|
|
80
45
|
],
|
|
81
46
|
});
|
|
82
47
|
});
|
|
@@ -33,51 +33,6 @@ 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
|
-
|
|
81
36
|
const rule: Rule.RuleModule = {
|
|
82
37
|
meta: {
|
|
83
38
|
hasSuggestions: false,
|
|
@@ -86,14 +41,9 @@ const rule: Rule.RuleModule = {
|
|
|
86
41
|
},
|
|
87
42
|
type: 'problem',
|
|
88
43
|
messages: {
|
|
89
|
-
onlyInlineIf:
|
|
90
|
-
"Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
91
|
-
onlyStringLiteral:
|
|
92
|
-
"Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
93
44
|
registrationSectionMissing:
|
|
94
45
|
'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
95
46
|
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`,
|
|
97
47
|
},
|
|
98
48
|
},
|
|
99
49
|
create(context) {
|
|
@@ -103,33 +53,6 @@ const rule: Rule.RuleModule = {
|
|
|
103
53
|
if (node.type === 'CallExpression') {
|
|
104
54
|
const args = node.arguments;
|
|
105
55
|
|
|
106
|
-
if (args.length === 1 && args[0].type !== 'Literal') {
|
|
107
|
-
return context.report({
|
|
108
|
-
node,
|
|
109
|
-
messageId: 'onlyStringLiteral',
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
switch (node.parent?.type) {
|
|
114
|
-
case 'IfStatement':
|
|
115
|
-
case 'ConditionalExpression':
|
|
116
|
-
break;
|
|
117
|
-
case 'LogicalExpression':
|
|
118
|
-
if (!isOnlyOneFlagCheckInExpression(node)) {
|
|
119
|
-
context.report({
|
|
120
|
-
node,
|
|
121
|
-
messageId: 'multipleFlagCheckInExpression',
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
break;
|
|
125
|
-
default:
|
|
126
|
-
return context.report({
|
|
127
|
-
node,
|
|
128
|
-
messageId: 'onlyInlineIf',
|
|
129
|
-
});
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
56
|
const filename = context.getFilename();
|
|
134
57
|
const packageJson = getPackageJsonForFileName(filename);
|
|
135
58
|
const platformFeatureFlags = packageJson[
|