@atlaskit/eslint-plugin-platform 0.0.5 → 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 +6 -0
- package/dist/cjs/index.js +6 -0
- 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/version.json +1 -1
- package/dist/es2019/index.js +6 -0
- 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/version.json +1 -1
- package/dist/esm/index.js +6 -0
- 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/version.json +1 -1
- package/dist/types/index.d.ts +4 -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/package.json +1 -1
- package/report.api.md +4 -0
- package/src/index.tsx +6 -0
- 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/tmp/api-report-tmp.d.ts +4 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
import type { SimpleCallExpression } from 'estree';
|
|
3
|
+
|
|
4
|
+
const NESTED_LIMIT: number = 4;
|
|
5
|
+
const TEST_RUNNER_IDENTIFIER = 'ffTest' as const;
|
|
6
|
+
|
|
7
|
+
const getDepthOfNestedRunner = (
|
|
8
|
+
node: SimpleCallExpression & Rule.NodeParentExtension,
|
|
9
|
+
): number => {
|
|
10
|
+
// Calculate the depth of a binary tree, using a queue to track path
|
|
11
|
+
let queue: typeof node[] = [];
|
|
12
|
+
queue.push(node);
|
|
13
|
+
let depth = 0;
|
|
14
|
+
while (queue.length > 0) {
|
|
15
|
+
let nodeCount = queue.length;
|
|
16
|
+
while (nodeCount > 0) {
|
|
17
|
+
let currentNode = queue.shift() as typeof node;
|
|
18
|
+
if (
|
|
19
|
+
currentNode.arguments[1].type === 'ArrowFunctionExpression' &&
|
|
20
|
+
currentNode.arguments[1].body.type === 'CallExpression' &&
|
|
21
|
+
currentNode.arguments[1].body.callee.type === 'Identifier' &&
|
|
22
|
+
currentNode.arguments[1].body.callee.name === TEST_RUNNER_IDENTIFIER
|
|
23
|
+
) {
|
|
24
|
+
queue.push({
|
|
25
|
+
...currentNode.arguments[1].body,
|
|
26
|
+
parent: currentNode.parent,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (
|
|
30
|
+
currentNode.arguments[2]?.type === 'ArrowFunctionExpression' &&
|
|
31
|
+
currentNode.arguments[2].body.type === 'CallExpression' &&
|
|
32
|
+
currentNode.arguments[2].body.callee.type === 'Identifier' &&
|
|
33
|
+
currentNode.arguments[2].body.callee.name === TEST_RUNNER_IDENTIFIER
|
|
34
|
+
) {
|
|
35
|
+
queue.push({
|
|
36
|
+
...currentNode.arguments[2].body,
|
|
37
|
+
parent: currentNode.parent,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
nodeCount--;
|
|
41
|
+
}
|
|
42
|
+
depth++;
|
|
43
|
+
}
|
|
44
|
+
return depth;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const rule: Rule.RuleModule = {
|
|
48
|
+
meta: {
|
|
49
|
+
docs: {
|
|
50
|
+
recommended: false,
|
|
51
|
+
},
|
|
52
|
+
type: 'problem',
|
|
53
|
+
messages: {
|
|
54
|
+
tooManyNestedTestRunner:
|
|
55
|
+
'{{nestedTestRunner}} test runners are nested. Feature flags may need a clean-up',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
create(context) {
|
|
59
|
+
return {
|
|
60
|
+
// Find the most outside test runner, could be inside a describe or not
|
|
61
|
+
[`Program > * > CallExpression[callee.name=/${TEST_RUNNER_IDENTIFIER}/], CallExpression[callee.name=/describe/] > * > * > * > CallExpression[callee.name=/${TEST_RUNNER_IDENTIFIER}/]`]:
|
|
62
|
+
(node: Rule.Node) => {
|
|
63
|
+
if (node.type === 'CallExpression') {
|
|
64
|
+
// Calculate the depth of nested test runners, counting from the most outside
|
|
65
|
+
const depth = getDepthOfNestedRunner(node);
|
|
66
|
+
|
|
67
|
+
if (depth > NESTED_LIMIT) {
|
|
68
|
+
return context.report({
|
|
69
|
+
node,
|
|
70
|
+
messageId: 'tooManyNestedTestRunner',
|
|
71
|
+
data: {
|
|
72
|
+
nestedTestRunner: depth.toString(),
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default rule;
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export const configs: {
|
|
|
12
12
|
plugins: string[];
|
|
13
13
|
rules: {
|
|
14
14
|
'@atlaskit/platform/ensure-feature-flag-registration': string;
|
|
15
|
+
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
16
|
+
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
15
17
|
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
16
18
|
};
|
|
17
19
|
};
|
|
@@ -20,6 +22,8 @@ export const configs: {
|
|
|
20
22
|
// @public (undocumented)
|
|
21
23
|
export const rules: {
|
|
22
24
|
'ensure-feature-flag-registration': Rule.RuleModule;
|
|
25
|
+
'ensure-test-runner-arguments': Rule.RuleModule;
|
|
26
|
+
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
23
27
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
24
28
|
};
|
|
25
29
|
|