@atlaskit/eslint-plugin-platform 0.1.2 → 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 CHANGED
@@ -1,5 +1,17 @@
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
+
9
+ ## 0.1.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`7facf919a4e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7facf919a4e) - Remove product specific rules and make it so the recommended set is used everywhere instead
14
+
3
15
  ## 0.1.2
4
16
 
5
17
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -19,19 +19,10 @@ var rules = {
19
19
  };
20
20
  exports.rules = rules;
21
21
  var configs = {
22
- productRecommended: {
23
- plugins: ['@atlaskit/platform'],
24
- rules: {
25
- '@atlaskit/platform/ensure-test-runner-arguments': 'error',
26
- '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
27
- '@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
28
- }
29
- },
30
22
  recommended: {
31
23
  plugins: ['@atlaskit/platform'],
32
24
  rules: {
33
25
  '@atlaskit/platform/ensure-feature-flag-registration': 'error',
34
- '@atlaskit/platform/no-pre-post-install-scripts': 'error',
35
26
  '@atlaskit/platform/ensure-test-runner-arguments': 'error',
36
27
  '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
37
28
  '@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
@@ -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;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-platform",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "sideEffects": false
5
5
  }
@@ -11,19 +11,10 @@ export const rules = {
11
11
  'no-pre-post-install-scripts': noPreAndPostInstallScripts
12
12
  };
13
13
  export const configs = {
14
- productRecommended: {
15
- plugins: ['@atlaskit/platform'],
16
- rules: {
17
- '@atlaskit/platform/ensure-test-runner-arguments': 'error',
18
- '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
19
- '@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
20
- }
21
- },
22
14
  recommended: {
23
15
  plugins: ['@atlaskit/platform'],
24
16
  rules: {
25
17
  '@atlaskit/platform/ensure-feature-flag-registration': 'error',
26
- '@atlaskit/platform/no-pre-post-install-scripts': 'error',
27
18
  '@atlaskit/platform/ensure-test-runner-arguments': 'error',
28
19
  '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
29
20
  '@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
@@ -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;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-platform",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "sideEffects": false
5
5
  }
package/dist/esm/index.js CHANGED
@@ -11,19 +11,10 @@ export var rules = {
11
11
  'no-pre-post-install-scripts': noPreAndPostInstallScripts
12
12
  };
13
13
  export var configs = {
14
- productRecommended: {
15
- plugins: ['@atlaskit/platform'],
16
- rules: {
17
- '@atlaskit/platform/ensure-test-runner-arguments': 'error',
18
- '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
19
- '@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
20
- }
21
- },
22
14
  recommended: {
23
15
  plugins: ['@atlaskit/platform'],
24
16
  rules: {
25
17
  '@atlaskit/platform/ensure-feature-flag-registration': 'error',
26
- '@atlaskit/platform/no-pre-post-install-scripts': 'error',
27
18
  '@atlaskit/platform/ensure-test-runner-arguments': 'error',
28
19
  '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
29
20
  '@atlaskit/platform/no-invalid-feature-flag-usage': 'error'
@@ -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;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-platform",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "sideEffects": false
5
5
  }
@@ -7,19 +7,10 @@ export declare const rules: {
7
7
  'no-pre-post-install-scripts': import("eslint").Rule.RuleModule;
8
8
  };
9
9
  export declare const configs: {
10
- productRecommended: {
11
- plugins: string[];
12
- rules: {
13
- '@atlaskit/platform/ensure-test-runner-arguments': string;
14
- '@atlaskit/platform/ensure-test-runner-nested-count': string;
15
- '@atlaskit/platform/no-invalid-feature-flag-usage': string;
16
- };
17
- };
18
10
  recommended: {
19
11
  plugins: string[];
20
12
  rules: {
21
13
  '@atlaskit/platform/ensure-feature-flag-registration': string;
22
- '@atlaskit/platform/no-pre-post-install-scripts': string;
23
14
  '@atlaskit/platform/ensure-test-runner-arguments': string;
24
15
  '@atlaskit/platform/ensure-test-runner-nested-count': string;
25
16
  '@atlaskit/platform/no-invalid-feature-flag-usage': string;
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.2",
4
+ "version": "0.1.4",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "atlassian": {
7
7
  "team": "UIP - Platform Integration Trust (PITa)",
package/report.api.md CHANGED
@@ -20,19 +20,10 @@ import { Rule } from 'eslint';
20
20
 
21
21
  // @public (undocumented)
22
22
  export const configs: {
23
- productRecommended: {
24
- plugins: string[];
25
- rules: {
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;
29
- };
30
- };
31
23
  recommended: {
32
24
  plugins: string[];
33
25
  rules: {
34
26
  '@atlaskit/platform/ensure-feature-flag-registration': string;
35
- '@atlaskit/platform/no-pre-post-install-scripts': string;
36
27
  '@atlaskit/platform/ensure-test-runner-arguments': string;
37
28
  '@atlaskit/platform/ensure-test-runner-nested-count': string;
38
29
  '@atlaskit/platform/no-invalid-feature-flag-usage': string;
package/src/index.tsx CHANGED
@@ -14,19 +14,10 @@ export const rules = {
14
14
  };
15
15
 
16
16
  export const configs = {
17
- productRecommended: {
18
- plugins: ['@atlaskit/platform'],
19
- rules: {
20
- '@atlaskit/platform/ensure-test-runner-arguments': 'error',
21
- '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
22
- '@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
23
- },
24
- },
25
17
  recommended: {
26
18
  plugins: ['@atlaskit/platform'],
27
19
  rules: {
28
20
  '@atlaskit/platform/ensure-feature-flag-registration': 'error',
29
- '@atlaskit/platform/no-pre-post-install-scripts': 'error',
30
21
  '@atlaskit/platform/ensure-test-runner-arguments': 'error',
31
22
  '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
32
23
  '@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
@@ -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: `getBooleanFF('invalid-flag')`,
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 =
@@ -9,19 +9,10 @@ import { Rule } from 'eslint';
9
9
 
10
10
  // @public (undocumented)
11
11
  export const configs: {
12
- productRecommended: {
13
- plugins: string[];
14
- rules: {
15
- '@atlaskit/platform/ensure-test-runner-arguments': string;
16
- '@atlaskit/platform/ensure-test-runner-nested-count': string;
17
- '@atlaskit/platform/no-invalid-feature-flag-usage': string;
18
- };
19
- };
20
12
  recommended: {
21
13
  plugins: string[];
22
14
  rules: {
23
15
  '@atlaskit/platform/ensure-feature-flag-registration': string;
24
- '@atlaskit/platform/no-pre-post-install-scripts': string;
25
16
  '@atlaskit/platform/ensure-test-runner-arguments': string;
26
17
  '@atlaskit/platform/ensure-test-runner-nested-count': string;
27
18
  '@atlaskit/platform/no-invalid-feature-flag-usage': string;