@atlaskit/eslint-plugin-ui-styling-standard 1.5.0 → 1.6.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 (33) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/cjs/rules/enforce-style-prop/index.js +87 -2
  3. package/dist/cjs/rules/no-unsafe-selectors/constants.js +49 -2
  4. package/dist/cjs/rules/no-unsafe-selectors/walk-css-map.js +10 -5
  5. package/dist/es2019/rules/enforce-style-prop/index.js +89 -2
  6. package/dist/es2019/rules/no-unsafe-selectors/constants.js +48 -1
  7. package/dist/es2019/rules/no-unsafe-selectors/walk-css-map.js +10 -5
  8. package/dist/esm/rules/enforce-style-prop/index.js +87 -2
  9. package/dist/esm/rules/no-unsafe-selectors/constants.js +48 -1
  10. package/dist/esm/rules/no-unsafe-selectors/walk-css-map.js +10 -5
  11. package/dist/types/rules/no-array-arguments/index.d.ts +1 -1
  12. package/dist/types/rules/no-classname-prop/index.d.ts +1 -1
  13. package/dist/types/rules/no-container-queries/index.d.ts +1 -1
  14. package/dist/types/rules/no-dynamic-styles/index.d.ts +1 -1
  15. package/dist/types/rules/no-exported-styles/index.d.ts +1 -1
  16. package/dist/types/rules/no-global-styles/index.d.ts +1 -1
  17. package/dist/types/rules/no-important-styles/index.d.ts +1 -1
  18. package/dist/types/rules/no-nested-selectors/index.d.ts +1 -1
  19. package/dist/types/rules/no-styled/index.d.ts +1 -1
  20. package/dist/types/rules/no-unsafe-selectors/constants.d.ts +45 -0
  21. package/dist/types/rules/no-unsafe-values/index.d.ts +1 -1
  22. package/dist/types-ts4.5/rules/no-array-arguments/index.d.ts +1 -1
  23. package/dist/types-ts4.5/rules/no-classname-prop/index.d.ts +1 -1
  24. package/dist/types-ts4.5/rules/no-container-queries/index.d.ts +1 -1
  25. package/dist/types-ts4.5/rules/no-dynamic-styles/index.d.ts +1 -1
  26. package/dist/types-ts4.5/rules/no-exported-styles/index.d.ts +1 -1
  27. package/dist/types-ts4.5/rules/no-global-styles/index.d.ts +1 -1
  28. package/dist/types-ts4.5/rules/no-important-styles/index.d.ts +1 -1
  29. package/dist/types-ts4.5/rules/no-nested-selectors/index.d.ts +1 -1
  30. package/dist/types-ts4.5/rules/no-styled/index.d.ts +1 -1
  31. package/dist/types-ts4.5/rules/no-unsafe-selectors/constants.d.ts +45 -0
  32. package/dist/types-ts4.5/rules/no-unsafe-values/index.d.ts +1 -1
  33. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`5db9e3f21a52f`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5db9e3f21a52f) -
8
+ Changes the `@atlaskit/ui-styling-standard/enforce-style-prop` ESLint rule to allow pass-through
9
+ styles.
10
+
11
+ ## 1.5.1
12
+
13
+ ### Patch Changes
14
+
15
+ - [`ceba2f0da51d4`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ceba2f0da51d4) -
16
+ Add @starting-style to ESLint ignoredAtRules to allow usage without eslint-disable comments
17
+
3
18
  ## 1.5.0
4
19
 
5
20
  ### Minor Changes
@@ -141,6 +141,40 @@ function isPropertyValueAllowed(property, context) {
141
141
  }
142
142
  return true;
143
143
  }
144
+
145
+ /**
146
+ * Returns true if the property is not nested within another property.
147
+ */
148
+ function isShallowProperty(property) {
149
+ var objectPattern = property.parent;
150
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(objectPattern, 'ObjectPattern')) {
151
+ return false;
152
+ }
153
+ return (0, _eslintCodemodUtils.isNodeOfType)(objectPattern.parent, 'VariableDeclarator') || (0, _eslintCodemodUtils.isNodeOfType)(objectPattern.parent, 'FunctionDeclaration') || (0, _eslintCodemodUtils.isNodeOfType)(objectPattern.parent, 'FunctionExpression') || (0, _eslintCodemodUtils.isNodeOfType)(objectPattern.parent, 'ArrowFunctionExpression');
154
+ }
155
+ function isAllowedName(name) {
156
+ return name.name === 'style';
157
+ }
158
+ function isAllowedDefinition(definition) {
159
+ var name = definition.name;
160
+ var parent = name.parent;
161
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(parent, 'Property')) {
162
+ return false;
163
+ }
164
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(parent.key, 'Identifier') || !(0, _eslintCodemodUtils.isNodeOfType)(parent.value, 'Identifier') || !isAllowedName(parent.key) || !isAllowedName(parent.value)) {
165
+ return false;
166
+ }
167
+ if (!isShallowProperty(parent)) {
168
+ return false;
169
+ }
170
+ return true;
171
+ }
172
+ function isFirstParameter(identifier) {
173
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(identifier.parent, 'FunctionDeclaration') && !(0, _eslintCodemodUtils.isNodeOfType)(identifier.parent, 'ArrowFunctionExpression') && !(0, _eslintCodemodUtils.isNodeOfType)(identifier.parent, 'FunctionExpression')) {
174
+ return false;
175
+ }
176
+ return identifier.parent.params[0] === identifier;
177
+ }
144
178
  var rule = exports.rule = (0, _createRule.createLintRule)({
145
179
  meta: {
146
180
  name: 'enforce-style-prop',
@@ -178,7 +212,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
178
212
  // Typical `style={{ … }}` scenario
179
213
  expression = node.expression;
180
214
  } else if (node.expression.type === 'Identifier') {
181
- var _variable$defs;
215
+ var _variable$defs, _definition$node$init, _variable$defs2;
182
216
  /*
183
217
  * Example:
184
218
  * ```tsx
@@ -190,15 +224,66 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
190
224
  sourceCode: (0, _contextCompat.getSourceCode)(context),
191
225
  identifier: node.expression
192
226
  });
227
+ var definition = variable === null || variable === void 0 || (_variable$defs = variable.defs) === null || _variable$defs === void 0 ? void 0 : _variable$defs[0];
228
+
229
+ /**
230
+ * Allow passing a function parameter directly to the style prop
231
+ *
232
+ * @example
233
+ * function Component({ style }) { return <div style={style} />; }
234
+ *
235
+ * @example
236
+ * <Popper>
237
+ * {({ ref, style }) => <div ref={ref} style={style} />}
238
+ * </Popper>
239
+ */
240
+ if ((definition === null || definition === void 0 ? void 0 : definition.type) === 'Parameter' && isAllowedDefinition(definition)) {
241
+ return;
242
+ }
243
+
244
+ /**
245
+ * Allow passing a value destructured in the body from a function parameter to the style prop
246
+ *
247
+ * @example
248
+ * function Component(props) {
249
+ * const { style } = props;
250
+ * return <div style={style} />;
251
+ * }
252
+ */
253
+ if ((definition === null || definition === void 0 ? void 0 : definition.type) === 'Variable' && ((_definition$node$init = definition.node.init) === null || _definition$node$init === void 0 ? void 0 : _definition$node$init.type) === 'Identifier') {
254
+ var sourceVariable = (0, _findVariable2.findVariable)({
255
+ identifier: definition.node.init,
256
+ sourceCode: (0, _contextCompat.getSourceCode)(context)
257
+ });
258
+ var sourceDefinition = sourceVariable === null || sourceVariable === void 0 ? void 0 : sourceVariable.defs[0];
259
+ if ((sourceDefinition === null || sourceDefinition === void 0 ? void 0 : sourceDefinition.type) === 'Parameter' && isAllowedDefinition(definition)) {
260
+ return;
261
+ }
262
+ }
193
263
 
194
264
  // Types are alluding us here, but we really only want an ObjectExpression here
195
265
  // Additionally, if we have multiple variable definitions, we're in some unhandled scenario
196
266
  // so we're only going to look at the first one…
197
- var hopefulObjectExpression = variable === null || variable === void 0 || (_variable$defs = variable.defs) === null || _variable$defs === void 0 || (_variable$defs = _variable$defs[0]) === null || _variable$defs === void 0 || (_variable$defs = _variable$defs.node) === null || _variable$defs === void 0 ? void 0 : _variable$defs.init;
267
+ var hopefulObjectExpression = variable === null || variable === void 0 || (_variable$defs2 = variable.defs) === null || _variable$defs2 === void 0 || (_variable$defs2 = _variable$defs2[0]) === null || _variable$defs2 === void 0 || (_variable$defs2 = _variable$defs2.node) === null || _variable$defs2 === void 0 ? void 0 : _variable$defs2.init;
198
268
  if ((hopefulObjectExpression === null || hopefulObjectExpression === void 0 ? void 0 : hopefulObjectExpression.type) === 'ObjectExpression') {
199
269
  expression = hopefulObjectExpression;
200
270
  }
201
271
  reportOnNodeExpression = true;
272
+ } else if (node.expression.type === 'MemberExpression') {
273
+ /**
274
+ * Allow passing `props.style` to the style prop
275
+ */
276
+ if (node.expression.object.type === 'Identifier' && node.expression.property.type === 'Identifier' && isAllowedName(node.expression.property)) {
277
+ var _variable2$defs;
278
+ var _variable2 = (0, _findVariable2.findVariable)({
279
+ sourceCode: (0, _contextCompat.getSourceCode)(context),
280
+ identifier: node.expression.object
281
+ });
282
+ var _definition = _variable2 === null || _variable2 === void 0 || (_variable2$defs = _variable2.defs) === null || _variable2$defs === void 0 ? void 0 : _variable2$defs[0];
283
+ if ((_definition === null || _definition === void 0 ? void 0 : _definition.type) === 'Parameter' && isFirstParameter(_definition.name)) {
284
+ return;
285
+ }
286
+ }
202
287
  }
203
288
  if (!((_expression = expression) !== null && _expression !== void 0 && _expression.properties)) {
204
289
  context.report({
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.legacyPseudoElements = exports.ignoredAtRules = exports.allowedPseudos = void 0;
6
+ exports.legacyPseudoElements = exports.ignoredAtRules = exports.allowedPseudos = exports.allowedGroupedAtRules = void 0;
7
7
  /**
8
8
  * Validation approach from
9
9
  * https://stackoverflow.com/a/71236280
@@ -27,4 +27,51 @@ var ignoredAtRules = exports.ignoredAtRules = new Set(['@container',
27
27
  // ignored because it's covered by `no-container-queries`
28
28
  '@media',
29
29
  // ignored because it's covered by `no-nested-styles`
30
- '@supports', '@property']);
30
+ '@supports', '@property', '@starting-style']);
31
+
32
+ /**
33
+ * At-rules that are allowed to be used in "grouped" form within cssMap.
34
+ *
35
+ * "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
36
+ * (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
37
+ *
38
+ * ```typescript
39
+ * // ❌ GROUPED (not allowed for @media):
40
+ * cssMap({
41
+ * variant: {
42
+ * '@media': { // at-rule key with no parameters
43
+ * '(min-width: 900px)': {}, // nested variants
44
+ * '(min-width: 1200px)': {},
45
+ * }
46
+ * }
47
+ * })
48
+ *
49
+ * // ✅ FLAT (preferred for @media):
50
+ * cssMap({
51
+ * variant: {
52
+ * '@media (min-width: 900px)': {}, // at-rule with parameters
53
+ * '@media (min-width: 1200px)': {},
54
+ * }
55
+ * })
56
+ * ```
57
+ *
58
+ * However, some at-rules like `@starting-style` have no parameters and can only be
59
+ * written in the "grouped" form at the variant level:
60
+ *
61
+ * ```typescript
62
+ * // ✅ ALLOWED (only valid syntax for @starting-style):
63
+ * cssMap({
64
+ * fade: {
65
+ * '@starting-style': { // at-rule with no parameters
66
+ * opacity: 0, // styles to apply
67
+ * }
68
+ * }
69
+ * })
70
+ * ```
71
+ *
72
+ * Note: This only applies to at-rules at the variant level. Nested at-rules inside
73
+ * other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
74
+ * `walkStyleRuleset` and are not considered "grouped".
75
+ */
76
+ var allowedGroupedAtRules = exports.allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
77
+ ]);
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.walkCssMap = walkCssMap;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
10
+ var _constants = require("./constants");
10
11
  /**
11
12
  * This util is intentionally not in `@atlaskit/eslint-utils` at this time.
12
13
  *
@@ -110,11 +111,15 @@ function walkCssMapAtRuleGrouping(_ref4) {
110
111
  if (!atRule) {
111
112
  return;
112
113
  }
113
- visitor({
114
- type: 'grouped-at-rules',
115
- node: atRuleGrouping,
116
- atRule: atRule
117
- });
114
+
115
+ // Skip reporting if the at-rule is allowed to be grouped
116
+ if (!_constants.allowedGroupedAtRules.has(atRule)) {
117
+ visitor({
118
+ type: 'grouped-at-rules',
119
+ node: atRuleGrouping,
120
+ atRule: atRule
121
+ });
122
+ }
118
123
  if (atRuleGrouping.value.type !== 'ObjectExpression') {
119
124
  return;
120
125
  }
@@ -135,6 +135,42 @@ function isPropertyValueAllowed(property, context) {
135
135
  }
136
136
  return true;
137
137
  }
138
+
139
+ /**
140
+ * Returns true if the property is not nested within another property.
141
+ */
142
+ function isShallowProperty(property) {
143
+ const objectPattern = property.parent;
144
+ if (!isNodeOfType(objectPattern, 'ObjectPattern')) {
145
+ return false;
146
+ }
147
+ return isNodeOfType(objectPattern.parent, 'VariableDeclarator') || isNodeOfType(objectPattern.parent, 'FunctionDeclaration') || isNodeOfType(objectPattern.parent, 'FunctionExpression') || isNodeOfType(objectPattern.parent, 'ArrowFunctionExpression');
148
+ }
149
+ function isAllowedName(name) {
150
+ return name.name === 'style';
151
+ }
152
+ function isAllowedDefinition(definition) {
153
+ const name = definition.name;
154
+ const {
155
+ parent
156
+ } = name;
157
+ if (!isNodeOfType(parent, 'Property')) {
158
+ return false;
159
+ }
160
+ if (!isNodeOfType(parent.key, 'Identifier') || !isNodeOfType(parent.value, 'Identifier') || !isAllowedName(parent.key) || !isAllowedName(parent.value)) {
161
+ return false;
162
+ }
163
+ if (!isShallowProperty(parent)) {
164
+ return false;
165
+ }
166
+ return true;
167
+ }
168
+ function isFirstParameter(identifier) {
169
+ if (!isNodeOfType(identifier.parent, 'FunctionDeclaration') && !isNodeOfType(identifier.parent, 'ArrowFunctionExpression') && !isNodeOfType(identifier.parent, 'FunctionExpression')) {
170
+ return false;
171
+ }
172
+ return identifier.parent.params[0] === identifier;
173
+ }
138
174
  export const rule = createLintRule({
139
175
  meta: {
140
176
  name: 'enforce-style-prop',
@@ -172,7 +208,7 @@ export const rule = createLintRule({
172
208
  // Typical `style={{ … }}` scenario
173
209
  expression = node.expression;
174
210
  } else if (node.expression.type === 'Identifier') {
175
- var _variable$defs, _variable$defs$, _variable$defs$$node;
211
+ var _variable$defs, _definition$node$init, _variable$defs2, _variable$defs2$, _variable$defs2$$node;
176
212
  /*
177
213
  * Example:
178
214
  * ```tsx
@@ -184,15 +220,66 @@ export const rule = createLintRule({
184
220
  sourceCode: getSourceCode(context),
185
221
  identifier: node.expression
186
222
  });
223
+ const definition = variable === null || variable === void 0 ? void 0 : (_variable$defs = variable.defs) === null || _variable$defs === void 0 ? void 0 : _variable$defs[0];
224
+
225
+ /**
226
+ * Allow passing a function parameter directly to the style prop
227
+ *
228
+ * @example
229
+ * function Component({ style }) { return <div style={style} />; }
230
+ *
231
+ * @example
232
+ * <Popper>
233
+ * {({ ref, style }) => <div ref={ref} style={style} />}
234
+ * </Popper>
235
+ */
236
+ if ((definition === null || definition === void 0 ? void 0 : definition.type) === 'Parameter' && isAllowedDefinition(definition)) {
237
+ return;
238
+ }
239
+
240
+ /**
241
+ * Allow passing a value destructured in the body from a function parameter to the style prop
242
+ *
243
+ * @example
244
+ * function Component(props) {
245
+ * const { style } = props;
246
+ * return <div style={style} />;
247
+ * }
248
+ */
249
+ if ((definition === null || definition === void 0 ? void 0 : definition.type) === 'Variable' && ((_definition$node$init = definition.node.init) === null || _definition$node$init === void 0 ? void 0 : _definition$node$init.type) === 'Identifier') {
250
+ const sourceVariable = findVariable({
251
+ identifier: definition.node.init,
252
+ sourceCode: getSourceCode(context)
253
+ });
254
+ const sourceDefinition = sourceVariable === null || sourceVariable === void 0 ? void 0 : sourceVariable.defs[0];
255
+ if ((sourceDefinition === null || sourceDefinition === void 0 ? void 0 : sourceDefinition.type) === 'Parameter' && isAllowedDefinition(definition)) {
256
+ return;
257
+ }
258
+ }
187
259
 
188
260
  // Types are alluding us here, but we really only want an ObjectExpression here
189
261
  // Additionally, if we have multiple variable definitions, we're in some unhandled scenario
190
262
  // so we're only going to look at the first one…
191
- const hopefulObjectExpression = variable === null || variable === void 0 ? void 0 : (_variable$defs = variable.defs) === null || _variable$defs === void 0 ? void 0 : (_variable$defs$ = _variable$defs[0]) === null || _variable$defs$ === void 0 ? void 0 : (_variable$defs$$node = _variable$defs$.node) === null || _variable$defs$$node === void 0 ? void 0 : _variable$defs$$node.init;
263
+ const hopefulObjectExpression = variable === null || variable === void 0 ? void 0 : (_variable$defs2 = variable.defs) === null || _variable$defs2 === void 0 ? void 0 : (_variable$defs2$ = _variable$defs2[0]) === null || _variable$defs2$ === void 0 ? void 0 : (_variable$defs2$$node = _variable$defs2$.node) === null || _variable$defs2$$node === void 0 ? void 0 : _variable$defs2$$node.init;
192
264
  if ((hopefulObjectExpression === null || hopefulObjectExpression === void 0 ? void 0 : hopefulObjectExpression.type) === 'ObjectExpression') {
193
265
  expression = hopefulObjectExpression;
194
266
  }
195
267
  reportOnNodeExpression = true;
268
+ } else if (node.expression.type === 'MemberExpression') {
269
+ /**
270
+ * Allow passing `props.style` to the style prop
271
+ */
272
+ if (node.expression.object.type === 'Identifier' && node.expression.property.type === 'Identifier' && isAllowedName(node.expression.property)) {
273
+ var _variable$defs3;
274
+ const variable = findVariable({
275
+ sourceCode: getSourceCode(context),
276
+ identifier: node.expression.object
277
+ });
278
+ const definition = variable === null || variable === void 0 ? void 0 : (_variable$defs3 = variable.defs) === null || _variable$defs3 === void 0 ? void 0 : _variable$defs3[0];
279
+ if ((definition === null || definition === void 0 ? void 0 : definition.type) === 'Parameter' && isFirstParameter(definition.name)) {
280
+ return;
281
+ }
282
+ }
196
283
  }
197
284
  if (!((_expression = expression) !== null && _expression !== void 0 && _expression.properties)) {
198
285
  context.report({
@@ -19,4 +19,51 @@ export const ignoredAtRules = new Set(['@container',
19
19
  // ignored because it's covered by `no-container-queries`
20
20
  '@media',
21
21
  // ignored because it's covered by `no-nested-styles`
22
- '@supports', '@property']);
22
+ '@supports', '@property', '@starting-style']);
23
+
24
+ /**
25
+ * At-rules that are allowed to be used in "grouped" form within cssMap.
26
+ *
27
+ * "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
28
+ * (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
29
+ *
30
+ * ```typescript
31
+ * // ❌ GROUPED (not allowed for @media):
32
+ * cssMap({
33
+ * variant: {
34
+ * '@media': { // at-rule key with no parameters
35
+ * '(min-width: 900px)': {}, // nested variants
36
+ * '(min-width: 1200px)': {},
37
+ * }
38
+ * }
39
+ * })
40
+ *
41
+ * // ✅ FLAT (preferred for @media):
42
+ * cssMap({
43
+ * variant: {
44
+ * '@media (min-width: 900px)': {}, // at-rule with parameters
45
+ * '@media (min-width: 1200px)': {},
46
+ * }
47
+ * })
48
+ * ```
49
+ *
50
+ * However, some at-rules like `@starting-style` have no parameters and can only be
51
+ * written in the "grouped" form at the variant level:
52
+ *
53
+ * ```typescript
54
+ * // ✅ ALLOWED (only valid syntax for @starting-style):
55
+ * cssMap({
56
+ * fade: {
57
+ * '@starting-style': { // at-rule with no parameters
58
+ * opacity: 0, // styles to apply
59
+ * }
60
+ * }
61
+ * })
62
+ * ```
63
+ *
64
+ * Note: This only applies to at-rules at the variant level. Nested at-rules inside
65
+ * other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
66
+ * `walkStyleRuleset` and are not considered "grouped".
67
+ */
68
+ export const allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
69
+ ]);
@@ -5,6 +5,7 @@
5
5
  */
6
6
 
7
7
  import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
8
+ import { allowedGroupedAtRules } from './constants';
8
9
  export function walkCssMap({
9
10
  context,
10
11
  importSources,
@@ -102,11 +103,15 @@ function walkCssMapAtRuleGrouping({
102
103
  if (!atRule) {
103
104
  return;
104
105
  }
105
- visitor({
106
- type: 'grouped-at-rules',
107
- node: atRuleGrouping,
108
- atRule
109
- });
106
+
107
+ // Skip reporting if the at-rule is allowed to be grouped
108
+ if (!allowedGroupedAtRules.has(atRule)) {
109
+ visitor({
110
+ type: 'grouped-at-rules',
111
+ node: atRuleGrouping,
112
+ atRule
113
+ });
114
+ }
110
115
  if (atRuleGrouping.value.type !== 'ObjectExpression') {
111
116
  return;
112
117
  }
@@ -135,6 +135,40 @@ function isPropertyValueAllowed(property, context) {
135
135
  }
136
136
  return true;
137
137
  }
138
+
139
+ /**
140
+ * Returns true if the property is not nested within another property.
141
+ */
142
+ function isShallowProperty(property) {
143
+ var objectPattern = property.parent;
144
+ if (!isNodeOfType(objectPattern, 'ObjectPattern')) {
145
+ return false;
146
+ }
147
+ return isNodeOfType(objectPattern.parent, 'VariableDeclarator') || isNodeOfType(objectPattern.parent, 'FunctionDeclaration') || isNodeOfType(objectPattern.parent, 'FunctionExpression') || isNodeOfType(objectPattern.parent, 'ArrowFunctionExpression');
148
+ }
149
+ function isAllowedName(name) {
150
+ return name.name === 'style';
151
+ }
152
+ function isAllowedDefinition(definition) {
153
+ var name = definition.name;
154
+ var parent = name.parent;
155
+ if (!isNodeOfType(parent, 'Property')) {
156
+ return false;
157
+ }
158
+ if (!isNodeOfType(parent.key, 'Identifier') || !isNodeOfType(parent.value, 'Identifier') || !isAllowedName(parent.key) || !isAllowedName(parent.value)) {
159
+ return false;
160
+ }
161
+ if (!isShallowProperty(parent)) {
162
+ return false;
163
+ }
164
+ return true;
165
+ }
166
+ function isFirstParameter(identifier) {
167
+ if (!isNodeOfType(identifier.parent, 'FunctionDeclaration') && !isNodeOfType(identifier.parent, 'ArrowFunctionExpression') && !isNodeOfType(identifier.parent, 'FunctionExpression')) {
168
+ return false;
169
+ }
170
+ return identifier.parent.params[0] === identifier;
171
+ }
138
172
  export var rule = createLintRule({
139
173
  meta: {
140
174
  name: 'enforce-style-prop',
@@ -172,7 +206,7 @@ export var rule = createLintRule({
172
206
  // Typical `style={{ … }}` scenario
173
207
  expression = node.expression;
174
208
  } else if (node.expression.type === 'Identifier') {
175
- var _variable$defs;
209
+ var _variable$defs, _definition$node$init, _variable$defs2;
176
210
  /*
177
211
  * Example:
178
212
  * ```tsx
@@ -184,15 +218,66 @@ export var rule = createLintRule({
184
218
  sourceCode: getSourceCode(context),
185
219
  identifier: node.expression
186
220
  });
221
+ var definition = variable === null || variable === void 0 || (_variable$defs = variable.defs) === null || _variable$defs === void 0 ? void 0 : _variable$defs[0];
222
+
223
+ /**
224
+ * Allow passing a function parameter directly to the style prop
225
+ *
226
+ * @example
227
+ * function Component({ style }) { return <div style={style} />; }
228
+ *
229
+ * @example
230
+ * <Popper>
231
+ * {({ ref, style }) => <div ref={ref} style={style} />}
232
+ * </Popper>
233
+ */
234
+ if ((definition === null || definition === void 0 ? void 0 : definition.type) === 'Parameter' && isAllowedDefinition(definition)) {
235
+ return;
236
+ }
237
+
238
+ /**
239
+ * Allow passing a value destructured in the body from a function parameter to the style prop
240
+ *
241
+ * @example
242
+ * function Component(props) {
243
+ * const { style } = props;
244
+ * return <div style={style} />;
245
+ * }
246
+ */
247
+ if ((definition === null || definition === void 0 ? void 0 : definition.type) === 'Variable' && ((_definition$node$init = definition.node.init) === null || _definition$node$init === void 0 ? void 0 : _definition$node$init.type) === 'Identifier') {
248
+ var sourceVariable = findVariable({
249
+ identifier: definition.node.init,
250
+ sourceCode: getSourceCode(context)
251
+ });
252
+ var sourceDefinition = sourceVariable === null || sourceVariable === void 0 ? void 0 : sourceVariable.defs[0];
253
+ if ((sourceDefinition === null || sourceDefinition === void 0 ? void 0 : sourceDefinition.type) === 'Parameter' && isAllowedDefinition(definition)) {
254
+ return;
255
+ }
256
+ }
187
257
 
188
258
  // Types are alluding us here, but we really only want an ObjectExpression here
189
259
  // Additionally, if we have multiple variable definitions, we're in some unhandled scenario
190
260
  // so we're only going to look at the first one…
191
- var hopefulObjectExpression = variable === null || variable === void 0 || (_variable$defs = variable.defs) === null || _variable$defs === void 0 || (_variable$defs = _variable$defs[0]) === null || _variable$defs === void 0 || (_variable$defs = _variable$defs.node) === null || _variable$defs === void 0 ? void 0 : _variable$defs.init;
261
+ var hopefulObjectExpression = variable === null || variable === void 0 || (_variable$defs2 = variable.defs) === null || _variable$defs2 === void 0 || (_variable$defs2 = _variable$defs2[0]) === null || _variable$defs2 === void 0 || (_variable$defs2 = _variable$defs2.node) === null || _variable$defs2 === void 0 ? void 0 : _variable$defs2.init;
192
262
  if ((hopefulObjectExpression === null || hopefulObjectExpression === void 0 ? void 0 : hopefulObjectExpression.type) === 'ObjectExpression') {
193
263
  expression = hopefulObjectExpression;
194
264
  }
195
265
  reportOnNodeExpression = true;
266
+ } else if (node.expression.type === 'MemberExpression') {
267
+ /**
268
+ * Allow passing `props.style` to the style prop
269
+ */
270
+ if (node.expression.object.type === 'Identifier' && node.expression.property.type === 'Identifier' && isAllowedName(node.expression.property)) {
271
+ var _variable2$defs;
272
+ var _variable2 = findVariable({
273
+ sourceCode: getSourceCode(context),
274
+ identifier: node.expression.object
275
+ });
276
+ var _definition = _variable2 === null || _variable2 === void 0 || (_variable2$defs = _variable2.defs) === null || _variable2$defs === void 0 ? void 0 : _variable2$defs[0];
277
+ if ((_definition === null || _definition === void 0 ? void 0 : _definition.type) === 'Parameter' && isFirstParameter(_definition.name)) {
278
+ return;
279
+ }
280
+ }
196
281
  }
197
282
  if (!((_expression = expression) !== null && _expression !== void 0 && _expression.properties)) {
198
283
  context.report({
@@ -21,4 +21,51 @@ export var ignoredAtRules = new Set(['@container',
21
21
  // ignored because it's covered by `no-container-queries`
22
22
  '@media',
23
23
  // ignored because it's covered by `no-nested-styles`
24
- '@supports', '@property']);
24
+ '@supports', '@property', '@starting-style']);
25
+
26
+ /**
27
+ * At-rules that are allowed to be used in "grouped" form within cssMap.
28
+ *
29
+ * "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
30
+ * (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
31
+ *
32
+ * ```typescript
33
+ * // ❌ GROUPED (not allowed for @media):
34
+ * cssMap({
35
+ * variant: {
36
+ * '@media': { // at-rule key with no parameters
37
+ * '(min-width: 900px)': {}, // nested variants
38
+ * '(min-width: 1200px)': {},
39
+ * }
40
+ * }
41
+ * })
42
+ *
43
+ * // ✅ FLAT (preferred for @media):
44
+ * cssMap({
45
+ * variant: {
46
+ * '@media (min-width: 900px)': {}, // at-rule with parameters
47
+ * '@media (min-width: 1200px)': {},
48
+ * }
49
+ * })
50
+ * ```
51
+ *
52
+ * However, some at-rules like `@starting-style` have no parameters and can only be
53
+ * written in the "grouped" form at the variant level:
54
+ *
55
+ * ```typescript
56
+ * // ✅ ALLOWED (only valid syntax for @starting-style):
57
+ * cssMap({
58
+ * fade: {
59
+ * '@starting-style': { // at-rule with no parameters
60
+ * opacity: 0, // styles to apply
61
+ * }
62
+ * }
63
+ * })
64
+ * ```
65
+ *
66
+ * Note: This only applies to at-rules at the variant level. Nested at-rules inside
67
+ * other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
68
+ * `walkStyleRuleset` and are not considered "grouped".
69
+ */
70
+ export var allowedGroupedAtRules = new Set(['@starting-style' // Has no parameters, can only be written in grouped form
71
+ ]);
@@ -6,6 +6,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
6
6
  */
7
7
 
8
8
  import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
9
+ import { allowedGroupedAtRules } from './constants';
9
10
  export function walkCssMap(_ref) {
10
11
  var context = _ref.context,
11
12
  importSources = _ref.importSources,
@@ -103,11 +104,15 @@ function walkCssMapAtRuleGrouping(_ref4) {
103
104
  if (!atRule) {
104
105
  return;
105
106
  }
106
- visitor({
107
- type: 'grouped-at-rules',
108
- node: atRuleGrouping,
109
- atRule: atRule
110
- });
107
+
108
+ // Skip reporting if the at-rule is allowed to be grouped
109
+ if (!allowedGroupedAtRules.has(atRule)) {
110
+ visitor({
111
+ type: 'grouped-at-rules',
112
+ node: atRuleGrouping,
113
+ atRule: atRule
114
+ });
115
+ }
111
116
  if (atRuleGrouping.value.type !== 'ObjectExpression') {
112
117
  return;
113
118
  }
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -17,4 +17,49 @@ declare const cssPseudos: readonly ["&:active", "&:autofill", "&:blank", "&:chec
17
17
  export declare const allowedPseudos: Set<string>;
18
18
  export declare const legacyPseudoElements: Set<string>;
19
19
  export declare const ignoredAtRules: Set<string>;
20
+ /**
21
+ * At-rules that are allowed to be used in "grouped" form within cssMap.
22
+ *
23
+ * "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
24
+ * (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
25
+ *
26
+ * ```typescript
27
+ * // ❌ GROUPED (not allowed for @media):
28
+ * cssMap({
29
+ * variant: {
30
+ * '@media': { // at-rule key with no parameters
31
+ * '(min-width: 900px)': {}, // nested variants
32
+ * '(min-width: 1200px)': {},
33
+ * }
34
+ * }
35
+ * })
36
+ *
37
+ * // ✅ FLAT (preferred for @media):
38
+ * cssMap({
39
+ * variant: {
40
+ * '@media (min-width: 900px)': {}, // at-rule with parameters
41
+ * '@media (min-width: 1200px)': {},
42
+ * }
43
+ * })
44
+ * ```
45
+ *
46
+ * However, some at-rules like `@starting-style` have no parameters and can only be
47
+ * written in the "grouped" form at the variant level:
48
+ *
49
+ * ```typescript
50
+ * // ✅ ALLOWED (only valid syntax for @starting-style):
51
+ * cssMap({
52
+ * fade: {
53
+ * '@starting-style': { // at-rule with no parameters
54
+ * opacity: 0, // styles to apply
55
+ * }
56
+ * }
57
+ * })
58
+ * ```
59
+ *
60
+ * Note: This only applies to at-rules at the variant level. Nested at-rules inside
61
+ * other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
62
+ * `walkStyleRuleset` and are not considered "grouped".
63
+ */
64
+ export declare const allowedGroupedAtRules: Set<string>;
20
65
  export {};
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
@@ -82,4 +82,49 @@ declare const cssPseudos: readonly [
82
82
  export declare const allowedPseudos: Set<string>;
83
83
  export declare const legacyPseudoElements: Set<string>;
84
84
  export declare const ignoredAtRules: Set<string>;
85
+ /**
86
+ * At-rules that are allowed to be used in "grouped" form within cssMap.
87
+ *
88
+ * "Grouped" refers to the legacy Compiled syntax where an at-rule key with no parameters
89
+ * (matching `/^@[A-z-]+$/`) contains nested variant keys, like:
90
+ *
91
+ * ```typescript
92
+ * // ❌ GROUPED (not allowed for @media):
93
+ * cssMap({
94
+ * variant: {
95
+ * '@media': { // at-rule key with no parameters
96
+ * '(min-width: 900px)': {}, // nested variants
97
+ * '(min-width: 1200px)': {},
98
+ * }
99
+ * }
100
+ * })
101
+ *
102
+ * // ✅ FLAT (preferred for @media):
103
+ * cssMap({
104
+ * variant: {
105
+ * '@media (min-width: 900px)': {}, // at-rule with parameters
106
+ * '@media (min-width: 1200px)': {},
107
+ * }
108
+ * })
109
+ * ```
110
+ *
111
+ * However, some at-rules like `@starting-style` have no parameters and can only be
112
+ * written in the "grouped" form at the variant level:
113
+ *
114
+ * ```typescript
115
+ * // ✅ ALLOWED (only valid syntax for @starting-style):
116
+ * cssMap({
117
+ * fade: {
118
+ * '@starting-style': { // at-rule with no parameters
119
+ * opacity: 0, // styles to apply
120
+ * }
121
+ * }
122
+ * })
123
+ * ```
124
+ *
125
+ * Note: This only applies to at-rules at the variant level. Nested at-rules inside
126
+ * other rulesets (e.g., `@starting-style` inside `@media (...)`) are handled by
127
+ * `walkStyleRuleset` and are not considered "grouped".
128
+ */
129
+ export declare const allowedGroupedAtRules: Set<string>;
85
130
  export {};
@@ -1,2 +1,2 @@
1
- export declare const rule: import("eslint").Rule.RuleModule;
1
+ export declare const rule: import('eslint').Rule.RuleModule;
2
2
  export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
6
6
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@
36
36
  ],
37
37
  "atlaskit:src": "src/index.tsx",
38
38
  "dependencies": {
39
- "@atlaskit/eslint-plugin-design-system": "^13.33.0",
39
+ "@atlaskit/eslint-plugin-design-system": "^13.40.0",
40
40
  "@atlaskit/eslint-utils": "^2.0.0",
41
41
  "@babel/runtime": "^7.0.0",
42
42
  "@typescript-eslint/utils": "^7.1.0",