@atlaskit/eslint-plugin-platform 0.4.0 → 0.4.1
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/afm-cc/tsconfig.json +21 -0
- package/dist/cjs/rules/no-invalid-feature-flag-usage/index.js +22 -1
- package/dist/es2019/rules/no-invalid-feature-flag-usage/index.js +22 -1
- package/dist/esm/rules/no-invalid-feature-flag-usage/index.js +22 -1
- package/package.json +1 -1
- package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +9 -0
- package/src/rules/no-invalid-feature-flag-usage/index.tsx +24 -0
- package/tmp/api-report-tmp.d.ts +0 -50
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#78702](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/78702) [`6b76dabb8255`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6b76dabb8255) - Add rule to check for invalid flag usages in exports
|
|
8
|
+
|
|
3
9
|
## 0.4.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.confluence.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"composite": true,
|
|
6
|
+
"outDir": "../dist",
|
|
7
|
+
"rootDir": "../",
|
|
8
|
+
"baseUrl": "../"
|
|
9
|
+
},
|
|
10
|
+
"include": [
|
|
11
|
+
"../src/**/*.ts",
|
|
12
|
+
"../src/**/*.tsx"
|
|
13
|
+
],
|
|
14
|
+
"exclude": [
|
|
15
|
+
"../src/**/__tests__/*",
|
|
16
|
+
"../__tests__/*",
|
|
17
|
+
"../src/**/*.test.*",
|
|
18
|
+
"../src/**/test.*"
|
|
19
|
+
],
|
|
20
|
+
"references": []
|
|
21
|
+
}
|
|
@@ -50,11 +50,13 @@ var rule = {
|
|
|
50
50
|
messages: {
|
|
51
51
|
onlyInlineIf: "Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
52
52
|
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
53
|
-
multipleFlagCheckInExpression: "Only check one flag per expression! See http://go/pff-eslint for more details"
|
|
53
|
+
multipleFlagCheckInExpression: "Only check one flag per expression! See http://go/pff-eslint for more details",
|
|
54
|
+
noModuleScope: "Don't use platform feature flags in module scope! See http://go/pff-eslint for more details"
|
|
54
55
|
}
|
|
55
56
|
},
|
|
56
57
|
create: function create(context) {
|
|
57
58
|
return (0, _defineProperty2.default)({}, "CallExpression[callee.name=/".concat(FF_GETTER_BOOLEAN_IDENTIFIER, "/]"), function CallExpressionCalleeName(node) {
|
|
59
|
+
var _node$parent2;
|
|
58
60
|
// to make typescript happy
|
|
59
61
|
if (node.type === 'CallExpression') {
|
|
60
62
|
var _node$parent;
|
|
@@ -67,7 +69,26 @@ var rule = {
|
|
|
67
69
|
}
|
|
68
70
|
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
69
71
|
case 'IfStatement':
|
|
72
|
+
break;
|
|
70
73
|
case 'ConditionalExpression':
|
|
74
|
+
switch ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.parent.type) {
|
|
75
|
+
case 'ExportDefaultDeclaration':
|
|
76
|
+
// handles "export default getBooleanFF('test-flag') ? "this is" : "not good";"
|
|
77
|
+
context.report({
|
|
78
|
+
node: node,
|
|
79
|
+
messageId: 'noModuleScope'
|
|
80
|
+
});
|
|
81
|
+
break;
|
|
82
|
+
case 'VariableDeclarator':
|
|
83
|
+
// handles "export const foo = getBooleanFF('test-flag') ? 'this is' : 'not good';"
|
|
84
|
+
if (node.parent.parent.parent.type === 'VariableDeclaration' && node.parent.parent.parent.parent.type === 'ExportNamedDeclaration') {
|
|
85
|
+
context.report({
|
|
86
|
+
node: node,
|
|
87
|
+
messageId: 'noModuleScope'
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
71
92
|
break;
|
|
72
93
|
case 'UnaryExpression':
|
|
73
94
|
case 'LogicalExpression':
|
|
@@ -42,12 +42,14 @@ const rule = {
|
|
|
42
42
|
messages: {
|
|
43
43
|
onlyInlineIf: "Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
44
44
|
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
45
|
-
multipleFlagCheckInExpression: `Only check one flag per expression! See http://go/pff-eslint for more details
|
|
45
|
+
multipleFlagCheckInExpression: `Only check one flag per expression! See http://go/pff-eslint for more details`,
|
|
46
|
+
noModuleScope: `Don't use platform feature flags in module scope! See http://go/pff-eslint for more details`
|
|
46
47
|
}
|
|
47
48
|
},
|
|
48
49
|
create(context) {
|
|
49
50
|
return {
|
|
50
51
|
[`CallExpression[callee.name=/${FF_GETTER_BOOLEAN_IDENTIFIER}/]`]: node => {
|
|
52
|
+
var _node$parent2;
|
|
51
53
|
// to make typescript happy
|
|
52
54
|
if (node.type === 'CallExpression') {
|
|
53
55
|
var _node$parent;
|
|
@@ -60,7 +62,26 @@ const rule = {
|
|
|
60
62
|
}
|
|
61
63
|
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
62
64
|
case 'IfStatement':
|
|
65
|
+
break;
|
|
63
66
|
case 'ConditionalExpression':
|
|
67
|
+
switch ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.parent.type) {
|
|
68
|
+
case 'ExportDefaultDeclaration':
|
|
69
|
+
// handles "export default getBooleanFF('test-flag') ? "this is" : "not good";"
|
|
70
|
+
context.report({
|
|
71
|
+
node,
|
|
72
|
+
messageId: 'noModuleScope'
|
|
73
|
+
});
|
|
74
|
+
break;
|
|
75
|
+
case 'VariableDeclarator':
|
|
76
|
+
// handles "export const foo = getBooleanFF('test-flag') ? 'this is' : 'not good';"
|
|
77
|
+
if (node.parent.parent.parent.type === 'VariableDeclaration' && node.parent.parent.parent.parent.type === 'ExportNamedDeclaration') {
|
|
78
|
+
context.report({
|
|
79
|
+
node,
|
|
80
|
+
messageId: 'noModuleScope'
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
64
85
|
break;
|
|
65
86
|
case 'UnaryExpression':
|
|
66
87
|
case 'LogicalExpression':
|
|
@@ -43,11 +43,13 @@ var rule = {
|
|
|
43
43
|
messages: {
|
|
44
44
|
onlyInlineIf: "Only call feature flags as part of an expression, don't assign to a variable! See http://go/pff-eslint for more details",
|
|
45
45
|
onlyStringLiteral: "Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
46
|
-
multipleFlagCheckInExpression: "Only check one flag per expression! See http://go/pff-eslint for more details"
|
|
46
|
+
multipleFlagCheckInExpression: "Only check one flag per expression! See http://go/pff-eslint for more details",
|
|
47
|
+
noModuleScope: "Don't use platform feature flags in module scope! See http://go/pff-eslint for more details"
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
50
|
create: function create(context) {
|
|
50
51
|
return _defineProperty({}, "CallExpression[callee.name=/".concat(FF_GETTER_BOOLEAN_IDENTIFIER, "/]"), function CallExpressionCalleeName(node) {
|
|
52
|
+
var _node$parent2;
|
|
51
53
|
// to make typescript happy
|
|
52
54
|
if (node.type === 'CallExpression') {
|
|
53
55
|
var _node$parent;
|
|
@@ -60,7 +62,26 @@ var rule = {
|
|
|
60
62
|
}
|
|
61
63
|
switch ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) {
|
|
62
64
|
case 'IfStatement':
|
|
65
|
+
break;
|
|
63
66
|
case 'ConditionalExpression':
|
|
67
|
+
switch ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.parent.type) {
|
|
68
|
+
case 'ExportDefaultDeclaration':
|
|
69
|
+
// handles "export default getBooleanFF('test-flag') ? "this is" : "not good";"
|
|
70
|
+
context.report({
|
|
71
|
+
node: node,
|
|
72
|
+
messageId: 'noModuleScope'
|
|
73
|
+
});
|
|
74
|
+
break;
|
|
75
|
+
case 'VariableDeclarator':
|
|
76
|
+
// handles "export const foo = getBooleanFF('test-flag') ? 'this is' : 'not good';"
|
|
77
|
+
if (node.parent.parent.parent.type === 'VariableDeclaration' && node.parent.parent.parent.parent.type === 'ExportNamedDeclaration') {
|
|
78
|
+
context.report({
|
|
79
|
+
node: node,
|
|
80
|
+
messageId: 'noModuleScope'
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
64
85
|
break;
|
|
65
86
|
case 'UnaryExpression':
|
|
66
87
|
case 'LogicalExpression':
|
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.4.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
|
@@ -55,6 +55,15 @@ describe('enforce-feature-flag-usage-structure tests', () => {
|
|
|
55
55
|
{ messageId: 'multipleFlagCheckInExpression' },
|
|
56
56
|
],
|
|
57
57
|
},
|
|
58
|
+
{
|
|
59
|
+
code: `export default getBooleanFF('test-flag') ? "this is" : "not good";`,
|
|
60
|
+
errors: [{ messageId: 'noModuleScope' }],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
only: true,
|
|
64
|
+
code: `export const foo = getBooleanFF('test-flag') ? "this is" : "not good";`,
|
|
65
|
+
errors: [{ messageId: 'noModuleScope' }],
|
|
66
|
+
},
|
|
58
67
|
],
|
|
59
68
|
});
|
|
60
69
|
});
|
|
@@ -63,6 +63,7 @@ const rule: Rule.RuleModule = {
|
|
|
63
63
|
onlyStringLiteral:
|
|
64
64
|
"Only get feature flags by string literal, don't use variables! See http://go/pff-eslint for more details",
|
|
65
65
|
multipleFlagCheckInExpression: `Only check one flag per expression! See http://go/pff-eslint for more details`,
|
|
66
|
+
noModuleScope: `Don't use platform feature flags in module scope! See http://go/pff-eslint for more details`,
|
|
66
67
|
},
|
|
67
68
|
},
|
|
68
69
|
create(context) {
|
|
@@ -83,7 +84,30 @@ const rule: Rule.RuleModule = {
|
|
|
83
84
|
|
|
84
85
|
switch (node.parent?.type) {
|
|
85
86
|
case 'IfStatement':
|
|
87
|
+
break;
|
|
86
88
|
case 'ConditionalExpression':
|
|
89
|
+
switch (node.parent?.parent.type) {
|
|
90
|
+
case 'ExportDefaultDeclaration':
|
|
91
|
+
// handles "export default getBooleanFF('test-flag') ? "this is" : "not good";"
|
|
92
|
+
context.report({
|
|
93
|
+
node,
|
|
94
|
+
messageId: 'noModuleScope',
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
case 'VariableDeclarator':
|
|
98
|
+
// handles "export const foo = getBooleanFF('test-flag') ? 'this is' : 'not good';"
|
|
99
|
+
if (
|
|
100
|
+
node.parent.parent.parent.type === 'VariableDeclaration' &&
|
|
101
|
+
node.parent.parent.parent.parent.type ===
|
|
102
|
+
'ExportNamedDeclaration'
|
|
103
|
+
) {
|
|
104
|
+
context.report({
|
|
105
|
+
node,
|
|
106
|
+
messageId: 'noModuleScope',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
87
111
|
break;
|
|
88
112
|
case 'UnaryExpression':
|
|
89
113
|
case 'LogicalExpression':
|
package/tmp/api-report-tmp.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
## API Report File for "@atlaskit/eslint-plugin-platform"
|
|
2
|
-
|
|
3
|
-
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
-
|
|
5
|
-
```ts
|
|
6
|
-
|
|
7
|
-
import type { Linter } from 'eslint';
|
|
8
|
-
import { Rule } from 'eslint';
|
|
9
|
-
|
|
10
|
-
// @public (undocumented)
|
|
11
|
-
export const configs: {
|
|
12
|
-
recommended: {
|
|
13
|
-
plugins: string[];
|
|
14
|
-
rules: {
|
|
15
|
-
'@atlaskit/platform/ensure-feature-flag-registration': string;
|
|
16
|
-
'@atlaskit/platform/ensure-feature-flag-prefix': (string | {
|
|
17
|
-
allowedPrefixes: string[];
|
|
18
|
-
})[];
|
|
19
|
-
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
20
|
-
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
21
|
-
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
22
|
-
'@atlaskit/platform/no-invalid-storybook-decorator-usage': string;
|
|
23
|
-
'@atlaskit/platform/ensure-atlassian-team': string;
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
// @public (undocumented)
|
|
29
|
-
export const processors: {
|
|
30
|
-
'package-json-processor': Linter.Processor<Linter.ProcessorFile | string>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// @public (undocumented)
|
|
34
|
-
export const rules: {
|
|
35
|
-
'ensure-feature-flag-registration': Rule.RuleModule;
|
|
36
|
-
'ensure-feature-flag-prefix': Rule.RuleModule;
|
|
37
|
-
'ensure-test-runner-arguments': Rule.RuleModule;
|
|
38
|
-
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
39
|
-
'ensure-atlassian-team': Rule.RuleModule;
|
|
40
|
-
'ensure-critical-dependency-resolutions': Rule.RuleModule;
|
|
41
|
-
'no-duplicate-dependencies': Rule.RuleModule;
|
|
42
|
-
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
43
|
-
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
44
|
-
'no-invalid-storybook-decorator-usage': Rule.RuleModule;
|
|
45
|
-
'ensure-publish-valid': Rule.RuleModule;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// (No @packageDocumentation comment for this package)
|
|
49
|
-
|
|
50
|
-
```
|