@atlaskit/eslint-plugin-ui-styling-standard 0.6.0 → 0.6.2
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 +13 -0
- package/README.md +16 -15
- package/constellation/convert-props-syntax/usage.mdx +115 -0
- package/constellation/index/overview.mdx +16 -15
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/convert-props-syntax/index.js +396 -0
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/utils/is-supported-import.js +7 -0
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/convert-props-syntax/index.js +291 -0
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/utils/is-supported-import.js +7 -0
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/convert-props-syntax/index.js +389 -0
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/utils/is-supported-import.js +7 -0
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/convert-props-syntax/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/utils/create-rule.d.ts +1 -1
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/convert-props-syntax/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -1
- package/package.json +6 -4
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/convert-props-syntax/README.md +113 -0
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +76 -0
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +422 -0
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +140 -0
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +69 -0
- package/src/rules/convert-props-syntax/index.tsx +414 -0
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/utils/README.md +1 -0
- package/src/rules/utils/is-supported-import.tsx +7 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.rule = exports.default = void 0;
|
|
8
|
+
var _eslintScope = require("eslint-scope");
|
|
9
|
+
var _createRule = require("../utils/create-rule");
|
|
10
|
+
var _isSupportedImport = require("../utils/is-supported-import");
|
|
11
|
+
var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
12
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
13
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
+
var IMPORT_SOURCES = [_isSupportedImport.CSS_IN_JS_IMPORTS.styledComponents];
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Represents some information about single line that contains some props, e.g.
|
|
19
|
+
* the arrow function in
|
|
20
|
+
*
|
|
21
|
+
* color: (props) => `mix(${props.myColor}, #fff)`
|
|
22
|
+
*
|
|
23
|
+
* or about a destructuring assignment, e.g. the arrow function in
|
|
24
|
+
*
|
|
25
|
+
* color: ({ myColor, otherColor }) => someFunction(myColor, otherColor)
|
|
26
|
+
*
|
|
27
|
+
* or something that we don't recognise, or that we don't think is valid
|
|
28
|
+
*
|
|
29
|
+
* color: (props, someOtherVariable) => someOtherVariable
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
var standardizePropExpression = function standardizePropExpression(sourceCode, expression) {
|
|
33
|
+
var propsObjectName = 'props';
|
|
34
|
+
if (expression.type === 'Identifier') {
|
|
35
|
+
return "".concat(propsObjectName, ".").concat(expression.name);
|
|
36
|
+
}
|
|
37
|
+
if (expression.type === 'MemberExpression' && expression.property.type === 'Identifier') {
|
|
38
|
+
var propertyName = sourceCode.getText(expression.property);
|
|
39
|
+
return "".concat(propsObjectName, ".").concat(propertyName);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Cannot safely process the expression, bail out!
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
45
|
+
var parseArrowFunctionExpression = function parseArrowFunctionExpression(expression, sourceCode) {
|
|
46
|
+
if (expression.params.length !== 1) {
|
|
47
|
+
return {
|
|
48
|
+
valid: false
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
var scopeManager = (0, _eslintScope.analyze)(expression, {});
|
|
52
|
+
var currentScope = scopeManager.acquire(expression);
|
|
53
|
+
if (!currentScope) {
|
|
54
|
+
return {
|
|
55
|
+
valid: false
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
var parameter = expression.params[0];
|
|
59
|
+
var props = [];
|
|
60
|
+
|
|
61
|
+
// Don't bother handling type annotations that appear in the parameters of arrow functions.
|
|
62
|
+
//
|
|
63
|
+
// This only applies if the ESLint rule is running under @typescript-eslint (not regular eslint), hence the roundabout way we use to check whether parameter.typeAnnotation exists or not.
|
|
64
|
+
if ('typeAnnotation' in parameter && parameter.typeAnnotation) {
|
|
65
|
+
return {
|
|
66
|
+
valid: false
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (parameter.type === 'ObjectPattern') {
|
|
70
|
+
if (parameter.properties.some(function (value) {
|
|
71
|
+
return value.type === 'RestElement';
|
|
72
|
+
})) {
|
|
73
|
+
return {
|
|
74
|
+
valid: false
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
var properties = parameter.properties;
|
|
78
|
+
var _iterator = _createForOfIteratorHelper(properties),
|
|
79
|
+
_step;
|
|
80
|
+
try {
|
|
81
|
+
var _loop = function _loop() {
|
|
82
|
+
var property = _step.value;
|
|
83
|
+
var propertyValue = property.value;
|
|
84
|
+
// Don't bother supporting other patterns like rest elements, default values...
|
|
85
|
+
if (propertyValue.type !== 'Identifier') {
|
|
86
|
+
return {
|
|
87
|
+
v: {
|
|
88
|
+
valid: false
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
var variable = currentScope.variables.find(function (varb) {
|
|
93
|
+
return varb.name === propertyValue.name;
|
|
94
|
+
});
|
|
95
|
+
if (!variable || !variable.references || !variable.references.length) {
|
|
96
|
+
// Something went wrong, best to just bail out.
|
|
97
|
+
return {
|
|
98
|
+
v: {
|
|
99
|
+
valid: false
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
var propName = standardizePropExpression(sourceCode, propertyValue);
|
|
104
|
+
if (!propName) {
|
|
105
|
+
return {
|
|
106
|
+
v: {
|
|
107
|
+
valid: false
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
props.push({
|
|
112
|
+
propName: propName,
|
|
113
|
+
usages: variable.references.map(function (reference) {
|
|
114
|
+
return reference.identifier;
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
_ret;
|
|
119
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
120
|
+
_ret = _loop();
|
|
121
|
+
if (_ret) return _ret.v;
|
|
122
|
+
}
|
|
123
|
+
} catch (err) {
|
|
124
|
+
_iterator.e(err);
|
|
125
|
+
} finally {
|
|
126
|
+
_iterator.f();
|
|
127
|
+
}
|
|
128
|
+
} else if (parameter.type === 'Identifier') {
|
|
129
|
+
var variable = currentScope.variables.find(function (varb) {
|
|
130
|
+
return varb.name === parameter.name;
|
|
131
|
+
});
|
|
132
|
+
if (!variable || !variable.references || !variable.references.length) {
|
|
133
|
+
// Something went wrong, best to just bail out.
|
|
134
|
+
return {
|
|
135
|
+
valid: false
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
var _iterator2 = _createForOfIteratorHelper(variable.references),
|
|
139
|
+
_step2;
|
|
140
|
+
try {
|
|
141
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
142
|
+
var reference = _step2.value;
|
|
143
|
+
var memberExpression = reference.identifier.parent;
|
|
144
|
+
if (memberExpression.type !== 'MemberExpression') {
|
|
145
|
+
// If reference.identifier.parent is not a member expression, that indicates
|
|
146
|
+
// that we have a usage of the props argument that does NOT look like
|
|
147
|
+
//
|
|
148
|
+
// (props) => props.color
|
|
149
|
+
//
|
|
150
|
+
// e.g. we might have (props) => props['...'] or (props) => `${props}px` perhaps...
|
|
151
|
+
//
|
|
152
|
+
// We have no choice but to bail out because the syntax is not what we expect.
|
|
153
|
+
return {
|
|
154
|
+
valid: false
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
var propName = standardizePropExpression(sourceCode, memberExpression);
|
|
158
|
+
if (!propName) {
|
|
159
|
+
return {
|
|
160
|
+
valid: false
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
props.push({
|
|
164
|
+
propName: propName,
|
|
165
|
+
usages: [memberExpression]
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
} catch (err) {
|
|
169
|
+
_iterator2.e(err);
|
|
170
|
+
} finally {
|
|
171
|
+
_iterator2.f();
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
// Bail out for any syntax we don't recognise.
|
|
175
|
+
return {
|
|
176
|
+
valid: false
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
arrowFunctionExpression: expression,
|
|
181
|
+
props: props,
|
|
182
|
+
valid: true
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
var lintArguments = function lintArguments(context, args) {
|
|
186
|
+
var _iterator3 = _createForOfIteratorHelper(args),
|
|
187
|
+
_step3;
|
|
188
|
+
try {
|
|
189
|
+
var _loop2 = function _loop2() {
|
|
190
|
+
var argument = _step3.value;
|
|
191
|
+
if (argument.type === 'ArrowFunctionExpression') {
|
|
192
|
+
// styled.div((props) => ({ ... }))
|
|
193
|
+
// styled.div(({ color, height }) => ({ ... }))
|
|
194
|
+
//
|
|
195
|
+
// Already in the form we want.
|
|
196
|
+
return 0; // continue
|
|
197
|
+
} else if (argument.type === 'ObjectExpression') {
|
|
198
|
+
var allProps = [];
|
|
199
|
+
|
|
200
|
+
// vvvvvvv
|
|
201
|
+
// styled.div({ ... })
|
|
202
|
+
var _iterator4 = _createForOfIteratorHelper(argument.properties),
|
|
203
|
+
_step4;
|
|
204
|
+
try {
|
|
205
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
206
|
+
var property = _step4.value;
|
|
207
|
+
if (property.type === 'SpreadElement') {
|
|
208
|
+
// e.g.
|
|
209
|
+
// styled.div({ color: 'blue', ...someStyles })
|
|
210
|
+
//
|
|
211
|
+
// If we have a spread element, we can no longer safely
|
|
212
|
+
// transform this styled/css call without a lot more effort.
|
|
213
|
+
//
|
|
214
|
+
// Best to give up...
|
|
215
|
+
return {
|
|
216
|
+
v: void 0
|
|
217
|
+
};
|
|
218
|
+
} else {
|
|
219
|
+
_estraverse.default.traverse(property.value, {
|
|
220
|
+
enter: function enter(node, _parent) {
|
|
221
|
+
if (node.type === 'ArrowFunctionExpression') {
|
|
222
|
+
var propNames = parseArrowFunctionExpression(node, context.getSourceCode());
|
|
223
|
+
if (!propNames) {
|
|
224
|
+
// We've encountered a CSS value we don't recognise, skip.
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
allProps.push(propNames);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
} catch (err) {
|
|
234
|
+
_iterator4.e(err);
|
|
235
|
+
} finally {
|
|
236
|
+
_iterator4.f();
|
|
237
|
+
}
|
|
238
|
+
if (!allProps.length) {
|
|
239
|
+
return 0; // continue
|
|
240
|
+
}
|
|
241
|
+
if (allProps.some(function (propUsage) {
|
|
242
|
+
return !propUsage.valid;
|
|
243
|
+
})) {
|
|
244
|
+
context.report({
|
|
245
|
+
node: argument,
|
|
246
|
+
messageId: 'unsupported-styled-components-prop-syntax-no-autofixer'
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
v: void 0
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
context.report({
|
|
253
|
+
node: argument,
|
|
254
|
+
messageId: 'unsupported-styled-components-prop-syntax',
|
|
255
|
+
fix: function fix(fixer) {
|
|
256
|
+
var sourceCode = context.getSourceCode();
|
|
257
|
+
return fixPropsObjectUsages(fixer, sourceCode, argument,
|
|
258
|
+
// The
|
|
259
|
+
// allProps.some((propUsage) => !propUsage.valid)
|
|
260
|
+
// condition above should have made this type assertion unnecessary...
|
|
261
|
+
allProps);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
_ret2;
|
|
267
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
268
|
+
_ret2 = _loop2();
|
|
269
|
+
if (_ret2 === 0) continue;
|
|
270
|
+
if (_ret2) return _ret2.v;
|
|
271
|
+
}
|
|
272
|
+
} catch (err) {
|
|
273
|
+
_iterator3.e(err);
|
|
274
|
+
} finally {
|
|
275
|
+
_iterator3.f();
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
var convertPropUsage = function convertPropUsage(propUsage, sourceCode) {
|
|
279
|
+
var arrowFunctionOffset = propUsage.arrowFunctionExpression.body.loc ? {
|
|
280
|
+
startIndex: sourceCode.getIndexFromLoc(propUsage.arrowFunctionExpression.body.loc.start),
|
|
281
|
+
endIndex: sourceCode.getIndexFromLoc(propUsage.arrowFunctionExpression.body.loc.end)
|
|
282
|
+
} : undefined;
|
|
283
|
+
if (!arrowFunctionOffset) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
var sectionsToUpdate = [];
|
|
287
|
+
var newCode = [];
|
|
288
|
+
var _iterator5 = _createForOfIteratorHelper(propUsage.props),
|
|
289
|
+
_step5;
|
|
290
|
+
try {
|
|
291
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
292
|
+
var prop = _step5.value;
|
|
293
|
+
var _iterator6 = _createForOfIteratorHelper(prop.usages),
|
|
294
|
+
_step6;
|
|
295
|
+
try {
|
|
296
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
297
|
+
var usage = _step6.value;
|
|
298
|
+
if (!usage.loc) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
sectionsToUpdate.push({
|
|
302
|
+
identifier: usage,
|
|
303
|
+
newCode: prop.propName,
|
|
304
|
+
startIndex: sourceCode.getIndexFromLoc(usage.loc.start),
|
|
305
|
+
endIndex: sourceCode.getIndexFromLoc(usage.loc.end)
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
} catch (err) {
|
|
309
|
+
_iterator6.e(err);
|
|
310
|
+
} finally {
|
|
311
|
+
_iterator6.f();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
} catch (err) {
|
|
315
|
+
_iterator5.e(err);
|
|
316
|
+
} finally {
|
|
317
|
+
_iterator5.f();
|
|
318
|
+
}
|
|
319
|
+
sectionsToUpdate.sort(function (a, b) {
|
|
320
|
+
if (!a.identifier.loc || !b.identifier.loc) {
|
|
321
|
+
return 0;
|
|
322
|
+
}
|
|
323
|
+
return a.identifier.loc.start.line - b.identifier.loc.start.line || a.identifier.loc.start.column - b.identifier.loc.start.column;
|
|
324
|
+
});
|
|
325
|
+
var prevEndIndex = arrowFunctionOffset.startIndex;
|
|
326
|
+
for (var _i = 0, _sectionsToUpdate = sectionsToUpdate; _i < _sectionsToUpdate.length; _i++) {
|
|
327
|
+
var section = _sectionsToUpdate[_i];
|
|
328
|
+
if (prevEndIndex > section.startIndex || prevEndIndex >= section.endIndex) {
|
|
329
|
+
// Props overlap! This is unexpected, bail out.
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
newCode.push(sourceCode.getText().slice(prevEndIndex, section.startIndex));
|
|
333
|
+
newCode.push(section.newCode);
|
|
334
|
+
prevEndIndex = section.endIndex;
|
|
335
|
+
}
|
|
336
|
+
newCode.push(sourceCode.getText().slice(prevEndIndex, arrowFunctionOffset.endIndex));
|
|
337
|
+
return newCode.join('');
|
|
338
|
+
};
|
|
339
|
+
var fixPropsObjectUsages = function fixPropsObjectUsages(fixer, sourceCode, expression, allProps) {
|
|
340
|
+
var fixers = [
|
|
341
|
+
// Wrap the object (containing the CSS properties and values) in an arrow function,
|
|
342
|
+
// so it becomes something like
|
|
343
|
+
//
|
|
344
|
+
// styled.div(
|
|
345
|
+
// (props) => ({
|
|
346
|
+
// color: ...
|
|
347
|
+
// })
|
|
348
|
+
// );
|
|
349
|
+
fixer.insertTextBefore(expression, '(props) => ('), fixer.insertTextAfter(expression, ')')];
|
|
350
|
+
var _iterator7 = _createForOfIteratorHelper(allProps),
|
|
351
|
+
_step7;
|
|
352
|
+
try {
|
|
353
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
354
|
+
var propUsage = _step7.value;
|
|
355
|
+
var arrowFunctionExpression = propUsage.arrowFunctionExpression;
|
|
356
|
+
var newCode = convertPropUsage(propUsage, sourceCode);
|
|
357
|
+
if (newCode) {
|
|
358
|
+
fixers.push(fixer.replaceText(arrowFunctionExpression, newCode));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
} catch (err) {
|
|
362
|
+
_iterator7.e(err);
|
|
363
|
+
} finally {
|
|
364
|
+
_iterator7.f();
|
|
365
|
+
}
|
|
366
|
+
return fixers;
|
|
367
|
+
};
|
|
368
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
369
|
+
meta: {
|
|
370
|
+
name: 'convert-props-syntax',
|
|
371
|
+
docs: {
|
|
372
|
+
description: 'Convert props syntax that is unsupported by `styled-components` <4.x to props syntax that is supported. This is useful when used in conjunction with `no-styled-tagged-template-expression`, as output from the latter may use props syntax unsupported by `styled-components`.',
|
|
373
|
+
recommended: true,
|
|
374
|
+
severity: 'error'
|
|
375
|
+
},
|
|
376
|
+
fixable: 'code',
|
|
377
|
+
messages: {
|
|
378
|
+
'unsupported-styled-components-prop-syntax': 'This syntax is not supported by styled-components <4.x and will fail at runtime!\n\nTo fix this, you can either migrate this to `@compiled/react`, or use the autofixer to switch the syntax from the `styled.div({ property: (props) => props.value })` syntax to the `styled.div(props => ({ property: props.value }))` syntax.',
|
|
379
|
+
'unsupported-styled-components-prop-syntax-no-autofixer': 'This syntax is not supported by styled-components <4.x and will fail at runtime!\n\nTo fix this, you can either migrate this to `@compiled/react`, or manually migrate the syntax from the `styled.div({ property: (props) => props.value })` syntax to the `styled.div(props => ({ property: props.value }))` syntax.\n\nCheck out the rule documentation for examples.'
|
|
380
|
+
},
|
|
381
|
+
type: 'problem'
|
|
382
|
+
},
|
|
383
|
+
create: function create(context) {
|
|
384
|
+
return {
|
|
385
|
+
'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
|
|
386
|
+
var references = context.getScope().references;
|
|
387
|
+
var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
|
|
388
|
+
if (!(0, _isSupportedImport.isStyledComponents)(callee, references, IMPORT_SOURCES)) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
lintArguments(context, node.arguments);
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
var _default = exports.default = rule;
|
|
@@ -5,15 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
+
var _convertPropsSyntax = _interopRequireDefault(require("./convert-props-syntax"));
|
|
8
9
|
var _localCxXcss = _interopRequireDefault(require("./local-cx-xcss"));
|
|
9
10
|
var _noClassnameProp = _interopRequireDefault(require("./no-classname-prop"));
|
|
10
11
|
var _noImportantStyles = _interopRequireDefault(require("./no-important-styles"));
|
|
11
12
|
/**
|
|
12
13
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
13
|
-
* @codegen <<SignedSource::
|
|
14
|
+
* @codegen <<SignedSource::7c8793f6c12f32e915fd9b4dc7a6edef>>
|
|
14
15
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
15
16
|
*/
|
|
16
17
|
var _default = exports.default = {
|
|
18
|
+
'convert-props-syntax': _convertPropsSyntax.default,
|
|
17
19
|
'local-cx-xcss': _localCxXcss.default,
|
|
18
20
|
'no-classname-prop': _noClassnameProp.default,
|
|
19
21
|
'no-important-styles': _noImportantStyles.default
|
|
@@ -4,6 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isXcss = exports.isStyledComponents = exports.isStyled = exports.isKeyframes = exports.isImportedFrom = exports.isEmotion = exports.isCxFunction = exports.isCssMap = exports.isCss = exports.isCompiled = exports.getImportSources = exports.DEFAULT_IMPORT_SOURCES = exports.CSS_IN_JS_IMPORTS = void 0;
|
|
7
|
+
// This should be kept in sync with
|
|
8
|
+
// packages/design-system/eslint-plugin/src/rules/utils/is-supported-import.tsx
|
|
9
|
+
// whenever possible.
|
|
10
|
+
//
|
|
11
|
+
// TODO: would having an @atlassian/eslint-plugin-design-system-common
|
|
12
|
+
// package be useful?
|
|
13
|
+
|
|
7
14
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
15
|
|
|
9
16
|
var CSS_IN_JS_IMPORTS = exports.CSS_IN_JS_IMPORTS = {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c4a9648d888d86d752ea2b3442d395ba>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
|
|
9
10
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::c4a9648d888d86d752ea2b3442d395ba>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
|
|
9
10
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|