@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.
Files changed (126) hide show
  1. package/CHANGELOG.md +103 -28
  2. package/afm-jira/tsconfig.json +20 -0
  3. package/dist/cjs/index.js +48 -2
  4. package/dist/cjs/rules/constants.js +11 -0
  5. package/dist/cjs/rules/ensure-critical-dependency-resolutions/index.js +54 -6
  6. package/dist/cjs/rules/ensure-native-and-af-exports-synced/index.js +16 -7
  7. package/dist/cjs/rules/ensure-valid-emotion-css-prop/index.js +91 -0
  8. package/dist/cjs/rules/inline-usage/index.js +94 -0
  9. package/dist/cjs/rules/no-alias/index.js +64 -0
  10. package/dist/cjs/rules/no-module-level-eval/index.js +45 -0
  11. package/dist/cjs/rules/no-preconditioning/index.js +108 -0
  12. package/dist/cjs/rules/prefer-fg/index.js +106 -0
  13. package/dist/cjs/rules/static-feature-flags/index.js +63 -0
  14. package/dist/cjs/rules/use-recommended-utils/index.js +47 -0
  15. package/dist/cjs/rules/util/registration-utils.js +2 -1
  16. package/dist/cjs/rules/utils.js +53 -0
  17. package/dist/es2019/index.js +52 -2
  18. package/dist/es2019/rules/constants.js +5 -0
  19. package/dist/es2019/rules/ensure-critical-dependency-resolutions/index.js +52 -6
  20. package/dist/es2019/rules/ensure-native-and-af-exports-synced/index.js +15 -7
  21. package/dist/es2019/rules/ensure-valid-emotion-css-prop/index.js +87 -0
  22. package/dist/es2019/rules/inline-usage/index.js +90 -0
  23. package/dist/es2019/rules/no-alias/index.js +58 -0
  24. package/dist/es2019/rules/no-module-level-eval/index.js +39 -0
  25. package/dist/es2019/rules/no-preconditioning/index.js +105 -0
  26. package/dist/es2019/rules/prefer-fg/index.js +81 -0
  27. package/dist/es2019/rules/static-feature-flags/index.js +54 -0
  28. package/dist/es2019/rules/use-recommended-utils/index.js +41 -0
  29. package/dist/es2019/rules/util/registration-utils.js +2 -1
  30. package/dist/es2019/rules/utils.js +29 -0
  31. package/dist/esm/index.js +48 -2
  32. package/dist/esm/rules/constants.js +5 -0
  33. package/dist/esm/rules/ensure-critical-dependency-resolutions/index.js +54 -6
  34. package/dist/esm/rules/ensure-native-and-af-exports-synced/index.js +16 -7
  35. package/dist/esm/rules/ensure-valid-emotion-css-prop/index.js +85 -0
  36. package/dist/esm/rules/inline-usage/index.js +87 -0
  37. package/dist/esm/rules/no-alias/index.js +57 -0
  38. package/dist/esm/rules/no-module-level-eval/index.js +39 -0
  39. package/dist/esm/rules/no-preconditioning/index.js +102 -0
  40. package/dist/esm/rules/prefer-fg/index.js +99 -0
  41. package/dist/esm/rules/static-feature-flags/index.js +56 -0
  42. package/dist/esm/rules/use-recommended-utils/index.js +41 -0
  43. package/dist/esm/rules/util/registration-utils.js +2 -1
  44. package/dist/esm/rules/utils.js +45 -0
  45. package/dist/types/index.d.ts +15 -0
  46. package/dist/types/rules/constants.d.ts +3 -0
  47. package/dist/types/rules/ensure-valid-emotion-css-prop/index.d.ts +3 -0
  48. package/dist/types/rules/inline-usage/index.d.ts +3 -0
  49. package/dist/types/rules/no-alias/index.d.ts +3 -0
  50. package/dist/types/rules/no-module-level-eval/index.d.ts +3 -0
  51. package/dist/types/rules/no-preconditioning/index.d.ts +3 -0
  52. package/dist/types/rules/prefer-fg/index.d.ts +3 -0
  53. package/dist/types/rules/static-feature-flags/index.d.ts +3 -0
  54. package/dist/types/rules/use-recommended-utils/index.d.ts +3 -0
  55. package/dist/types/rules/util/registration-utils.d.ts +1 -0
  56. package/dist/types/rules/utils.d.ts +7 -0
  57. package/dist/types-ts4.5/index.d.ts +15 -0
  58. package/dist/types-ts4.5/rules/constants.d.ts +3 -0
  59. package/dist/types-ts4.5/rules/ensure-valid-emotion-css-prop/index.d.ts +3 -0
  60. package/dist/types-ts4.5/rules/inline-usage/index.d.ts +3 -0
  61. package/dist/types-ts4.5/rules/no-alias/index.d.ts +3 -0
  62. package/dist/types-ts4.5/rules/no-module-level-eval/index.d.ts +3 -0
  63. package/dist/types-ts4.5/rules/no-preconditioning/index.d.ts +3 -0
  64. package/dist/types-ts4.5/rules/prefer-fg/index.d.ts +3 -0
  65. package/dist/types-ts4.5/rules/static-feature-flags/index.d.ts +3 -0
  66. package/dist/types-ts4.5/rules/use-recommended-utils/index.d.ts +3 -0
  67. package/dist/types-ts4.5/rules/util/registration-utils.d.ts +1 -0
  68. package/dist/types-ts4.5/rules/utils.d.ts +7 -0
  69. package/index.js +9 -9
  70. package/package.json +43 -44
  71. package/report.api.md +31 -30
  72. package/src/__tests__/utils/_tester.tsx +16 -16
  73. package/src/index.tsx +102 -51
  74. package/src/rules/constants.tsx +20 -0
  75. package/src/rules/ensure-atlassian-team/__tests__/unit/rule.test.ts +19 -19
  76. package/src/rules/ensure-atlassian-team/index.ts +39 -52
  77. package/src/rules/ensure-critical-dependency-resolutions/__test__/unit/rule.test.tsx +146 -81
  78. package/src/rules/ensure-critical-dependency-resolutions/index.tsx +152 -97
  79. package/src/rules/ensure-feature-flag-prefix/__tests__/unit/rule.test.tsx +51 -51
  80. package/src/rules/ensure-feature-flag-prefix/index.tsx +65 -80
  81. package/src/rules/ensure-feature-flag-registration/__tests__/unit/rule.test.tsx +97 -97
  82. package/src/rules/ensure-feature-flag-registration/index.tsx +88 -105
  83. package/src/rules/ensure-native-and-af-exports-synced/__tests__/unit/rule.test.tsx +180 -180
  84. package/src/rules/ensure-native-and-af-exports-synced/index.tsx +162 -168
  85. package/src/rules/ensure-publish-valid/__tests__/unit/rule.test.ts +34 -36
  86. package/src/rules/ensure-publish-valid/index.ts +66 -81
  87. package/src/rules/ensure-test-runner-arguments/__tests__/unit/rule.test.tsx +93 -93
  88. package/src/rules/ensure-test-runner-arguments/index.tsx +107 -121
  89. package/src/rules/ensure-test-runner-nested-count/__tests__/unit/rule.test.tsx +43 -43
  90. package/src/rules/ensure-test-runner-nested-count/index.tsx +68 -70
  91. package/src/rules/ensure-valid-emotion-css-prop/__tests__/unit/rule.test.ts +142 -0
  92. package/src/rules/ensure-valid-emotion-css-prop/index.ts +96 -0
  93. package/src/rules/inline-usage/README.md +53 -0
  94. package/src/rules/inline-usage/__tests__/rule.test.tsx +106 -0
  95. package/src/rules/inline-usage/index.tsx +130 -0
  96. package/src/rules/no-alias/README.md +29 -0
  97. package/src/rules/no-alias/__tests__/rule.test.tsx +76 -0
  98. package/src/rules/no-alias/index.tsx +75 -0
  99. package/src/rules/no-duplicate-dependencies/__tests__/unit/rule.test.ts +44 -44
  100. package/src/rules/no-duplicate-dependencies/index.ts +68 -73
  101. package/src/rules/no-invalid-feature-flag-usage/__tests__/unit/rule.test.tsx +64 -64
  102. package/src/rules/no-invalid-feature-flag-usage/index.tsx +105 -112
  103. package/src/rules/no-invalid-storybook-decorator-usage/__tests__/unit/rule.test.tsx +13 -13
  104. package/src/rules/no-invalid-storybook-decorator-usage/index.tsx +28 -30
  105. package/src/rules/no-module-level-eval/README.md +53 -0
  106. package/src/rules/no-module-level-eval/__tests__/test.tsx +133 -0
  107. package/src/rules/no-module-level-eval/index.tsx +52 -0
  108. package/src/rules/no-pre-post-installs/__tests__/unit/rule.test.ts +36 -36
  109. package/src/rules/no-pre-post-installs/index.ts +27 -27
  110. package/src/rules/no-preconditioning/README.md +69 -0
  111. package/src/rules/no-preconditioning/__tests__/rule.test.tsx +164 -0
  112. package/src/rules/no-preconditioning/index.tsx +138 -0
  113. package/src/rules/prefer-fg/README.md +3 -0
  114. package/src/rules/prefer-fg/__tests__/rule.test.tsx +83 -0
  115. package/src/rules/prefer-fg/index.tsx +108 -0
  116. package/src/rules/static-feature-flags/README.md +3 -0
  117. package/src/rules/static-feature-flags/__tests__/test.tsx +135 -0
  118. package/src/rules/static-feature-flags/index.tsx +103 -0
  119. package/src/rules/use-recommended-utils/README.md +67 -0
  120. package/src/rules/use-recommended-utils/__tests__/rule.test.tsx +78 -0
  121. package/src/rules/use-recommended-utils/index.tsx +57 -0
  122. package/src/rules/util/handle-ast-object.ts +21 -32
  123. package/src/rules/util/registration-utils.ts +31 -30
  124. package/src/rules/utils.tsx +46 -0
  125. package/tsconfig.app.json +35 -35
  126. package/tsconfig.dev.json +39 -39
package/CHANGELOG.md CHANGED
@@ -1,169 +1,244 @@
1
1
  # @atlaskit/eslint-plugin-platform
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#115707](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/115707)
8
+ [`a5cce078e311b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a5cce078e311b) -
9
+ Add new feature flag rules and add them to the recommended preset as error violations.
10
+
11
+ ## 0.6.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [#104090](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/104090)
16
+ [`3f7cadbe8c81`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3f7cadbe8c81) -
17
+ Fixed an issue with the package.json processor in FlatConfig
18
+
3
19
  ## 0.6.1
4
20
 
5
21
  ### Patch Changes
6
22
 
7
- - [#83116](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83116) [`8d4e99057fe0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8d4e99057fe0) - Upgrade Typescript from `4.9.5` to `5.4.2`
23
+ - [#83116](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83116)
24
+ [`8d4e99057fe0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8d4e99057fe0) -
25
+ Upgrade Typescript from `4.9.5` to `5.4.2`
8
26
 
9
27
  ## 0.6.0
10
28
 
11
29
  ### Minor Changes
12
30
 
13
- - [#82550](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/82550) [`f0948af9e586`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f0948af9e586) - Allow typescript upgrade to 5.x
31
+ - [#82550](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/82550)
32
+ [`f0948af9e586`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f0948af9e586) -
33
+ Allow typescript upgrade to 5.x
14
34
 
15
35
  ## 0.5.0
16
36
 
17
37
  ### Minor Changes
18
38
 
19
- - [#81166](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81166) [`a249a1bd29a6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a249a1bd29a6) - Upgrade ESLint to version 8
39
+ - [#81166](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/81166)
40
+ [`a249a1bd29a6`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/a249a1bd29a6) -
41
+ Upgrade ESLint to version 8
20
42
 
21
43
  ## 0.4.1
22
44
 
23
45
  ### Patch Changes
24
46
 
25
- - [#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
47
+ - [#78702](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/78702)
48
+ [`6b76dabb8255`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/6b76dabb8255) -
49
+ Add rule to check for invalid flag usages in exports
26
50
 
27
51
  ## 0.4.0
28
52
 
29
53
  ### Minor Changes
30
54
 
31
- - [#43563](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43563) [`51f9f6e2f10`](https://bitbucket.org/atlassian/atlassian-frontend/commits/51f9f6e2f10) - Add @types/react v18.2 to critical deps whitelist
55
+ - [#43563](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43563)
56
+ [`51f9f6e2f10`](https://bitbucket.org/atlassian/atlassian-frontend/commits/51f9f6e2f10) - Add
57
+ @types/react v18.2 to critical deps whitelist
32
58
 
33
59
  ## 0.3.0
34
60
 
35
61
  ### Minor Changes
36
62
 
37
- - [#41190](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41190) [`a5047d254d4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a5047d254d4) - Add no-duplicate-dependencies rule and enable package-json-processor autofix
63
+ - [#41190](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41190)
64
+ [`a5047d254d4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a5047d254d4) - Add
65
+ no-duplicate-dependencies rule and enable package-json-processor autofix
38
66
 
39
67
  ## 0.2.6
40
68
 
41
69
  ### Patch Changes
42
70
 
43
- - [#39249](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/39249) [`7efeb93141c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7efeb93141c) - Add a rule to ensure critical packages are resolved to the correct versions
71
+ - [#39249](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/39249)
72
+ [`7efeb93141c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7efeb93141c) - Add a
73
+ rule to ensure critical packages are resolved to the correct versions
44
74
 
45
75
  ## 0.2.5
46
76
 
47
77
  ### Patch Changes
48
78
 
49
- - [#39049](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/39049) [`e5f52093b2a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e5f52093b2a) - Add a rule to ensure that publish config is correct for packages
79
+ - [#39049](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/39049)
80
+ [`e5f52093b2a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e5f52093b2a) - Add a
81
+ rule to ensure that publish config is correct for packages
50
82
 
51
83
  ## 0.2.4
52
84
 
53
85
  ### Patch Changes
54
86
 
55
- - [#38261](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/38261) [`eb64cbdd681`](https://bitbucket.org/atlassian/atlassian-frontend/commits/eb64cbdd681) - Add a new rule to verify that the atlassian team is defined if the relevant section exists in the package.json
87
+ - [#38261](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/38261)
88
+ [`eb64cbdd681`](https://bitbucket.org/atlassian/atlassian-frontend/commits/eb64cbdd681) - Add a
89
+ new rule to verify that the atlassian team is defined if the relevant section exists in the
90
+ package.json
56
91
 
57
92
  ## 0.2.3
58
93
 
59
94
  ### Patch Changes
60
95
 
61
- - [#33879](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/33879) [`0bf64fb3dd0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0bf64fb3dd0) - Update to support unary expressions like negation
96
+ - [#33879](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/33879)
97
+ [`0bf64fb3dd0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0bf64fb3dd0) - Update
98
+ to support unary expressions like negation
62
99
 
63
100
  ## 0.2.2
64
101
 
65
102
  ### Patch Changes
66
103
 
67
- - [#33793](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/33793) [`9d00501a414`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9d00501a414) - Ensure legacy types are published for TS 4.5-4.8
104
+ - [#33793](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/33793)
105
+ [`9d00501a414`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9d00501a414) - Ensure
106
+ legacy types are published for TS 4.5-4.8
68
107
 
69
108
  ## 0.2.1
70
109
 
71
110
  ### Patch Changes
72
111
 
73
- - [#33649](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/33649) [`41fae2c6f68`](https://bitbucket.org/atlassian/atlassian-frontend/commits/41fae2c6f68) - Upgrade Typescript from `4.5.5` to `4.9.5`
112
+ - [#33649](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/33649)
113
+ [`41fae2c6f68`](https://bitbucket.org/atlassian/atlassian-frontend/commits/41fae2c6f68) - Upgrade
114
+ Typescript from `4.5.5` to `4.9.5`
74
115
 
75
116
  ## 0.2.0
76
117
 
77
118
  ### Minor Changes
78
119
 
79
- - [#33258](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/33258) [`56507598609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56507598609) - Skip minor dependency bump
120
+ - [#33258](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/33258)
121
+ [`56507598609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56507598609) - Skip
122
+ minor dependency bump
80
123
 
81
124
  ## 0.1.8
82
125
 
83
126
  ### Patch Changes
84
127
 
85
- - [#32441](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/32441) [`cb0e94d2ce4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cb0e94d2ce4) - Fix prefixes for all flags being checked at any callsite, only the current flag will be checked from now on
128
+ - [#32441](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/32441)
129
+ [`cb0e94d2ce4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cb0e94d2ce4) - Fix
130
+ prefixes for all flags being checked at any callsite, only the current flag will be checked from
131
+ now on
86
132
 
87
133
  ## 0.1.7
88
134
 
89
135
  ### Patch Changes
90
136
 
91
- - [#32424](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/32424) [`2e01c9c74b5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2e01c9c74b5) - DUMMY remove before merging to master; dupe adf-schema via adf-utils
137
+ - [#32424](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/32424)
138
+ [`2e01c9c74b5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/2e01c9c74b5) - DUMMY
139
+ remove before merging to master; dupe adf-schema via adf-utils
92
140
 
93
141
  ## 0.1.6
94
142
 
95
143
  ### Patch Changes
96
144
 
97
- - [#31962](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31962) [`e8a8808f299`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e8a8808f299) - Add a new eslint rule that enforces prefixes on platform feature flags. Ignore existing usages.
145
+ - [#31962](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31962)
146
+ [`e8a8808f299`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e8a8808f299) - Add a
147
+ new eslint rule that enforces prefixes on platform feature flags. Ignore existing usages.
98
148
 
99
149
  ## 0.1.5
100
150
 
101
151
  ### Patch Changes
102
152
 
103
- - [#31956](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31956) [`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.
153
+ - [#31956](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31956)
154
+ [`b47e48ad163`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b47e48ad163) - Adds an
155
+ eslint rule to confirm that storybooks only get passed an object - to ensure that codemods work
156
+ correctly.
104
157
 
105
158
  ## 0.1.4
106
159
 
107
160
  ### Patch Changes
108
161
 
109
- - [#31631](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31631) [`971489f4ff4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/971489f4ff4) - Add test runner to identified calls that require registration of platform feature flags
162
+ - [#31631](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31631)
163
+ [`971489f4ff4`](https://bitbucket.org/atlassian/atlassian-frontend/commits/971489f4ff4) - Add test
164
+ runner to identified calls that require registration of platform feature flags
110
165
 
111
166
  ## 0.1.3
112
167
 
113
168
  ### Patch Changes
114
169
 
115
- - [#31581](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31581) [`7facf919a4e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7facf919a4e) - Remove product specific rules and make it so the recommended set is used everywhere instead
170
+ - [#31581](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31581)
171
+ [`7facf919a4e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7facf919a4e) - Remove
172
+ product specific rules and make it so the recommended set is used everywhere instead
116
173
 
117
174
  ## 0.1.2
118
175
 
119
176
  ### Patch Changes
120
177
 
121
- - [#31440](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31440) [`166815fbd8f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/166815fbd8f) - Add recommended set of flags for use in products
178
+ - [#31440](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/31440)
179
+ [`166815fbd8f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/166815fbd8f) - Add
180
+ recommended set of flags for use in products
122
181
 
123
182
  ## 0.1.1
124
183
 
125
184
  ### Patch Changes
126
185
 
127
- - [#30710](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30710) [`7edd9e8b4b1`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7edd9e8b4b1) - Add suggestion to change feature flag to the closest matching feature flag using fuzzy search
186
+ - [#30710](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30710)
187
+ [`7edd9e8b4b1`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7edd9e8b4b1) - Add
188
+ suggestion to change feature flag to the closest matching feature flag using fuzzy search
128
189
 
129
190
  ## 0.1.0
130
191
 
131
192
  ### Minor Changes
132
193
 
133
- - [#30401](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30401) [`6339334e3ac`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6339334e3ac) - Adds new rule to disallow pre/post install scripts in package.json.
194
+ - [#30401](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30401)
195
+ [`6339334e3ac`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6339334e3ac) - Adds new
196
+ rule to disallow pre/post install scripts in package.json.
134
197
 
135
198
  ## 0.0.7
136
199
 
137
200
  ### Patch Changes
138
201
 
139
- - [#30777](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30777) [`0cab60b90c3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0cab60b90c3) - Add fix to eslint rule on the arguments of nested test runner
202
+ - [#30777](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30777)
203
+ [`0cab60b90c3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/0cab60b90c3) - Add fix
204
+ to eslint rule on the arguments of nested test runner
140
205
 
141
206
  ## 0.0.6
142
207
 
143
208
  ### Patch Changes
144
209
 
145
- - [#30491](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30491) [`99449cce7f5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/99449cce7f5) - Eslint rules around test runner arguments and limit on nested test runners
210
+ - [#30491](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30491)
211
+ [`99449cce7f5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/99449cce7f5) - Eslint
212
+ rules around test runner arguments and limit on nested test runners
146
213
 
147
214
  ## 0.0.5
148
215
 
149
216
  ### Patch Changes
150
217
 
151
- - [#30484](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30484) [`aeb52cac34c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/aeb52cac34c) - Split feature flag registration rule into two to more easily use it in products
218
+ - [#30484](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30484)
219
+ [`aeb52cac34c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/aeb52cac34c) - Split
220
+ feature flag registration rule into two to more easily use it in products
152
221
 
153
222
  ## 0.0.4
154
223
 
155
224
  ### Patch Changes
156
225
 
157
- - [#30432](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30432) [`cd5b194f403`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cd5b194f403) - Add check to ensure that there is only one feature flag call per expression
226
+ - [#30432](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30432)
227
+ [`cd5b194f403`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cd5b194f403) - Add
228
+ check to ensure that there is only one feature flag call per expression
158
229
 
159
230
  ## 0.0.3
160
231
 
161
232
  ### Patch Changes
162
233
 
163
- - [#30320](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30320) [`11706c3e7c5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/11706c3e7c5) - Publish platform eslint rules to npm to be consumed in other products
234
+ - [#30320](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/30320)
235
+ [`11706c3e7c5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/11706c3e7c5) - Publish
236
+ platform eslint rules to npm to be consumed in other products
164
237
 
165
238
  ## 0.0.2
166
239
 
167
240
  ### Patch Changes
168
241
 
169
- - [#28303](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/28303) [`85dc0230439`](https://bitbucket.org/atlassian/atlassian-frontend/commits/85dc0230439) - Add eslint rule to allow for platform feature flag usage
242
+ - [#28303](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/28303)
243
+ [`85dc0230439`](https://bitbucket.org/atlassian/atlassian-frontend/commits/85dc0230439) - Add
244
+ eslint rule to allow for platform feature flag usage
@@ -0,0 +1,20 @@
1
+ {
2
+ "extends": "../../../../tsconfig.entry-points.jira.json",
3
+ "compilerOptions": {
4
+ "target": "es5",
5
+ "outDir": "../../../../../tsDist/@atlaskit__eslint-plugin-platform/app",
6
+ "composite": true,
7
+ "rootDir": "../"
8
+ },
9
+ "include": [
10
+ "../src/**/*.ts",
11
+ "../src/**/*.tsx"
12
+ ],
13
+ "exclude": [
14
+ "../src/**/__tests__/*",
15
+ "../__tests__/*",
16
+ "../src/**/*.test.*",
17
+ "../src/**/test.*"
18
+ ],
19
+ "references": []
20
+ }
package/dist/cjs/index.js CHANGED
@@ -15,9 +15,17 @@ var _noDuplicateDependencies = _interopRequireDefault(require("./rules/no-duplic
15
15
  var _noInvalidFeatureFlagUsage = _interopRequireDefault(require("./rules/no-invalid-feature-flag-usage"));
16
16
  var _ensureFeatureFlagPrefix = _interopRequireDefault(require("./rules/ensure-feature-flag-prefix"));
17
17
  var _ensureCriticalDependencyResolutions = _interopRequireDefault(require("./rules/ensure-critical-dependency-resolutions"));
18
+ var _ensureValidEmotionCssProp = _interopRequireDefault(require("./rules/ensure-valid-emotion-css-prop"));
18
19
  var _noInvalidStorybookDecoratorUsage = _interopRequireDefault(require("./rules/no-invalid-storybook-decorator-usage"));
19
20
  var _ensurePublishValid = _interopRequireDefault(require("./rules/ensure-publish-valid"));
20
21
  var _ensureNativeAndAfExportsSynced = _interopRequireDefault(require("./rules/ensure-native-and-af-exports-synced"));
22
+ var _noModuleLevelEval = _interopRequireDefault(require("./rules/no-module-level-eval"));
23
+ var _staticFeatureFlags = _interopRequireDefault(require("./rules/static-feature-flags"));
24
+ var _noPreconditioning = _interopRequireDefault(require("./rules/no-preconditioning"));
25
+ var _inlineUsage = _interopRequireDefault(require("./rules/inline-usage"));
26
+ var _preferFg = _interopRequireDefault(require("./rules/prefer-fg"));
27
+ var _noAlias = _interopRequireDefault(require("./rules/no-alias"));
28
+ var _useRecommendedUtils = _interopRequireDefault(require("./rules/use-recommended-utils"));
21
29
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
30
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // eslint-disable-next-line import/no-extraneous-dependencies
23
31
  var rules = exports.rules = {
@@ -27,12 +35,20 @@ var rules = exports.rules = {
27
35
  'ensure-test-runner-nested-count': _ensureTestRunnerNestedCount.default,
28
36
  'ensure-atlassian-team': _ensureAtlassianTeam.default,
29
37
  'ensure-critical-dependency-resolutions': _ensureCriticalDependencyResolutions.default,
38
+ 'ensure-valid-emotion-css-prop': _ensureValidEmotionCssProp.default,
30
39
  'no-duplicate-dependencies': _noDuplicateDependencies.default,
31
40
  'no-invalid-feature-flag-usage': _noInvalidFeatureFlagUsage.default,
32
41
  'no-pre-post-install-scripts': _noPrePostInstalls.default,
33
42
  'no-invalid-storybook-decorator-usage': _noInvalidStorybookDecoratorUsage.default,
34
43
  'ensure-publish-valid': _ensurePublishValid.default,
35
- 'ensure-native-and-af-exports-synced': _ensureNativeAndAfExportsSynced.default
44
+ 'ensure-native-and-af-exports-synced': _ensureNativeAndAfExportsSynced.default,
45
+ 'no-module-level-eval': _noModuleLevelEval.default,
46
+ 'static-feature-flags': _staticFeatureFlags.default,
47
+ 'no-preconditioning': _noPreconditioning.default,
48
+ 'inline-usage': _inlineUsage.default,
49
+ 'prefer-fg': _preferFg.default,
50
+ 'no-alias': _noAlias.default,
51
+ 'use-recommended-utils': _useRecommendedUtils.default
36
52
  };
37
53
  var configs = exports.configs = {
38
54
  recommended: {
@@ -46,11 +62,18 @@ var configs = exports.configs = {
46
62
  '@atlaskit/platform/ensure-test-runner-nested-count': 'warn',
47
63
  '@atlaskit/platform/no-invalid-feature-flag-usage': 'error',
48
64
  '@atlaskit/platform/no-invalid-storybook-decorator-usage': 'error',
49
- '@atlaskit/platform/ensure-atlassian-team': 'error'
65
+ '@atlaskit/platform/ensure-atlassian-team': 'error',
66
+ '@atlaskit/platform/no-module-level-eval': 'error',
67
+ '@atlaskit/platform/static-feature-flags': 'error',
68
+ '@atlaskit/platform/no-preconditioning': 'error',
69
+ '@atlaskit/platform/inline-usage': 'error',
70
+ '@atlaskit/platform/prefer-fg': 'error',
71
+ '@atlaskit/platform/no-alias': 'error'
50
72
  }
51
73
  }
52
74
  };
53
75
  var jsonPrefix = '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, @typescript-eslint/semi, no-template-curly-in-string */ module.exports = ';
76
+ var jsonPrefixForFlatConfig = '/* eslint-disable quote-props, comma-dangle, quotes, semi, eol-last, no-template-curly-in-string */ module.exports = ';
54
77
  var processors = exports.processors = {
55
78
  'package-json-processor': {
56
79
  preprocess: function preprocess(source) {
@@ -72,5 +95,28 @@ var processors = exports.processors = {
72
95
  });
73
96
  },
74
97
  supportsAutofix: true
98
+ },
99
+ // This processor is used for ESLint FlatConfig,
100
+ // once we roll out FlatConfig, we can remove the above processor
101
+ 'package-json-processor-for-flat-config': {
102
+ preprocess: function preprocess(source) {
103
+ // augment the json into a js file
104
+ return [jsonPrefixForFlatConfig + source.trim()];
105
+ },
106
+ postprocess: function postprocess(messages) {
107
+ return messages[0].map(function (message) {
108
+ var fix = message.fix;
109
+ if (!fix) {
110
+ return message;
111
+ }
112
+ var offset = jsonPrefixForFlatConfig.length;
113
+ return _objectSpread(_objectSpread({}, message), {}, {
114
+ fix: _objectSpread(_objectSpread({}, fix), {}, {
115
+ range: [fix.range[0] - offset, fix.range[1] - offset]
116
+ })
117
+ });
118
+ });
119
+ },
120
+ supportsAutofix: true
75
121
  }
76
122
  };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FEATURE_UTILS_IMPORT_SOURCES = exports.FEATURE_MOCKS_IMPORT_SOURCES = exports.FEATURE_API_IMPORT_SOURCES = void 0;
7
+ // List of libraries that we maintain or have worked on
8
+ // - eg `@atlaskit/feature-gate-js-client` shouldn't be included in here
9
+ var FEATURE_API_IMPORT_SOURCES = exports.FEATURE_API_IMPORT_SOURCES = new Set(['@atlassian/jira-feature-flagging', '@atlassian/jira-feature-flagging-using-meta', '@atlassian/jira-feature-gating', '@atlassian/jira-feature-experiments', '@atlaskit/platform-feature-flags']);
10
+ var FEATURE_MOCKS_IMPORT_SOURCES = exports.FEATURE_MOCKS_IMPORT_SOURCES = new Set(['@atlassian/jira-feature-flagging-mocks', '@atlassian/jira-feature-gates-test-mocks', '@atlassian/jira-feature-gates-storybook-mocks']);
11
+ var FEATURE_UTILS_IMPORT_SOURCES = exports.FEATURE_UTILS_IMPORT_SOURCES = new Set(['@atlassian/jira-feature-flagging-utils', '@atlassian/jira-feature-gate-component']);
@@ -15,30 +15,69 @@ var _handleAstObject = require("../util/handle-ast-object");
15
15
  //
16
16
  var DESIRED_PKG_VERSIONS = {
17
17
  typescript: ['5.4'],
18
- '@types/react': ['16.14', '18.2']
18
+ tslib: ['2.6'],
19
+ '@types/react': ['16.14', '18.2'],
20
+ 'react-relay': ['npm:atl-react-relay@0.0.0-main-2ccd6998'],
21
+ 'relay-compiler': ['npm:atl-relay-compiler@0.0.0-main-2ccd6998'],
22
+ 'relay-runtime': ['npm:atl-relay-runtime@0.0.0-main-2ccd6998'],
23
+ 'relay-test-utils': ['npm:atl-relay-test-utils@0.0.0-main-2ccd6998']
19
24
  };
20
25
  var matchMinorVersion = function matchMinorVersion(desiredVersion, versionInResolutions) {
21
26
  var firstChar = versionInResolutions[0];
22
27
  // The version is invalid if it doesn't start with a number or ~
23
- if (!/^\d$/.test(firstChar) && firstChar !== '~') {
28
+ if (!/^\d$/.test(firstChar) && firstChar !== '~' && !versionInResolutions.startsWith('npm:')) {
24
29
  return false;
25
30
  }
26
31
  return versionInResolutions.startsWith(desiredVersion) || versionInResolutions.startsWith('~' + desiredVersion);
27
32
  };
28
- var verifyResolutionFromObject = function verifyResolutionFromObject(node, pkg, version, optional) {
33
+ var verifyResolutionFromObject = function verifyResolutionFromObject(_ref) {
34
+ var resolutions = _ref.resolutions,
35
+ dependencies = _ref.dependencies,
36
+ devDependencies = _ref.devDependencies,
37
+ pkg = _ref.pkg,
38
+ version = _ref.version,
39
+ optional = _ref.optional;
29
40
  // For root package.json, we require the critical packages' resolutions exist and with matching version
30
41
  // For individual package's package.json, it's ok if resolutions don't exist. But if they do, the version should match
31
- var resolutionExist = node.properties.some(function (p) {
42
+ var resolutionExist = resolutions.properties.some(function (p) {
32
43
  return p.type === 'Property' && p.key.type === 'Literal' && p.key.value === pkg;
33
44
  });
45
+ isDependencyPresent({
46
+ resolutions: resolutions,
47
+ dependencies: dependencies,
48
+ devDependencies: devDependencies,
49
+ pkg: pkg
50
+ });
34
51
  if (!resolutionExist) {
52
+ // when package is not a part of dependencies/devDependencies
53
+ if (optional === false && !isDependencyPresent({
54
+ resolutions: resolutions,
55
+ dependencies: dependencies,
56
+ devDependencies: devDependencies,
57
+ pkg: pkg
58
+ })) {
59
+ return true;
60
+ }
35
61
  return optional;
36
62
  }
37
- var resolutionExistAndMatch = node.properties.some(function (p) {
63
+ var resolutionExistAndMatch = resolutions.properties.some(function (p) {
38
64
  return p.type === 'Property' && p.key.type === 'Literal' && p.key.value === pkg && p.value.type === 'Literal' && matchMinorVersion(version, p.value.value);
39
65
  });
40
66
  return resolutionExistAndMatch;
41
67
  };
68
+ var isDependencyPresent = function isDependencyPresent(_ref2) {
69
+ var resolutions = _ref2.resolutions,
70
+ dependencies = _ref2.dependencies,
71
+ devDependencies = _ref2.devDependencies,
72
+ pkg = _ref2.pkg;
73
+ var dependencyExist = dependencies !== null && dependencies.properties.some(function (p) {
74
+ return p.type === 'Property' && p.key.type === 'Literal' && p.key.value === pkg;
75
+ });
76
+ var devDependencyExist = devDependencies !== null && devDependencies.properties.some(function (p) {
77
+ return p.type === 'Property' && p.key.type === 'Literal' && p.key.value === pkg;
78
+ });
79
+ return dependencyExist || devDependencyExist;
80
+ };
42
81
  var rule = {
43
82
  meta: {
44
83
  type: 'problem',
@@ -67,6 +106,8 @@ var rule = {
67
106
  return;
68
107
  }
69
108
  var packageResolutions = (0, _handleAstObject.getObjectPropertyAsObject)(node, 'resolutions');
109
+ var packageDependencies = (0, _handleAstObject.getObjectPropertyAsObject)(node, 'dependencies');
110
+ var packageDevDependencies = (0, _handleAstObject.getObjectPropertyAsObject)(node, 'devDependencies');
70
111
  var rootDir = (0, _findRoot.findRootSync)(process.cwd());
71
112
  var isRootPackageJson = fileName.endsWith("".concat(rootDir, "/package.json"));
72
113
  if (packageResolutions !== null) {
@@ -75,7 +116,14 @@ var rule = {
75
116
  key = _Object$entries$_i[0],
76
117
  values = _Object$entries$_i[1];
77
118
  if (!values.some(function (value) {
78
- return verifyResolutionFromObject(packageResolutions, key, value, !isRootPackageJson);
119
+ return verifyResolutionFromObject({
120
+ resolutions: packageResolutions,
121
+ dependencies: packageDependencies,
122
+ devDependencies: packageDevDependencies,
123
+ pkg: key,
124
+ version: value,
125
+ optional: !isRootPackageJson
126
+ });
79
127
  })) {
80
128
  return {
81
129
  v: context.report({
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
8
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
11
  var _path = _interopRequireDefault(require("path"));
@@ -77,7 +78,7 @@ var rule = {
77
78
  });
78
79
  continue;
79
80
  }
80
- var exportValueViolations = getExportValueViolation(pkgName, afExportsKey, afExportsValue, nativeExports);
81
+ var exportValueViolations = getExportValueViolation(afExportsKey, afExportsValue, nativeExports);
81
82
  if (exportValueViolations) {
82
83
  context.report({
83
84
  data: _objectSpread(_objectSpread({}, exportValueViolations), {}, {
@@ -94,7 +95,7 @@ var rule = {
94
95
  }
95
96
  };
96
97
  function getExportKeyViolation(afExportsKey, afExportsValue, nativeExports) {
97
- var afExportsValueHasExtension = _path.default.extname(afExportsValue);
98
+ var afExportsValueHasExtension = _path.default.extname(afExportsValue) !== '';
98
99
  if (afExportsValueHasExtension && !nativeExports.hasOwnProperty(afExportsKey)) {
99
100
  return {
100
101
  messageId: 'missingExportsKey',
@@ -117,15 +118,23 @@ function getExportKeyViolation(afExportsKey, afExportsValue, nativeExports) {
117
118
  };
118
119
  }
119
120
  }
120
- function getExportValueViolation(pkgName, afExportsKey, afExportsValue, nativeExports) {
121
- var afExportsValueHasExtension = _path.default.extname(afExportsValue);
121
+ function getNativeExportsValue(afExportsKey, afExportsValueHasExtension, nativeExports) {
122
+ var nativeExportsKey = afExportsValueHasExtension ? afExportsKey : "".concat(afExportsKey, "/*");
123
+ if ((0, _typeof2.default)(nativeExports[nativeExportsKey]) === 'object') {
124
+ return nativeExports[nativeExportsKey].default;
125
+ }
126
+ return nativeExports[nativeExportsKey];
127
+ }
128
+ function getExportValueViolation(afExportsKey, afExportsValue, nativeExports) {
129
+ var afExportsValueHasExtension = _path.default.extname(afExportsValue) !== '';
130
+ var nativeExportsValue = getNativeExportsValue(afExportsKey, afExportsValueHasExtension, nativeExports);
122
131
 
123
132
  // Some entrypoints have been updated to an index.js file that registers ts-node
124
133
  // Use path.basename to get the file name to see if it is equal to 'index.js'
125
- if (afExportsValueHasExtension && _path.default.basename(nativeExports[afExportsKey]) === 'index.js') {
134
+ if (afExportsValueHasExtension && _path.default.basename(nativeExportsValue) === 'index.js') {
126
135
  return;
127
136
  }
128
- if (afExportsValueHasExtension && nativeExports[afExportsKey] !== afExportsValue) {
137
+ if (afExportsValueHasExtension && nativeExportsValue !== afExportsValue) {
129
138
  return {
130
139
  key: afExportsKey,
131
140
  expectedValue: afExportsValue
@@ -133,7 +142,7 @@ function getExportValueViolation(pkgName, afExportsKey, afExportsValue, nativeEx
133
142
  }
134
143
 
135
144
  // af:exports entrypoints without a file extension export the whole directory so check to ensure the exports value includes the wildcard
136
- if (!afExportsValueHasExtension && !nativeExports["".concat(afExportsKey, "/*")].startsWith("".concat(afExportsValue, "/*"))) {
145
+ if (!afExportsValueHasExtension && !nativeExportsValue.startsWith("".concat(afExportsValue, "/*"))) {
137
146
  return {
138
147
  key: "".concat(afExportsKey, "/*"),
139
148
  expectedValue: "".concat(afExportsValue, "/*")
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ // eslint-disable-next-line import/no-extraneous-dependencies
8
+
9
+ var rule = {
10
+ meta: {
11
+ type: 'problem',
12
+ docs: {
13
+ description: 'Ensure valid use of the `css` prop from `@emotion/react`',
14
+ recommended: true
15
+ },
16
+ messages: {
17
+ noEmotionCssImport: 'Must import `css` from `@emotion/react` when using the `css` prop.',
18
+ noEmotionCssPropFunctionCall: 'No function calls allowed when passing an object directly to the `css` prop with `@emotion/react`.'
19
+ }
20
+ },
21
+ create: function create(context) {
22
+ var emotionJsxImported = false;
23
+ var emotionJsxImportPosition;
24
+ var emotionCssImported = false;
25
+ var cssPropExpressonUsed = false;
26
+
27
+ // Ignore files in these directories
28
+ if (/example|__tests__|__fixtures__/.test(context.filename)) {
29
+ return {};
30
+ }
31
+ return {
32
+ ImportDeclaration: function ImportDeclaration(node) {
33
+ if (node.source.value === '@emotion/react') {
34
+ node.specifiers.forEach(function (specifier) {
35
+ if (specifier.type === 'ImportSpecifier') {
36
+ if (specifier.imported.name === 'jsx') {
37
+ var _specifier$loc;
38
+ emotionJsxImported = true;
39
+ emotionJsxImportPosition = (_specifier$loc = specifier.loc) === null || _specifier$loc === void 0 ? void 0 : _specifier$loc.start;
40
+ }
41
+ if (specifier.imported.name === 'css') {
42
+ emotionCssImported = true;
43
+ }
44
+ }
45
+ });
46
+ }
47
+ },
48
+ JSXAttribute: function JSXAttribute(node) {
49
+ var name = node.name,
50
+ value = node.value;
51
+
52
+ // Only run on emotion css props
53
+ if (!emotionJsxImported) return;
54
+ if (name.name !== 'css') return;
55
+ if (value.type === 'JSXExpressionContainer' && value.expression.type === 'ObjectExpression') {
56
+ cssPropExpressonUsed = true;
57
+ var containsFunctionExpression = false;
58
+
59
+ // Iterate over the properties of the object
60
+ value.expression.properties.forEach(function (prop) {
61
+ var _prop$value, _prop$value2, _prop$value3;
62
+ // Check for function expressions directly within the object literal
63
+ if (((_prop$value = prop.value) === null || _prop$value === void 0 ? void 0 : _prop$value.type) === 'ArrowFunctionExpression' || ((_prop$value2 = prop.value) === null || _prop$value2 === void 0 ? void 0 : _prop$value2.type) === 'FunctionExpression' || ((_prop$value3 = prop.value) === null || _prop$value3 === void 0 ? void 0 : _prop$value3.type) === 'CallExpression') {
64
+ containsFunctionExpression = true;
65
+ }
66
+ });
67
+
68
+ // If a function expression is found within the direct object literal, report an error
69
+ if (containsFunctionExpression) {
70
+ context.report({
71
+ node: node,
72
+ messageId: 'noEmotionCssPropFunctionCall'
73
+ });
74
+ }
75
+ }
76
+ },
77
+ 'Program:exit': function ProgramExit() {
78
+ if (emotionJsxImported && cssPropExpressonUsed && !emotionCssImported) {
79
+ context.report({
80
+ messageId: 'noEmotionCssImport',
81
+ loc: emotionJsxImportPosition || {
82
+ line: 1,
83
+ column: 0
84
+ }
85
+ });
86
+ }
87
+ }
88
+ };
89
+ }
90
+ };
91
+ var _default = exports.default = rule;