@atlaskit/eslint-plugin-platform 0.1.3 → 0.1.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 +18 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/rules/ensure-feature-flag-registration/index.js +18 -2
- package/dist/es2019/version.json +1 -1
- package/dist/esm/rules/ensure-feature-flag-registration/index.js +18 -2
- package/dist/esm/version.json +1 -1
- package/package.json +1 -1
- package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +36 -1
- package/src/rules/ensure-feature-flag-registration/index.tsx +22 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`971489f4ff4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/971489f4ff4) - Add test runner to identified calls that require registration of platform feature flags
|
|
8
|
+
|
|
3
9
|
## 0.1.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -13,8 +13,10 @@ var _fuse = _interopRequireDefault(require("fuse.js"));
|
|
|
13
13
|
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; }
|
|
14
14
|
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) { (0, _defineProperty2.default)(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; }
|
|
15
15
|
// defines a "getter" to "type" map, if more types are required for feature flags (like string) add it here!
|
|
16
|
+
// if you don't want to verify the type use `null` as the value
|
|
16
17
|
var getterIdentifierToFlagTypeMap = {
|
|
17
|
-
getBooleanFF: 'boolean'
|
|
18
|
+
getBooleanFF: 'boolean',
|
|
19
|
+
ffTest: 'boolean'
|
|
18
20
|
};
|
|
19
21
|
// make sure we cache reading the package.json so we don't end up reading it for every instance of this rule.
|
|
20
22
|
var pkgJsonCache = new Map();
|
|
@@ -54,7 +56,8 @@ var rule = {
|
|
|
54
56
|
messages: {
|
|
55
57
|
registrationSectionMissing: 'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
56
58
|
featureFlagMissing: "Please add a \"{{ featureFlag }}\" section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details",
|
|
57
|
-
changeFeatureFlag: "Change flag key to \"{{ closestFlag }}\" already defined in package.json"
|
|
59
|
+
changeFeatureFlag: "Change flag key to \"{{ closestFlag }}\" already defined in package.json",
|
|
60
|
+
featureFlagIncorrectType: "Please change the type for \"{{ featureFlag }}\" to \"{{ expectedType }}\" in the section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details\""
|
|
58
61
|
},
|
|
59
62
|
hasSuggestions: true
|
|
60
63
|
},
|
|
@@ -78,6 +81,19 @@ var rule = {
|
|
|
78
81
|
if (args.length === 1 && args[0].type === 'Literal' && args[0].raw) {
|
|
79
82
|
var featureFlag = args[0].value;
|
|
80
83
|
var featureFlagRegistration = platformFeatureFlags[featureFlag];
|
|
84
|
+
var expectedType = getterIdentifierToFlagTypeMap[getterIdentifier];
|
|
85
|
+
|
|
86
|
+
// ensure the flag type matches what is registered
|
|
87
|
+
if (featureFlagRegistration != null && expectedType != null && (featureFlagRegistration === null || featureFlagRegistration === void 0 ? void 0 : featureFlagRegistration.type) !== expectedType) {
|
|
88
|
+
return context.report({
|
|
89
|
+
node: args[0],
|
|
90
|
+
messageId: 'featureFlagIncorrectType',
|
|
91
|
+
data: {
|
|
92
|
+
featureFlag: featureFlag,
|
|
93
|
+
expectedType: expectedType
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
81
97
|
if (!featureFlagRegistration) {
|
|
82
98
|
// find the closest match in existing section for suggestion text
|
|
83
99
|
var closestMatchFix = null;
|
package/dist/cjs/version.json
CHANGED
|
@@ -3,8 +3,10 @@ import path from 'path';
|
|
|
3
3
|
import Fuse from 'fuse.js';
|
|
4
4
|
|
|
5
5
|
// defines a "getter" to "type" map, if more types are required for feature flags (like string) add it here!
|
|
6
|
+
// if you don't want to verify the type use `null` as the value
|
|
6
7
|
const getterIdentifierToFlagTypeMap = {
|
|
7
|
-
getBooleanFF: 'boolean'
|
|
8
|
+
getBooleanFF: 'boolean',
|
|
9
|
+
ffTest: 'boolean'
|
|
8
10
|
};
|
|
9
11
|
// make sure we cache reading the package.json so we don't end up reading it for every instance of this rule.
|
|
10
12
|
const pkgJsonCache = new Map();
|
|
@@ -45,7 +47,8 @@ const rule = {
|
|
|
45
47
|
messages: {
|
|
46
48
|
registrationSectionMissing: 'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
47
49
|
featureFlagMissing: `Please add a "{{ featureFlag }}" section to the "platform-feature-flags" section in your package.json. See http://go/pff-eslint for more details`,
|
|
48
|
-
changeFeatureFlag: `Change flag key to "{{ closestFlag }}" already defined in package.json
|
|
50
|
+
changeFeatureFlag: `Change flag key to "{{ closestFlag }}" already defined in package.json`,
|
|
51
|
+
featureFlagIncorrectType: `Please change the type for "{{ featureFlag }}" to "{{ expectedType }}" in the section to the "platform-feature-flags" section in your package.json. See http://go/pff-eslint for more details"`
|
|
49
52
|
},
|
|
50
53
|
hasSuggestions: true
|
|
51
54
|
},
|
|
@@ -69,6 +72,19 @@ const rule = {
|
|
|
69
72
|
if (args.length === 1 && args[0].type === 'Literal' && args[0].raw) {
|
|
70
73
|
const featureFlag = args[0].value;
|
|
71
74
|
const featureFlagRegistration = platformFeatureFlags[featureFlag];
|
|
75
|
+
const expectedType = getterIdentifierToFlagTypeMap[getterIdentifier];
|
|
76
|
+
|
|
77
|
+
// ensure the flag type matches what is registered
|
|
78
|
+
if (featureFlagRegistration != null && expectedType != null && (featureFlagRegistration === null || featureFlagRegistration === void 0 ? void 0 : featureFlagRegistration.type) !== expectedType) {
|
|
79
|
+
return context.report({
|
|
80
|
+
node: args[0],
|
|
81
|
+
messageId: 'featureFlagIncorrectType',
|
|
82
|
+
data: {
|
|
83
|
+
featureFlag,
|
|
84
|
+
expectedType
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
72
88
|
if (!featureFlagRegistration) {
|
|
73
89
|
// find the closest match in existing section for suggestion text
|
|
74
90
|
let closestMatchFix = null;
|
package/dist/es2019/version.json
CHANGED
|
@@ -7,8 +7,10 @@ import path from 'path';
|
|
|
7
7
|
import Fuse from 'fuse.js';
|
|
8
8
|
|
|
9
9
|
// defines a "getter" to "type" map, if more types are required for feature flags (like string) add it here!
|
|
10
|
+
// if you don't want to verify the type use `null` as the value
|
|
10
11
|
var getterIdentifierToFlagTypeMap = {
|
|
11
|
-
getBooleanFF: 'boolean'
|
|
12
|
+
getBooleanFF: 'boolean',
|
|
13
|
+
ffTest: 'boolean'
|
|
12
14
|
};
|
|
13
15
|
// make sure we cache reading the package.json so we don't end up reading it for every instance of this rule.
|
|
14
16
|
var pkgJsonCache = new Map();
|
|
@@ -48,7 +50,8 @@ var rule = {
|
|
|
48
50
|
messages: {
|
|
49
51
|
registrationSectionMissing: 'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
50
52
|
featureFlagMissing: "Please add a \"{{ featureFlag }}\" section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details",
|
|
51
|
-
changeFeatureFlag: "Change flag key to \"{{ closestFlag }}\" already defined in package.json"
|
|
53
|
+
changeFeatureFlag: "Change flag key to \"{{ closestFlag }}\" already defined in package.json",
|
|
54
|
+
featureFlagIncorrectType: "Please change the type for \"{{ featureFlag }}\" to \"{{ expectedType }}\" in the section to the \"platform-feature-flags\" section in your package.json. See http://go/pff-eslint for more details\""
|
|
52
55
|
},
|
|
53
56
|
hasSuggestions: true
|
|
54
57
|
},
|
|
@@ -72,6 +75,19 @@ var rule = {
|
|
|
72
75
|
if (args.length === 1 && args[0].type === 'Literal' && args[0].raw) {
|
|
73
76
|
var featureFlag = args[0].value;
|
|
74
77
|
var featureFlagRegistration = platformFeatureFlags[featureFlag];
|
|
78
|
+
var expectedType = getterIdentifierToFlagTypeMap[getterIdentifier];
|
|
79
|
+
|
|
80
|
+
// ensure the flag type matches what is registered
|
|
81
|
+
if (featureFlagRegistration != null && expectedType != null && (featureFlagRegistration === null || featureFlagRegistration === void 0 ? void 0 : featureFlagRegistration.type) !== expectedType) {
|
|
82
|
+
return context.report({
|
|
83
|
+
node: args[0],
|
|
84
|
+
messageId: 'featureFlagIncorrectType',
|
|
85
|
+
data: {
|
|
86
|
+
featureFlag: featureFlag,
|
|
87
|
+
expectedType: expectedType
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
75
91
|
if (!featureFlagRegistration) {
|
|
76
92
|
// find the closest match in existing section for suggestion text
|
|
77
93
|
var closestMatchFix = null;
|
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.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
|
@@ -27,6 +27,9 @@ describe('with existing platform-feature-flags section', () => {
|
|
|
27
27
|
'test-flag': {
|
|
28
28
|
type: 'boolean',
|
|
29
29
|
},
|
|
30
|
+
'string-flag': {
|
|
31
|
+
type: 'string',
|
|
32
|
+
},
|
|
30
33
|
},
|
|
31
34
|
};
|
|
32
35
|
});
|
|
@@ -37,10 +40,30 @@ describe('with existing platform-feature-flags section', () => {
|
|
|
37
40
|
{
|
|
38
41
|
code: `getBooleanFF('test-flag')`,
|
|
39
42
|
},
|
|
43
|
+
{
|
|
44
|
+
code: `ffTest('test-flag')`,
|
|
45
|
+
},
|
|
40
46
|
],
|
|
41
47
|
invalid: [
|
|
42
48
|
{
|
|
43
|
-
code: `
|
|
49
|
+
code: `ffTest('test-flag-invalid')`,
|
|
50
|
+
errors: [
|
|
51
|
+
{
|
|
52
|
+
messageId: 'featureFlagMissing',
|
|
53
|
+
suggestions: [
|
|
54
|
+
{
|
|
55
|
+
messageId: 'changeFeatureFlag',
|
|
56
|
+
data: {
|
|
57
|
+
closestFlag: 'test-flag',
|
|
58
|
+
},
|
|
59
|
+
output: `ffTest('test-flag')`,
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
code: `getBooleanFF('test-flag-invalid')`,
|
|
44
67
|
errors: [
|
|
45
68
|
{
|
|
46
69
|
messageId: 'featureFlagMissing',
|
|
@@ -56,6 +79,18 @@ describe('with existing platform-feature-flags section', () => {
|
|
|
56
79
|
},
|
|
57
80
|
],
|
|
58
81
|
},
|
|
82
|
+
{
|
|
83
|
+
code: `getBooleanFF('string-flag')`,
|
|
84
|
+
errors: [
|
|
85
|
+
{
|
|
86
|
+
messageId: 'featureFlagIncorrectType',
|
|
87
|
+
data: {
|
|
88
|
+
featureFlag: 'string-flag',
|
|
89
|
+
expectedType: 'boolean',
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
59
94
|
],
|
|
60
95
|
});
|
|
61
96
|
});
|
|
@@ -4,8 +4,10 @@ import path from 'path';
|
|
|
4
4
|
import Fuse from 'fuse.js';
|
|
5
5
|
|
|
6
6
|
// defines a "getter" to "type" map, if more types are required for feature flags (like string) add it here!
|
|
7
|
+
// if you don't want to verify the type use `null` as the value
|
|
7
8
|
const getterIdentifierToFlagTypeMap = {
|
|
8
9
|
getBooleanFF: 'boolean' as const,
|
|
10
|
+
ffTest: 'boolean' as const,
|
|
9
11
|
} as const;
|
|
10
12
|
|
|
11
13
|
type PlatformFeatureFlagRegistrationSection = {
|
|
@@ -69,6 +71,7 @@ const rule: Rule.RuleModule = {
|
|
|
69
71
|
'Please add a "platform-feature-flags" section to your package.json! See http://go/pff-eslint for more details',
|
|
70
72
|
featureFlagMissing: `Please add a "{{ featureFlag }}" section to the "platform-feature-flags" section in your package.json. See http://go/pff-eslint for more details`,
|
|
71
73
|
changeFeatureFlag: `Change flag key to "{{ closestFlag }}" already defined in package.json`,
|
|
74
|
+
featureFlagIncorrectType: `Please change the type for "{{ featureFlag }}" to "{{ expectedType }}" in the section to the "platform-feature-flags" section in your package.json. See http://go/pff-eslint for more details"`,
|
|
72
75
|
},
|
|
73
76
|
|
|
74
77
|
hasSuggestions: true,
|
|
@@ -106,6 +109,25 @@ const rule: Rule.RuleModule = {
|
|
|
106
109
|
const featureFlag = args[0].value as string;
|
|
107
110
|
const featureFlagRegistration = platformFeatureFlags[featureFlag];
|
|
108
111
|
|
|
112
|
+
const expectedType =
|
|
113
|
+
getterIdentifierToFlagTypeMap[getterIdentifier];
|
|
114
|
+
|
|
115
|
+
// ensure the flag type matches what is registered
|
|
116
|
+
if (
|
|
117
|
+
featureFlagRegistration != null &&
|
|
118
|
+
expectedType != null &&
|
|
119
|
+
featureFlagRegistration?.type !== expectedType
|
|
120
|
+
) {
|
|
121
|
+
return context.report({
|
|
122
|
+
node: args[0],
|
|
123
|
+
messageId: 'featureFlagIncorrectType',
|
|
124
|
+
data: {
|
|
125
|
+
featureFlag,
|
|
126
|
+
expectedType,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
109
131
|
if (!featureFlagRegistration) {
|
|
110
132
|
// find the closest match in existing section for suggestion text
|
|
111
133
|
let closestMatchFix: Rule.SuggestionReportDescriptor | null =
|