@atlaskit/eslint-plugin-platform 0.6.1 → 0.7.0
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 +103 -28
- package/afm-jira/tsconfig.json +20 -0
- package/dist/cjs/index.js +48 -2
- package/dist/cjs/rules/constants.js +11 -0
- package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +54 -6
- package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +16 -7
- package/dist/cjs/rules/ensure-valid-emotion-css-prop/index.js +91 -0
- package/dist/cjs/rules/inline-usage/index.js +94 -0
- package/dist/cjs/rules/no-alias/index.js +64 -0
- package/dist/cjs/rules/no-module-level-eval/index.js +45 -0
- package/dist/cjs/rules/no-preconditioning/index.js +108 -0
- package/dist/cjs/rules/prefer-fg/index.js +106 -0
- package/dist/cjs/rules/static-feature-flags/index.js +63 -0
- package/dist/cjs/rules/use-recommended-utils/index.js +47 -0
- package/dist/cjs/rules/util/registration-utils.js +2 -1
- package/dist/cjs/rules/utils.js +53 -0
- package/dist/es2019/index.js +52 -2
- package/dist/es2019/rules/constants.js +5 -0
- package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +52 -6
- package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +15 -7
- package/dist/es2019/rules/ensure-valid-emotion-css-prop/index.js +87 -0
- package/dist/es2019/rules/inline-usage/index.js +90 -0
- package/dist/es2019/rules/no-alias/index.js +58 -0
- package/dist/es2019/rules/no-module-level-eval/index.js +39 -0
- package/dist/es2019/rules/no-preconditioning/index.js +105 -0
- package/dist/es2019/rules/prefer-fg/index.js +81 -0
- package/dist/es2019/rules/static-feature-flags/index.js +54 -0
- package/dist/es2019/rules/use-recommended-utils/index.js +41 -0
- package/dist/es2019/rules/util/registration-utils.js +2 -1
- package/dist/es2019/rules/utils.js +29 -0
- package/dist/esm/index.js +48 -2
- package/dist/esm/rules/constants.js +5 -0
- package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +54 -6
- package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +16 -7
- package/dist/esm/rules/ensure-valid-emotion-css-prop/index.js +85 -0
- package/dist/esm/rules/inline-usage/index.js +87 -0
- package/dist/esm/rules/no-alias/index.js +57 -0
- package/dist/esm/rules/no-module-level-eval/index.js +39 -0
- package/dist/esm/rules/no-preconditioning/index.js +102 -0
- package/dist/esm/rules/prefer-fg/index.js +99 -0
- package/dist/esm/rules/static-feature-flags/index.js +56 -0
- package/dist/esm/rules/use-recommended-utils/index.js +41 -0
- package/dist/esm/rules/util/registration-utils.js +2 -1
- package/dist/esm/rules/utils.js +45 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/rules/constants.d.ts +3 -0
- package/dist/types/rules/ensure-valid-emotion-css-prop/index.d.ts +3 -0
- package/dist/types/rules/inline-usage/index.d.ts +3 -0
- package/dist/types/rules/no-alias/index.d.ts +3 -0
- package/dist/types/rules/no-module-level-eval/index.d.ts +3 -0
- package/dist/types/rules/no-preconditioning/index.d.ts +3 -0
- package/dist/types/rules/prefer-fg/index.d.ts +3 -0
- package/dist/types/rules/static-feature-flags/index.d.ts +3 -0
- package/dist/types/rules/use-recommended-utils/index.d.ts +3 -0
- package/dist/types/rules/util/registration-utils.d.ts +1 -0
- package/dist/types/rules/utils.d.ts +7 -0
- package/dist/types-ts4.5/index.d.ts +15 -0
- package/dist/types-ts4.5/rules/constants.d.ts +3 -0
- package/dist/types-ts4.5/rules/ensure-valid-emotion-css-prop/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/inline-usage/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-alias/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-module-level-eval/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/no-preconditioning/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/prefer-fg/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/static-feature-flags/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-recommended-utils/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/util/registration-utils.d.ts +1 -0
- package/dist/types-ts4.5/rules/utils.d.ts +7 -0
- package/index.js +9 -9
- package/package.json +43 -44
- package/report.api.md +31 -30
- package/src/__tests__/utils/_tester.tsx +16 -16
- package/src/index.tsx +102 -51
- package/src/rules/constants.tsx +20 -0
- package/src/rules/ensure-atlassian-team/__tests__/unit/rule.test.ts +19 -19
- package/src/rules/ensure-atlassian-team/index.ts +39 -52
- package/src/rules/ensure-critical-dependency-resolutions/__test__/unit/rule.test.tsx +146 -81
- package/src/rules/ensure-critical-dependency-resolutions/index.tsx +152 -97
- package/src/rules/ensure-feature-flag-prefix/__tests__/unit/rule.test.tsx +51 -51
- package/src/rules/ensure-feature-flag-prefix/index.tsx +65 -80
- package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +97 -97
- package/src/rules/ensure-feature-flag-registration/index.tsx +88 -105
- package/src/rules/ensure-native-and-af-exports-synced/__tests__/unit/rule.test.tsx +180 -180
- package/src/rules/ensure-native-and-af-exports-synced/index.tsx +162 -168
- package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +34 -36
- package/src/rules/ensure-publish-valid/index.ts +66 -81
- package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +93 -93
- package/src/rules/ensure-test-runner-arguments/index.tsx +107 -121
- package/src/rules/ensure-test-runner-nested-count/__tests__/unit/rule.test.tsx +43 -43
- package/src/rules/ensure-test-runner-nested-count/index.tsx +68 -70
- package/src/rules/ensure-valid-emotion-css-prop/__tests__/unit/rule.test.ts +142 -0
- package/src/rules/ensure-valid-emotion-css-prop/index.ts +96 -0
- package/src/rules/inline-usage/README.md +53 -0
- package/src/rules/inline-usage/__tests__/rule.test.tsx +106 -0
- package/src/rules/inline-usage/index.tsx +130 -0
- package/src/rules/no-alias/README.md +29 -0
- package/src/rules/no-alias/__tests__/rule.test.tsx +76 -0
- package/src/rules/no-alias/index.tsx +75 -0
- package/src/rules/no-duplicate-dependencies/__tests__/unit/rule.test.ts +44 -44
- package/src/rules/no-duplicate-dependencies/index.ts +68 -73
- package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +64 -64
- package/src/rules/no-invalid-feature-flag-usage/index.tsx +105 -112
- package/src/rules/no-invalid-storybook-decorator-usage/__tests__/unit/rule.test.tsx +13 -13
- package/src/rules/no-invalid-storybook-decorator-usage/index.tsx +28 -30
- package/src/rules/no-module-level-eval/README.md +53 -0
- package/src/rules/no-module-level-eval/__tests__/test.tsx +133 -0
- package/src/rules/no-module-level-eval/index.tsx +52 -0
- package/src/rules/no-pre-post-installs/__tests__/unit/rule.test.ts +36 -36
- package/src/rules/no-pre-post-installs/index.ts +27 -27
- package/src/rules/no-preconditioning/README.md +69 -0
- package/src/rules/no-preconditioning/__tests__/rule.test.tsx +164 -0
- package/src/rules/no-preconditioning/index.tsx +138 -0
- package/src/rules/prefer-fg/README.md +3 -0
- package/src/rules/prefer-fg/__tests__/rule.test.tsx +83 -0
- package/src/rules/prefer-fg/index.tsx +108 -0
- package/src/rules/static-feature-flags/README.md +3 -0
- package/src/rules/static-feature-flags/__tests__/test.tsx +135 -0
- package/src/rules/static-feature-flags/index.tsx +103 -0
- package/src/rules/use-recommended-utils/README.md +67 -0
- package/src/rules/use-recommended-utils/__tests__/rule.test.tsx +78 -0
- package/src/rules/use-recommended-utils/index.tsx +57 -0
- package/src/rules/util/handle-ast-object.ts +21 -32
- package/src/rules/util/registration-utils.ts +31 -30
- package/src/rules/utils.tsx +46 -0
- package/tsconfig.app.json +35 -35
- package/tsconfig.dev.json +39 -39
|
@@ -2,94 +2,94 @@ import { tester } from '../../../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../../index';
|
|
3
3
|
|
|
4
4
|
describe('Feature Flag can only be passed into ffTest as Literal', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
tester.run('ensure-test-runner-arguments', rule, {
|
|
6
|
+
valid: [
|
|
7
|
+
{
|
|
8
|
+
code: `ffTest('sample.feature.flag', () => {
|
|
9
9
|
const { getByText } = render(<SampleComponent />);
|
|
10
10
|
expect(getByText('SampleComponent')).toBeDefined();
|
|
11
11
|
});`,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
invalid: [
|
|
15
|
+
{
|
|
16
|
+
code: `ffTest(myFeatureFlag, () => {
|
|
17
17
|
const { getByText } = render(<SampleComponent />);
|
|
18
18
|
expect(getByText('SampleComponent')).toBeDefined();
|
|
19
19
|
});`,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
errors: [
|
|
21
|
+
{
|
|
22
|
+
messageId: 'onlyInlineFeatureFlag',
|
|
23
|
+
data: { identifierName: 'myFeatureFlag' },
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
describe('Test functions can only be passed in directly, instead of as variables', () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
tester.run('ensure-test-runner-arguments', rule, {
|
|
33
|
+
valid: [
|
|
34
|
+
{
|
|
35
|
+
code: `ffTest('sample.feature.flag', () => {
|
|
36
36
|
const { getByText } = render(<SampleComponent />);
|
|
37
37
|
expect(getByText('SampleComponent')).toBeDefined();
|
|
38
38
|
});`,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
code: `ffTest('sample.feature.flag', () => {
|
|
42
42
|
const { getByText } = render(<SampleComponent />);
|
|
43
43
|
expect(getByText('SampleComponent')).toBeDefined();
|
|
44
44
|
}, () => {
|
|
45
45
|
const { getByText } = render(<SampleComponent />);
|
|
46
46
|
expect(getByText('AnotherSampleComponent')).toBeDefined();
|
|
47
47
|
});`,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
invalid: [
|
|
51
|
+
{
|
|
52
|
+
code: `ffTest('sample.feature.flag', fnToPassIn);`,
|
|
53
|
+
errors: [
|
|
54
|
+
{
|
|
55
|
+
messageId: 'onlyInlineTestFunction',
|
|
56
|
+
data: { identifierName: 'fnToPassIn' },
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
code: `ffTest('sample.feature.flag', () => {
|
|
62
62
|
const { getByText } = render(<SampleComponent />);
|
|
63
63
|
expect(getByText('SampleComponent')).toBeDefined();
|
|
64
64
|
}, fnToPassInWhenFlagIsDisabled);`,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
errors: [
|
|
66
|
+
{
|
|
67
|
+
messageId: 'onlyInlineTestFunction',
|
|
68
|
+
data: { identifierName: 'fnToPassInWhenFlagIsDisabled' },
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
code: `ffTest('sample.feature.flag', fnToPassInWhenFlagIsEnabled, () => {
|
|
74
74
|
const { getByText } = render(<SampleComponent />);
|
|
75
75
|
expect(getByText('SampleComponent')).toBeDefined();
|
|
76
76
|
},);`,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
errors: [
|
|
78
|
+
{
|
|
79
|
+
messageId: 'onlyInlineTestFunction',
|
|
80
|
+
data: { identifierName: 'fnToPassInWhenFlagIsEnabled' },
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
describe('Verify existing ff overrides are passed down if test runner is nested', () => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
tester.run('ensure-test-runner-arguments', rule, {
|
|
90
|
+
valid: [
|
|
91
|
+
{
|
|
92
|
+
code: `ffTest(
|
|
93
93
|
'uip.sample.color',
|
|
94
94
|
ff =>
|
|
95
95
|
ffTest(
|
|
@@ -115,11 +115,11 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
115
115
|
),
|
|
116
116
|
);
|
|
117
117
|
`,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
invalid: [
|
|
121
|
+
{
|
|
122
|
+
code: `ffTest(
|
|
123
123
|
'uip.sample.color',
|
|
124
124
|
() =>
|
|
125
125
|
ffTest(
|
|
@@ -145,7 +145,7 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
145
145
|
),
|
|
146
146
|
);
|
|
147
147
|
`,
|
|
148
|
-
|
|
148
|
+
output: `ffTest(
|
|
149
149
|
'uip.sample.color',
|
|
150
150
|
ff =>
|
|
151
151
|
ffTest(
|
|
@@ -171,14 +171,14 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
171
171
|
),
|
|
172
172
|
);
|
|
173
173
|
`,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
174
|
+
errors: [
|
|
175
|
+
{
|
|
176
|
+
messageId: 'passDownExistingFeatureFlagParam',
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
code: `ffTest(
|
|
182
182
|
'uip.sample.color',
|
|
183
183
|
ff =>
|
|
184
184
|
ffTest(
|
|
@@ -203,7 +203,7 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
203
203
|
),
|
|
204
204
|
);
|
|
205
205
|
`,
|
|
206
|
-
|
|
206
|
+
output: `ffTest(
|
|
207
207
|
'uip.sample.color',
|
|
208
208
|
ff =>
|
|
209
209
|
ffTest(
|
|
@@ -228,14 +228,14 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
228
228
|
),
|
|
229
229
|
);
|
|
230
230
|
`,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
231
|
+
errors: [
|
|
232
|
+
{
|
|
233
|
+
messageId: 'passDownExistingFeatureFlagArgument',
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
code: `ffTest(
|
|
239
239
|
'uip.sample.color',
|
|
240
240
|
ff =>
|
|
241
241
|
ffTest(
|
|
@@ -261,7 +261,7 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
261
261
|
),
|
|
262
262
|
);
|
|
263
263
|
`,
|
|
264
|
-
|
|
264
|
+
output: `ffTest(
|
|
265
265
|
'uip.sample.color',
|
|
266
266
|
ff =>
|
|
267
267
|
ffTest(
|
|
@@ -287,12 +287,12 @@ describe('Verify existing ff overrides are passed down if test runner is nested'
|
|
|
287
287
|
),
|
|
288
288
|
);
|
|
289
289
|
`,
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
290
|
+
errors: [
|
|
291
|
+
{
|
|
292
|
+
messageId: 'passDownExistingFeatureFlagNamesMatch',
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
});
|
|
298
298
|
});
|
|
@@ -4,132 +4,118 @@ import type { Rule } from 'eslint';
|
|
|
4
4
|
const TEST_RUNNER_IDENTIFIER = 'ffTest' as const;
|
|
5
5
|
|
|
6
6
|
const rule: Rule.RuleModule = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (node.type === 'CallExpression') {
|
|
32
|
-
const args = node.arguments;
|
|
7
|
+
meta: {
|
|
8
|
+
docs: {
|
|
9
|
+
recommended: false,
|
|
10
|
+
},
|
|
11
|
+
type: 'problem',
|
|
12
|
+
fixable: 'code',
|
|
13
|
+
messages: {
|
|
14
|
+
onlyInlineFeatureFlag:
|
|
15
|
+
'Only pass in feature flag as string literal, please replace {{identifierName}} with its value.',
|
|
16
|
+
onlyInlineTestFunction:
|
|
17
|
+
'Only pass in test functions/cases in an inline manner. Test functions/cases should be passed in directly, instead of as variables. Please replace {{identifierName}} with its own definition.',
|
|
18
|
+
passDownExistingFeatureFlagParam:
|
|
19
|
+
'An argument symbolising existing FFs needs to be passed down as param when calling nested test runner. See examples in the package which declares this function.',
|
|
20
|
+
passDownExistingFeatureFlagArgument:
|
|
21
|
+
'An argument symbolising existing FFs needs to be passed in as argument when calling nested test runner. See examples in the package which declares this function.',
|
|
22
|
+
passDownExistingFeatureFlagNamesMatch:
|
|
23
|
+
'Argument names not matching when passing down existing feature flags. See examples in the package which declares this function.',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
create(context) {
|
|
27
|
+
return {
|
|
28
|
+
[`CallExpression[callee.name=/${TEST_RUNNER_IDENTIFIER}/]`]: (node: Rule.Node) => {
|
|
29
|
+
if (node.type === 'CallExpression') {
|
|
30
|
+
const args = node.arguments;
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
32
|
+
// Verify FF is passed inline
|
|
33
|
+
if (args[0] && args[0].type !== 'Literal') {
|
|
34
|
+
return context.report({
|
|
35
|
+
node,
|
|
36
|
+
messageId: 'onlyInlineFeatureFlag',
|
|
37
|
+
data: {
|
|
38
|
+
identifierName: args[0].type === 'Identifier' ? args[0].name : '',
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
43
|
+
// Verify test functions/cases are passed inline
|
|
44
|
+
if (args[1] && args[1].type !== 'ArrowFunctionExpression') {
|
|
45
|
+
return context.report({
|
|
46
|
+
node,
|
|
47
|
+
messageId: 'onlyInlineTestFunction',
|
|
48
|
+
data: {
|
|
49
|
+
identifierName: args[1].type === 'Identifier' ? args[1].name : '',
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}
|
|
57
53
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
54
|
+
if (args[2] && args[2].type !== 'ArrowFunctionExpression') {
|
|
55
|
+
return context.report({
|
|
56
|
+
node,
|
|
57
|
+
messageId: 'onlyInlineTestFunction',
|
|
58
|
+
data: {
|
|
59
|
+
identifierName: args[2].type === 'Identifier' ? args[2].name : '',
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
? fixer.replaceText(node.arguments[3], 'ff')
|
|
94
|
-
: fixer.insertTextAfter(node.arguments[2], ', ff'),
|
|
95
|
-
];
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
}
|
|
64
|
+
// Verify existing ff overrides are passed down if test runner is nested
|
|
65
|
+
let upperTestRunner = node.parent?.parent;
|
|
66
|
+
if (
|
|
67
|
+
upperTestRunner?.type === 'CallExpression' &&
|
|
68
|
+
upperTestRunner?.callee.type === 'Identifier' &&
|
|
69
|
+
upperTestRunner?.callee.name === TEST_RUNNER_IDENTIFIER &&
|
|
70
|
+
node.parent?.type === 'ArrowFunctionExpression'
|
|
71
|
+
) {
|
|
72
|
+
// Not pass in ff to the function that calls test runner
|
|
73
|
+
if (!node.parent.params[0] || node.parent.params[0].type !== 'Identifier') {
|
|
74
|
+
return context.report({
|
|
75
|
+
node: node.parent,
|
|
76
|
+
messageId: 'passDownExistingFeatureFlagParam',
|
|
77
|
+
fix: function (fixer) {
|
|
78
|
+
const parentNodeRange = node.parent.range as [number, number];
|
|
79
|
+
return [
|
|
80
|
+
fixer.replaceTextRange([parentNodeRange[0], parentNodeRange[0] + 2], 'ff'),
|
|
81
|
+
node.arguments[3]
|
|
82
|
+
? fixer.replaceText(node.arguments[3], 'ff')
|
|
83
|
+
: fixer.insertTextAfter(node.arguments[2], ', ff'),
|
|
84
|
+
];
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
99
88
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
},
|
|
89
|
+
// Not pass in ff to test runner as 4th argument
|
|
90
|
+
const paramName = node.parent.params[0].name;
|
|
91
|
+
if (!node.arguments[3] || node.arguments[3].type !== 'Identifier') {
|
|
92
|
+
return context.report({
|
|
93
|
+
node,
|
|
94
|
+
messageId: 'passDownExistingFeatureFlagArgument',
|
|
95
|
+
fix: function (fixer) {
|
|
96
|
+
return node.arguments[3]
|
|
97
|
+
? fixer.replaceText(node.arguments[3], paramName)
|
|
98
|
+
: fixer.insertTextAfter(node.arguments[2], `, ${paramName}`);
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// Pass in the above two, but names don't match
|
|
103
|
+
const arguName = node.arguments[3].name;
|
|
104
|
+
if (paramName !== arguName) {
|
|
105
|
+
return context.report({
|
|
106
|
+
node: node.parent,
|
|
107
|
+
messageId: 'passDownExistingFeatureFlagNamesMatch',
|
|
108
|
+
fix: function (fixer) {
|
|
109
|
+
return fixer.replaceText(node.arguments[3], paramName);
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return {};
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
},
|
|
133
119
|
};
|
|
134
120
|
|
|
135
121
|
export default rule;
|
|
@@ -2,18 +2,18 @@ import { tester } from '../../../../__tests__/utils/_tester';
|
|
|
2
2
|
import rule from '../../index';
|
|
3
3
|
|
|
4
4
|
describe('Warning about too many nested test runners', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
tester.run('ensure-test-runner-nested-count', rule, {
|
|
6
|
+
valid: [
|
|
7
|
+
{
|
|
8
|
+
code: `describe('1 FF', () => {
|
|
9
9
|
ffTest('uip.sample.color', () => {
|
|
10
10
|
const { getByText } = render(<SampleComponent />);
|
|
11
11
|
expect(getByText('SampleComponent')).toBeDefined();
|
|
12
12
|
});
|
|
13
13
|
});`,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
code: `describe('2 FFs', () => {
|
|
17
17
|
ffTest(
|
|
18
18
|
'uip.sample.color',
|
|
19
19
|
ff =>
|
|
@@ -40,9 +40,9 @@ describe('Warning about too many nested test runners', () => {
|
|
|
40
40
|
),
|
|
41
41
|
);
|
|
42
42
|
});`,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
code: `ffTest(
|
|
46
46
|
'uip.sample.color',
|
|
47
47
|
(ff) =>
|
|
48
48
|
ffTest(
|
|
@@ -59,9 +59,9 @@ describe('Warning about too many nested test runners', () => {
|
|
|
59
59
|
ff,
|
|
60
60
|
),
|
|
61
61
|
);`,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
code: `ffTest(
|
|
65
65
|
'uip.sample.color',
|
|
66
66
|
(ff) =>
|
|
67
67
|
ffTest(
|
|
@@ -96,9 +96,9 @@ describe('Warning about too many nested test runners', () => {
|
|
|
96
96
|
ff,
|
|
97
97
|
),
|
|
98
98
|
);`,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
code: `
|
|
102
102
|
ffTest(
|
|
103
103
|
'uip.sample.color',
|
|
104
104
|
(ff) =>
|
|
@@ -152,11 +152,11 @@ describe('Warning about too many nested test runners', () => {
|
|
|
152
152
|
ff,
|
|
153
153
|
),
|
|
154
154
|
);`,
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
},
|
|
156
|
+
],
|
|
157
|
+
invalid: [
|
|
158
|
+
{
|
|
159
|
+
code: `
|
|
160
160
|
describe('5 FFs', () => {
|
|
161
161
|
ffTest(
|
|
162
162
|
'uip.sample.color',
|
|
@@ -218,17 +218,17 @@ describe('Warning about too many nested test runners', () => {
|
|
|
218
218
|
),
|
|
219
219
|
);
|
|
220
220
|
});`,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
221
|
+
errors: [
|
|
222
|
+
{
|
|
223
|
+
messageId: 'tooManyNestedTestRunner',
|
|
224
|
+
data: {
|
|
225
|
+
nestedTestRunner: 5,
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
code: `
|
|
232
232
|
ffTest(
|
|
233
233
|
'uip.sample.color',
|
|
234
234
|
(ff) =>
|
|
@@ -294,15 +294,15 @@ describe('Warning about too many nested test runners', () => {
|
|
|
294
294
|
ff,
|
|
295
295
|
),
|
|
296
296
|
);`,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
297
|
+
errors: [
|
|
298
|
+
{
|
|
299
|
+
messageId: 'tooManyNestedTestRunner',
|
|
300
|
+
data: {
|
|
301
|
+
nestedTestRunner: 6,
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
],
|
|
305
|
+
},
|
|
306
|
+
],
|
|
307
|
+
});
|
|
308
308
|
});
|