@atlaskit/eslint-plugin-platform 0.1.3 → 0.1.5
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 +5 -2
- package/dist/cjs/rules/ensure-feature-flag-registration/index.js +18 -2
- package/dist/cjs/rules/no-invalid-storybook-decorator-usage/index.js +38 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/index.js +5 -2
- package/dist/es2019/rules/ensure-feature-flag-registration/index.js +18 -2
- package/dist/es2019/rules/no-invalid-storybook-decorator-usage/index.js +31 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/index.js +5 -2
- package/dist/esm/rules/ensure-feature-flag-registration/index.js +18 -2
- package/dist/esm/rules/no-invalid-storybook-decorator-usage/index.js +30 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/rules/no-invalid-storybook-decorator-usage/index.d.ts +3 -0
- package/package.json +1 -1
- package/report.api.md +2 -0
- package/src/index.tsx +3 -0
- 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/src/rules/no-invalid-storybook-decorator-usage/__tests__/unit/rule.test.tsx +18 -0
- package/src/rules/no-invalid-storybook-decorator-usage/index.tsx +40 -0
- package/tmp/api-report-tmp.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 0.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b47e48ad163`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b47e48ad163) - Adds an eslint rule to confirm that storybooks only get passed an object - to ensure that codemods work correctly.
|
|
8
|
+
|
|
9
|
+
## 0.1.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`971489f4ff4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/971489f4ff4) - Add test runner to identified calls that require registration of platform feature flags
|
|
14
|
+
|
|
3
15
|
## 0.1.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -10,12 +10,14 @@ var _noPrePostInstalls = _interopRequireDefault(require("./rules/no-pre-post-ins
|
|
|
10
10
|
var _ensureTestRunnerArguments = _interopRequireDefault(require("./rules/ensure-test-runner-arguments"));
|
|
11
11
|
var _ensureTestRunnerNestedCount = _interopRequireDefault(require("./rules/ensure-test-runner-nested-count"));
|
|
12
12
|
var _noInvalidFeatureFlagUsage = _interopRequireDefault(require("./rules/no-invalid-feature-flag-usage"));
|
|
13
|
+
var _noInvalidStorybookDecoratorUsage = _interopRequireDefault(require("./rules/no-invalid-storybook-decorator-usage"));
|
|
13
14
|
var rules = {
|
|
14
15
|
'ensure-feature-flag-registration': _ensureFeatureFlagRegistration.default,
|
|
15
16
|
'ensure-test-runner-arguments': _ensureTestRunnerArguments.default,
|
|
16
17
|
'ensure-test-runner-nested-count': _ensureTestRunnerNestedCount.default,
|
|
17
18
|
'no-invalid-feature-flag-usage': _noInvalidFeatureFlagUsage.default,
|
|
18
|
-
'no-pre-post-install-scripts': _noPrePostInstalls.default
|
|
19
|
+
'no-pre-post-install-scripts': _noPrePostInstalls.default,
|
|
20
|
+
'no-invalid-storybook-decorator-usage': _noInvalidStorybookDecoratorUsage.default
|
|
19
21
|
};
|
|
20
22
|
exports.rules = rules;
|
|
21
23
|
var configs = {
|
|
@@ -25,7 +27,8 @@ var configs = {
|
|
|
25
27
|
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
26
28
|
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
27
29
|
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
28
|
-
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
|
|
30
|
+
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
|
|
31
|
+
'@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error'
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
};
|
|
@@ -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;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var STORYBOOK_DECORATOR_IDENTIFIER = 'withPlatformFeatureFlags';
|
|
10
|
+
var rule = {
|
|
11
|
+
meta: {
|
|
12
|
+
hasSuggestions: false,
|
|
13
|
+
docs: {
|
|
14
|
+
recommended: false
|
|
15
|
+
},
|
|
16
|
+
type: 'problem',
|
|
17
|
+
messages: {
|
|
18
|
+
onlyObjectExpression: 'Only object literals allowed in the storybook decorator! See http://go/pff-eslint for more details'
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
create: function create(context) {
|
|
22
|
+
return (0, _defineProperty2.default)({}, "CallExpression[callee.name=/".concat(STORYBOOK_DECORATOR_IDENTIFIER, "/]"), function CallExpressionCalleeName(node) {
|
|
23
|
+
// to make typescript happy
|
|
24
|
+
if (node.type === 'CallExpression') {
|
|
25
|
+
var args = node.arguments;
|
|
26
|
+
if (args.length === 1 && args[0].type !== 'ObjectExpression') {
|
|
27
|
+
return context.report({
|
|
28
|
+
node: node,
|
|
29
|
+
messageId: 'onlyObjectExpression'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return {};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var _default = rule;
|
|
38
|
+
exports.default = _default;
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/index.js
CHANGED
|
@@ -3,12 +3,14 @@ import noPreAndPostInstallScripts from './rules/no-pre-post-installs';
|
|
|
3
3
|
import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
|
|
4
4
|
import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
|
|
5
5
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
6
|
+
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
6
7
|
export const rules = {
|
|
7
8
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
8
9
|
'ensure-test-runner-arguments': ensureTestRunnerArguments,
|
|
9
10
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
10
11
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
11
|
-
'no-pre-post-install-scripts': noPreAndPostInstallScripts
|
|
12
|
+
'no-pre-post-install-scripts': noPreAndPostInstallScripts,
|
|
13
|
+
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage
|
|
12
14
|
};
|
|
13
15
|
export const configs = {
|
|
14
16
|
recommended: {
|
|
@@ -17,7 +19,8 @@ export const configs = {
|
|
|
17
19
|
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
18
20
|
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
19
21
|
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
20
|
-
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
|
|
22
|
+
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
|
|
23
|
+
'@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error'
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
};
|
|
@@ -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;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const STORYBOOK_DECORATOR_IDENTIFIER = 'withPlatformFeatureFlags';
|
|
2
|
+
const rule = {
|
|
3
|
+
meta: {
|
|
4
|
+
hasSuggestions: false,
|
|
5
|
+
docs: {
|
|
6
|
+
recommended: false
|
|
7
|
+
},
|
|
8
|
+
type: 'problem',
|
|
9
|
+
messages: {
|
|
10
|
+
onlyObjectExpression: 'Only object literals allowed in the storybook decorator! See http://go/pff-eslint for more details'
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
create(context) {
|
|
14
|
+
return {
|
|
15
|
+
[`CallExpression[callee.name=/${STORYBOOK_DECORATOR_IDENTIFIER}/]`]: node => {
|
|
16
|
+
// to make typescript happy
|
|
17
|
+
if (node.type === 'CallExpression') {
|
|
18
|
+
const args = node.arguments;
|
|
19
|
+
if (args.length === 1 && args[0].type !== 'ObjectExpression') {
|
|
20
|
+
return context.report({
|
|
21
|
+
node,
|
|
22
|
+
messageId: 'onlyObjectExpression'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export default rule;
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -3,12 +3,14 @@ import noPreAndPostInstallScripts from './rules/no-pre-post-installs';
|
|
|
3
3
|
import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
|
|
4
4
|
import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
|
|
5
5
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
6
|
+
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
6
7
|
export var rules = {
|
|
7
8
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
8
9
|
'ensure-test-runner-arguments': ensureTestRunnerArguments,
|
|
9
10
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
10
11
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
11
|
-
'no-pre-post-install-scripts': noPreAndPostInstallScripts
|
|
12
|
+
'no-pre-post-install-scripts': noPreAndPostInstallScripts,
|
|
13
|
+
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage
|
|
12
14
|
};
|
|
13
15
|
export var configs = {
|
|
14
16
|
recommended: {
|
|
@@ -17,7 +19,8 @@ export var configs = {
|
|
|
17
19
|
'@atlaskit/platform/ensure-feature-flag-registration': 'error',
|
|
18
20
|
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
19
21
|
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
20
|
-
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
|
|
22
|
+
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
|
|
23
|
+
'@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error'
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
};
|
|
@@ -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;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
var STORYBOOK_DECORATOR_IDENTIFIER = 'withPlatformFeatureFlags';
|
|
3
|
+
var rule = {
|
|
4
|
+
meta: {
|
|
5
|
+
hasSuggestions: false,
|
|
6
|
+
docs: {
|
|
7
|
+
recommended: false
|
|
8
|
+
},
|
|
9
|
+
type: 'problem',
|
|
10
|
+
messages: {
|
|
11
|
+
onlyObjectExpression: 'Only object literals allowed in the storybook decorator! See http://go/pff-eslint for more details'
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
create: function create(context) {
|
|
15
|
+
return _defineProperty({}, "CallExpression[callee.name=/".concat(STORYBOOK_DECORATOR_IDENTIFIER, "/]"), function CallExpressionCalleeName(node) {
|
|
16
|
+
// to make typescript happy
|
|
17
|
+
if (node.type === 'CallExpression') {
|
|
18
|
+
var args = node.arguments;
|
|
19
|
+
if (args.length === 1 && args[0].type !== 'ObjectExpression') {
|
|
20
|
+
return context.report({
|
|
21
|
+
node: node,
|
|
22
|
+
messageId: 'onlyObjectExpression'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {};
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
export default rule;
|
package/dist/esm/version.json
CHANGED
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const rules: {
|
|
|
5
5
|
'ensure-test-runner-nested-count': import("eslint").Rule.RuleModule;
|
|
6
6
|
'no-invalid-feature-flag-usage': import("eslint").Rule.RuleModule;
|
|
7
7
|
'no-pre-post-install-scripts': import("eslint").Rule.RuleModule;
|
|
8
|
+
'no-invalid-storybook-decorator-usage': import("eslint").Rule.RuleModule;
|
|
8
9
|
};
|
|
9
10
|
export declare const configs: {
|
|
10
11
|
recommended: {
|
|
@@ -14,6 +15,7 @@ export declare const configs: {
|
|
|
14
15
|
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
15
16
|
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
16
17
|
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
18
|
+
'@atlaskit/platform/no-invalid-storybook-decorator-usage': string;
|
|
17
19
|
};
|
|
18
20
|
};
|
|
19
21
|
};
|
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.5",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "UIP - Platform Integration Trust (PITa)",
|
package/report.api.md
CHANGED
|
@@ -27,6 +27,7 @@ export const configs: {
|
|
|
27
27
|
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
28
28
|
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
29
29
|
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
30
|
+
'@atlaskit/platform/no-invalid-storybook-decorator-usage': string;
|
|
30
31
|
};
|
|
31
32
|
};
|
|
32
33
|
};
|
|
@@ -43,6 +44,7 @@ export const rules: {
|
|
|
43
44
|
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
44
45
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
45
46
|
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
47
|
+
'no-invalid-storybook-decorator-usage': Rule.RuleModule;
|
|
46
48
|
};
|
|
47
49
|
|
|
48
50
|
// (No @packageDocumentation comment for this package)
|
package/src/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import noPreAndPostInstallScripts from './rules/no-pre-post-installs';
|
|
|
4
4
|
import ensureTestRunnerArguments from './rules/ensure-test-runner-arguments';
|
|
5
5
|
import ensureTestRunnerNestedCount from './rules/ensure-test-runner-nested-count';
|
|
6
6
|
import noInvalidFeatureFlagUsage from './rules/no-invalid-feature-flag-usage';
|
|
7
|
+
import noInvalidStorybookDecoratorUsage from './rules/no-invalid-storybook-decorator-usage';
|
|
7
8
|
|
|
8
9
|
export const rules = {
|
|
9
10
|
'ensure-feature-flag-registration': ensureFeatureFlagRegistration,
|
|
@@ -11,6 +12,7 @@ export const rules = {
|
|
|
11
12
|
'ensure-test-runner-nested-count': ensureTestRunnerNestedCount,
|
|
12
13
|
'no-invalid-feature-flag-usage': noInvalidFeatureFlagUsage,
|
|
13
14
|
'no-pre-post-install-scripts': noPreAndPostInstallScripts,
|
|
15
|
+
'no-invalid-storybook-decorator-usage': noInvalidStorybookDecoratorUsage,
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
export const configs = {
|
|
@@ -21,6 +23,7 @@ export const configs = {
|
|
|
21
23
|
'@atlaskit/platform/ensure-test-runner-arguments': 'error',
|
|
22
24
|
'@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
|
|
23
25
|
'@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
|
|
26
|
+
'@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error',
|
|
24
27
|
},
|
|
25
28
|
},
|
|
26
29
|
};
|
|
@@ -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 =
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { tester } from '../../../../__tests__/utils/_tester';
|
|
2
|
+
import rule from '../../index';
|
|
3
|
+
|
|
4
|
+
describe('no-invalid-storybook-decorator-usage tests', () => {
|
|
5
|
+
tester.run('no-invalid-storybook-decorator-usage', rule, {
|
|
6
|
+
valid: [
|
|
7
|
+
{
|
|
8
|
+
code: `withPlatformFeatureFlags({})(<SampleComponent/>)`,
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
invalid: [
|
|
12
|
+
{
|
|
13
|
+
code: `const flags = {'uip.sample.color': true}; withPlatformFeatureFlags(flags)(<SampleComponent/>)`,
|
|
14
|
+
errors: [{ messageId: 'onlyObjectExpression' }],
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
const STORYBOOK_DECORATOR_IDENTIFIER = 'withPlatformFeatureFlags' as const;
|
|
4
|
+
|
|
5
|
+
const rule: Rule.RuleModule = {
|
|
6
|
+
meta: {
|
|
7
|
+
hasSuggestions: false,
|
|
8
|
+
docs: {
|
|
9
|
+
recommended: false,
|
|
10
|
+
},
|
|
11
|
+
type: 'problem',
|
|
12
|
+
messages: {
|
|
13
|
+
onlyObjectExpression:
|
|
14
|
+
'Only object literals allowed in the storybook decorator! See http://go/pff-eslint for more details',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
create(context) {
|
|
18
|
+
return {
|
|
19
|
+
[`CallExpression[callee.name=/${STORYBOOK_DECORATOR_IDENTIFIER}/]`]: (
|
|
20
|
+
node: Rule.Node,
|
|
21
|
+
) => {
|
|
22
|
+
// to make typescript happy
|
|
23
|
+
if (node.type === 'CallExpression') {
|
|
24
|
+
const args = node.arguments;
|
|
25
|
+
|
|
26
|
+
if (args.length === 1 && args[0].type !== 'ObjectExpression') {
|
|
27
|
+
return context.report({
|
|
28
|
+
node,
|
|
29
|
+
messageId: 'onlyObjectExpression',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default rule;
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export const configs: {
|
|
|
16
16
|
'@atlaskit/platform/ensure-test-runner-arguments': string;
|
|
17
17
|
'@atlaskit/platform/ensure-test-runner-nested-count': string;
|
|
18
18
|
'@atlaskit/platform/no-invalid-feature-flag-usage': string;
|
|
19
|
+
'@atlaskit/platform/no-invalid-storybook-decorator-usage': string;
|
|
19
20
|
};
|
|
20
21
|
};
|
|
21
22
|
};
|
|
@@ -32,6 +33,7 @@ export const rules: {
|
|
|
32
33
|
'ensure-test-runner-nested-count': Rule.RuleModule;
|
|
33
34
|
'no-invalid-feature-flag-usage': Rule.RuleModule;
|
|
34
35
|
'no-pre-post-install-scripts': Rule.RuleModule;
|
|
36
|
+
'no-invalid-storybook-decorator-usage': Rule.RuleModule;
|
|
35
37
|
};
|
|
36
38
|
|
|
37
39
|
// (No @packageDocumentation comment for this package)
|