@atlaskit/eslint-plugin-ui-styling-standard 0.9.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +2 -0
- package/constellation/index/overview.mdx +2 -0
- package/constellation/no-dynamic-styles/usage.mdx +128 -0
- package/constellation/no-unsafe-values/usage.mdx +222 -0
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended.codegen.js +3 -1
- package/dist/cjs/rules/index.codegen.js +6 -2
- package/dist/cjs/rules/no-dynamic-styles/index.js +69 -0
- package/dist/cjs/rules/no-unsafe-values/index.js +85 -0
- package/dist/cjs/rules/no-unsafe-values/messages.js +24 -0
- package/dist/cjs/rules/no-unsafe-values/utils.js +437 -0
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended.codegen.js +3 -1
- package/dist/es2019/rules/index.codegen.js +6 -2
- package/dist/es2019/rules/no-dynamic-styles/index.js +51 -0
- package/dist/es2019/rules/no-unsafe-values/index.js +80 -0
- package/dist/es2019/rules/no-unsafe-values/messages.js +72 -0
- package/dist/es2019/rules/no-unsafe-values/utils.js +350 -0
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended.codegen.js +3 -1
- package/dist/esm/rules/index.codegen.js +6 -2
- package/dist/esm/rules/no-dynamic-styles/index.js +62 -0
- package/dist/esm/rules/no-unsafe-values/index.js +79 -0
- package/dist/esm/rules/no-unsafe-values/messages.js +17 -0
- package/dist/esm/rules/no-unsafe-values/utils.js +430 -0
- package/dist/types/index.codegen.d.ts +4 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/presets/recommended.codegen.d.ts +3 -1
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/no-dynamic-styles/index.d.ts +2 -0
- package/dist/types/rules/no-unsafe-values/index.d.ts +2 -0
- package/dist/types/rules/no-unsafe-values/messages.d.ts +13 -0
- package/dist/types/rules/no-unsafe-values/utils.d.ts +28 -0
- package/dist/types-ts4.5/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-dynamic-styles/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-unsafe-values/index.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-unsafe-values/messages.d.ts +13 -0
- package/dist/types-ts4.5/rules/no-unsafe-values/utils.d.ts +28 -0
- package/package.json +5 -4
- package/src/presets/all.codegen.tsx +3 -1
- package/src/presets/recommended.codegen.tsx +3 -1
- package/src/rules/index.codegen.tsx +5 -1
- package/src/rules/no-dynamic-styles/README.md +126 -0
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +128 -0
- package/src/rules/no-dynamic-styles/index.tsx +63 -0
- package/src/rules/no-unsafe-values/README.md +220 -0
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +27 -0
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +37 -0
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +229 -0
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +267 -0
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +52 -0
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +106 -0
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +44 -0
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +48 -0
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +75 -0
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +121 -0
- package/src/rules/no-unsafe-values/index.tsx +96 -0
- package/src/rules/no-unsafe-values/messages.tsx +86 -0
- package/src/rules/no-unsafe-values/utils.tsx +399 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Linter = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
|
|
11
|
+
var _findIdentifierNode = require("@atlaskit/eslint-utils/find-identifier-node");
|
|
12
|
+
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
13
|
+
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; } } }; }
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
function isReferenceToCssVar(variable) {
|
|
17
|
+
var definitions = variable.defs;
|
|
18
|
+
return definitions.every(function (definition) {
|
|
19
|
+
if (definition.type !== 'Variable') {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
var initializer = definition.node.init;
|
|
23
|
+
if (!initializer) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return initializer.type === 'Literal' && typeof initializer.value === 'string' && initializer.value.startsWith('--');
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
30
|
+
function Linter(context, baseNode) {
|
|
31
|
+
(0, _classCallCheck2.default)(this, Linter);
|
|
32
|
+
this.context = context;
|
|
33
|
+
this.baseNode = baseNode;
|
|
34
|
+
this.allowedDynamicKeys = (0, _allowedFunctionCalls.getAllowedDynamicKeys)(context.options);
|
|
35
|
+
this.allowedFunctionCalls = (0, _allowedFunctionCalls.getAllowedFunctionCalls)(context.options);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Wrapper around `context.report` to provide type checking on the message ID.
|
|
40
|
+
*/
|
|
41
|
+
(0, _createClass2.default)(Linter, [{
|
|
42
|
+
key: "report",
|
|
43
|
+
value: function report(descriptor) {
|
|
44
|
+
this.context.report(descriptor);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Fallback case to lint any identifier that is not otherwise handled.
|
|
49
|
+
*/
|
|
50
|
+
}, {
|
|
51
|
+
key: "lintUnhandledIdentifier",
|
|
52
|
+
value: function lintUnhandledIdentifier(identifier) {
|
|
53
|
+
this.report({
|
|
54
|
+
node: identifier,
|
|
55
|
+
messageId: 'no-variables'
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}, {
|
|
59
|
+
key: "lintIdentifier",
|
|
60
|
+
value: function lintIdentifier(value) {
|
|
61
|
+
var _this = this;
|
|
62
|
+
if (value.name === 'undefined') {
|
|
63
|
+
/**
|
|
64
|
+
* `undefined` gets caught implicitly anyway by other checks below,
|
|
65
|
+
* but we are explicitly handling it here.
|
|
66
|
+
*
|
|
67
|
+
* We could potentially introduce a distinct message for it as well.
|
|
68
|
+
*/
|
|
69
|
+
this.lintUnhandledIdentifier(value);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
var variable = (0, _findVariable.findVariable)({
|
|
73
|
+
identifier: value,
|
|
74
|
+
sourceCode: this.context.sourceCode
|
|
75
|
+
});
|
|
76
|
+
if (!variable) {
|
|
77
|
+
this.lintUnhandledIdentifier(value);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Allows using whitelisted imported values
|
|
83
|
+
*/
|
|
84
|
+
if ((0, _allowedFunctionCalls.isAllowListedVariable)({
|
|
85
|
+
allowList: this.allowedFunctionCalls,
|
|
86
|
+
variable: variable
|
|
87
|
+
})) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
var definitions = variable.defs;
|
|
91
|
+
if (definitions.length === 0) {
|
|
92
|
+
this.lintUnhandledIdentifier(value);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
definitions.forEach(function (definition) {
|
|
96
|
+
if (definition.type === 'Variable') {
|
|
97
|
+
var initializer = definition.node.init;
|
|
98
|
+
if (!initializer) {
|
|
99
|
+
_this.lintUnhandledIdentifier(value);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Variables can be used if they resolve to a literal.
|
|
105
|
+
*/
|
|
106
|
+
if (initializer.type === 'Literal') {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Not allowing tagged template expressions through variables.
|
|
112
|
+
*/
|
|
113
|
+
if (initializer.type === 'TaggedTemplateExpression') {
|
|
114
|
+
_this.report({
|
|
115
|
+
node: value,
|
|
116
|
+
messageId: 'no-function-calls'
|
|
117
|
+
});
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Variables can be used if they resolve to an allowed function call.
|
|
123
|
+
*/
|
|
124
|
+
if (initializer.type === 'CallExpression') {
|
|
125
|
+
if (_this.isAllowedFunctionCall(initializer)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
_this.report({
|
|
129
|
+
node: value,
|
|
130
|
+
messageId: 'no-function-calls'
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (initializer.type === 'TemplateLiteral') {
|
|
135
|
+
var _iterator = _createForOfIteratorHelper(initializer.expressions),
|
|
136
|
+
_step;
|
|
137
|
+
try {
|
|
138
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
139
|
+
var expression = _step.value;
|
|
140
|
+
_this.lintValue(expression);
|
|
141
|
+
}
|
|
142
|
+
} catch (err) {
|
|
143
|
+
_iterator.e(err);
|
|
144
|
+
} finally {
|
|
145
|
+
_iterator.f();
|
|
146
|
+
}
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* This branch is only here for clarity.
|
|
152
|
+
*
|
|
153
|
+
* We could fallback to `no-variables` for it too.
|
|
154
|
+
*/
|
|
155
|
+
if (initializer.type === 'ObjectExpression') {
|
|
156
|
+
_this.report({
|
|
157
|
+
node: value,
|
|
158
|
+
messageId: 'no-object-references'
|
|
159
|
+
});
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
_this.lintUnhandledIdentifier(value);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}, {
|
|
167
|
+
key: "isAllowedDynamicKey",
|
|
168
|
+
value: function isAllowedDynamicKey(expression) {
|
|
169
|
+
var identifier = (0, _findIdentifierNode.findIdentifierNode)(expression);
|
|
170
|
+
if (!identifier) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
var variable = (0, _findVariable.findVariable)({
|
|
174
|
+
identifier: identifier,
|
|
175
|
+
sourceCode: this.context.sourceCode
|
|
176
|
+
});
|
|
177
|
+
if (!variable) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
return isReferenceToCssVar(variable) || (0, _allowedFunctionCalls.isAllowListedVariable)({
|
|
181
|
+
allowList: this.allowedDynamicKeys,
|
|
182
|
+
variable: variable
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
186
|
+
key: "lintKey",
|
|
187
|
+
value: function lintKey(property) {
|
|
188
|
+
/**
|
|
189
|
+
* If it's not computed then it must be a plain string.
|
|
190
|
+
*
|
|
191
|
+
* Private identifiers cannot be computed,
|
|
192
|
+
* but we need the extra check for type narrowing.
|
|
193
|
+
*/
|
|
194
|
+
if (!property.computed || property.key.type === 'PrivateIdentifier') {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Some dynamic keys are explicitly allowed.
|
|
200
|
+
*/
|
|
201
|
+
if (this.isAllowedDynamicKey(property.key)) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
this.report({
|
|
205
|
+
node: property.key,
|
|
206
|
+
messageId: 'no-dynamic-keys'
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}, {
|
|
210
|
+
key: "isAllowedFunctionCall",
|
|
211
|
+
value: function isAllowedFunctionCall(value) {
|
|
212
|
+
var identifier = (0, _findIdentifierNode.findIdentifierNode)(value);
|
|
213
|
+
if (!identifier) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
var variable = (0, _findVariable.findVariable)({
|
|
217
|
+
identifier: identifier,
|
|
218
|
+
sourceCode: this.context.sourceCode
|
|
219
|
+
});
|
|
220
|
+
if (!variable) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
return (0, _allowedFunctionCalls.isAllowListedVariable)({
|
|
224
|
+
allowList: this.allowedFunctionCalls,
|
|
225
|
+
variable: variable
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}, {
|
|
229
|
+
key: "lintFunctionCall",
|
|
230
|
+
value: function lintFunctionCall(value) {
|
|
231
|
+
if (this.isAllowedFunctionCall(value)) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
this.report({
|
|
235
|
+
node: value,
|
|
236
|
+
messageId: 'no-function-calls'
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}, {
|
|
240
|
+
key: "lintObjectExpression",
|
|
241
|
+
value: function lintObjectExpression(expression) {
|
|
242
|
+
var _iterator2 = _createForOfIteratorHelper(expression.properties),
|
|
243
|
+
_step2;
|
|
244
|
+
try {
|
|
245
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
246
|
+
var property = _step2.value;
|
|
247
|
+
if (property.type === 'SpreadElement') {
|
|
248
|
+
this.report({
|
|
249
|
+
node: property,
|
|
250
|
+
messageId: 'no-spread-elements'
|
|
251
|
+
});
|
|
252
|
+
} else {
|
|
253
|
+
this.lintKey(property);
|
|
254
|
+
this.lintValue(property.value);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} catch (err) {
|
|
258
|
+
_iterator2.e(err);
|
|
259
|
+
} finally {
|
|
260
|
+
_iterator2.f();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
key: "lintUnhandledValue",
|
|
265
|
+
value: function lintUnhandledValue(value) {
|
|
266
|
+
/**
|
|
267
|
+
* Default to blocking value if it isn't explictly handled.
|
|
268
|
+
*/
|
|
269
|
+
this.report({
|
|
270
|
+
node: value,
|
|
271
|
+
messageId: 'no-unsafe-values'
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}, {
|
|
275
|
+
key: "lintValue",
|
|
276
|
+
value: function lintValue(value) {
|
|
277
|
+
/**
|
|
278
|
+
* Literals are always allowed by this rule.
|
|
279
|
+
*/
|
|
280
|
+
if (value.type === 'Literal') {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Allow negative numbers.
|
|
286
|
+
*/
|
|
287
|
+
if (value.type === 'UnaryExpression' && value.operator === '-' && value.argument.type === 'Literal') {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (value.type === 'TemplateLiteral') {
|
|
291
|
+
var _iterator3 = _createForOfIteratorHelper(value.expressions),
|
|
292
|
+
_step3;
|
|
293
|
+
try {
|
|
294
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
295
|
+
var expression = _step3.value;
|
|
296
|
+
this.lintValue(expression);
|
|
297
|
+
}
|
|
298
|
+
} catch (err) {
|
|
299
|
+
_iterator3.e(err);
|
|
300
|
+
} finally {
|
|
301
|
+
_iterator3.f();
|
|
302
|
+
}
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (value.type === 'ConditionalExpression' || value.type === 'LogicalExpression') {
|
|
306
|
+
this.report({
|
|
307
|
+
node: value,
|
|
308
|
+
messageId: 'no-conditional-values'
|
|
309
|
+
});
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (value.type === 'BinaryExpression') {
|
|
313
|
+
this.lintValue(value.left);
|
|
314
|
+
this.lintValue(value.right);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
if (value.type === 'ObjectExpression') {
|
|
318
|
+
this.lintObjectExpression(value);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (value.type === 'Identifier') {
|
|
322
|
+
this.lintIdentifier(value);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
if (value.type === 'TaggedTemplateExpression') {
|
|
326
|
+
this.report({
|
|
327
|
+
node: value,
|
|
328
|
+
messageId: 'no-function-calls'
|
|
329
|
+
});
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if (value.type === 'CallExpression') {
|
|
333
|
+
this.lintFunctionCall(value);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
if (value.type === 'ArrowFunctionExpression' || value.type === 'FunctionExpression') {
|
|
337
|
+
/**
|
|
338
|
+
* Function values are handled by `no-dynamic-styles` instead
|
|
339
|
+
*/
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (value.type === 'MemberExpression') {
|
|
343
|
+
this.report({
|
|
344
|
+
node: value,
|
|
345
|
+
messageId: 'no-object-access'
|
|
346
|
+
});
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (value.type === 'ArrayExpression') {
|
|
350
|
+
this.report({
|
|
351
|
+
node: value,
|
|
352
|
+
messageId: 'no-array-values'
|
|
353
|
+
});
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
this.lintUnhandledValue(value);
|
|
357
|
+
}
|
|
358
|
+
}, {
|
|
359
|
+
key: "lintArgument",
|
|
360
|
+
value: function lintArgument(argument) {
|
|
361
|
+
if (argument.type === 'ArrowFunctionExpression') {
|
|
362
|
+
if (argument.body.type === 'ObjectExpression') {
|
|
363
|
+
// Something in this form:
|
|
364
|
+
//
|
|
365
|
+
// const styles = styled.div(
|
|
366
|
+
// (props) => ({ color: props.height }),
|
|
367
|
+
// );
|
|
368
|
+
this.lintArgument(argument.body);
|
|
369
|
+
}
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (argument.type === 'ArrayExpression') {
|
|
373
|
+
var _iterator4 = _createForOfIteratorHelper(argument.elements),
|
|
374
|
+
_step4;
|
|
375
|
+
try {
|
|
376
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
377
|
+
var element = _step4.value;
|
|
378
|
+
if (element === null) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
this.lintArgument(element);
|
|
382
|
+
}
|
|
383
|
+
} catch (err) {
|
|
384
|
+
_iterator4.e(err);
|
|
385
|
+
} finally {
|
|
386
|
+
_iterator4.f();
|
|
387
|
+
}
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (argument.type === 'ObjectExpression') {
|
|
391
|
+
this.lintObjectExpression(argument);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (argument.type === 'CallExpression') {
|
|
395
|
+
this.lintFunctionCall(argument);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (argument.type === 'ConditionalExpression' || argument.type === 'LogicalExpression') {
|
|
399
|
+
this.report({
|
|
400
|
+
node: argument,
|
|
401
|
+
messageId: 'no-conditional-values'
|
|
402
|
+
});
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (argument.type === 'Identifier' || argument.type === 'MemberExpression') {
|
|
406
|
+
this.report({
|
|
407
|
+
node: argument,
|
|
408
|
+
messageId: 'no-identifier-arguments'
|
|
409
|
+
});
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
this.lintUnhandledValue(argument);
|
|
413
|
+
}
|
|
414
|
+
}, {
|
|
415
|
+
key: "lintArguments",
|
|
416
|
+
value: function lintArguments(args) {
|
|
417
|
+
var _iterator5 = _createForOfIteratorHelper(args),
|
|
418
|
+
_step5;
|
|
419
|
+
try {
|
|
420
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
421
|
+
var argument = _step5.value;
|
|
422
|
+
this.lintArgument(argument);
|
|
423
|
+
}
|
|
424
|
+
} catch (err) {
|
|
425
|
+
_iterator5.e(err);
|
|
426
|
+
} finally {
|
|
427
|
+
_iterator5.f();
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}, {
|
|
431
|
+
key: "run",
|
|
432
|
+
value: function run() {
|
|
433
|
+
this.lintArguments(this.baseNode.arguments);
|
|
434
|
+
}
|
|
435
|
+
}]);
|
|
436
|
+
return Linter;
|
|
437
|
+
}();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::544c8b1c0eb0d6329064dcf92e18e45e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -12,8 +12,10 @@ export default {
|
|
|
12
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
15
16
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
17
19
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
18
20
|
excludeReactComponents: true
|
|
19
21
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::544c8b1c0eb0d6329064dcf92e18e45e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -12,8 +12,10 @@ export default {
|
|
|
12
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
13
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
15
16
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
18
|
+
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
17
19
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
18
20
|
excludeReactComponents: true
|
|
19
21
|
}],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::edaedcad824fed1e108f90d909287584>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import convertPropsSyntax from './convert-props-syntax';
|
|
@@ -9,8 +9,10 @@ import localCxXcss from './local-cx-xcss';
|
|
|
9
9
|
import noArrayArguments from './no-array-arguments';
|
|
10
10
|
import noClassnameProp from './no-classname-prop';
|
|
11
11
|
import noContainerQueries from './no-container-queries';
|
|
12
|
+
import noDynamicStyles from './no-dynamic-styles';
|
|
12
13
|
import noImportantStyles from './no-important-styles';
|
|
13
14
|
import noNestedSelectors from './no-nested-selectors';
|
|
15
|
+
import noUnsafeValues from './no-unsafe-values';
|
|
14
16
|
export default {
|
|
15
17
|
'convert-props-syntax': convertPropsSyntax,
|
|
16
18
|
'enforce-style-prop': enforceStyleProp,
|
|
@@ -18,6 +20,8 @@ export default {
|
|
|
18
20
|
'no-array-arguments': noArrayArguments,
|
|
19
21
|
'no-classname-prop': noClassnameProp,
|
|
20
22
|
'no-container-queries': noContainerQueries,
|
|
23
|
+
'no-dynamic-styles': noDynamicStyles,
|
|
21
24
|
'no-important-styles': noImportantStyles,
|
|
22
|
-
'no-nested-selectors': noNestedSelectors
|
|
25
|
+
'no-nested-selectors': noNestedSelectors,
|
|
26
|
+
'no-unsafe-values': noUnsafeValues
|
|
23
27
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import esquery from 'esquery';
|
|
2
|
+
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { createLintRule } from '../utils/create-rule';
|
|
4
|
+
const schema = [{
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
importSources: {
|
|
8
|
+
type: 'array',
|
|
9
|
+
items: {
|
|
10
|
+
type: 'string'
|
|
11
|
+
},
|
|
12
|
+
uniqueItems: true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}];
|
|
16
|
+
export const rule = createLintRule({
|
|
17
|
+
meta: {
|
|
18
|
+
name: 'no-dynamic-styles',
|
|
19
|
+
docs: {
|
|
20
|
+
description: 'Disallows use of dynamic styles in CSS-in-JS calls',
|
|
21
|
+
recommended: true,
|
|
22
|
+
severity: 'warn'
|
|
23
|
+
},
|
|
24
|
+
schema,
|
|
25
|
+
messages: {
|
|
26
|
+
'no-dynamic-styles': 'Dynamic styles are not allowed. Instead use the style prop to apply styles derived from component props.'
|
|
27
|
+
},
|
|
28
|
+
type: 'problem'
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
const importSources = getImportSources(context);
|
|
32
|
+
return {
|
|
33
|
+
CallExpression(node) {
|
|
34
|
+
const {
|
|
35
|
+
references
|
|
36
|
+
} = context.sourceCode.getScope(node);
|
|
37
|
+
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const matches = esquery(node, 'ArrowFunctionExpression, FunctionExpression');
|
|
41
|
+
for (const match of matches) {
|
|
42
|
+
context.report({
|
|
43
|
+
node: match,
|
|
44
|
+
messageId: 'no-dynamic-styles'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
export default rule;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
import { isCss, getImportSources, isStyled, isKeyframes, isCssMap, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { Linter } from './utils';
|
|
4
|
+
import { messages } from './messages';
|
|
5
|
+
const schema = [{
|
|
6
|
+
type: 'object',
|
|
7
|
+
additionalProperties: false,
|
|
8
|
+
properties: {
|
|
9
|
+
importSources: {
|
|
10
|
+
type: 'array',
|
|
11
|
+
items: {
|
|
12
|
+
type: 'string'
|
|
13
|
+
},
|
|
14
|
+
uniqueItems: true
|
|
15
|
+
},
|
|
16
|
+
allowedFunctionCalls: {
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: {
|
|
19
|
+
type: 'array',
|
|
20
|
+
minItems: 2,
|
|
21
|
+
maxItems: 2,
|
|
22
|
+
items: [{
|
|
23
|
+
type: 'string'
|
|
24
|
+
}, {
|
|
25
|
+
type: 'string'
|
|
26
|
+
}]
|
|
27
|
+
},
|
|
28
|
+
uniqueItems: true
|
|
29
|
+
},
|
|
30
|
+
allowedDynamicKeys: {
|
|
31
|
+
type: 'array',
|
|
32
|
+
items: {
|
|
33
|
+
type: 'array',
|
|
34
|
+
minItems: 2,
|
|
35
|
+
maxItems: 2,
|
|
36
|
+
items: [{
|
|
37
|
+
type: 'string'
|
|
38
|
+
}, {
|
|
39
|
+
type: 'string'
|
|
40
|
+
}]
|
|
41
|
+
},
|
|
42
|
+
uniqueItems: true
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}];
|
|
46
|
+
export const rule = createLintRule({
|
|
47
|
+
meta: {
|
|
48
|
+
name: 'no-unsafe-values',
|
|
49
|
+
docs: {
|
|
50
|
+
description: 'Disallows styles that are difficult/impossible to statically anaylze.',
|
|
51
|
+
recommended: true,
|
|
52
|
+
severity: 'warn'
|
|
53
|
+
},
|
|
54
|
+
messages,
|
|
55
|
+
type: 'problem',
|
|
56
|
+
schema
|
|
57
|
+
},
|
|
58
|
+
create(context) {
|
|
59
|
+
const importSources = getImportSources(context);
|
|
60
|
+
return {
|
|
61
|
+
CallExpression(node) {
|
|
62
|
+
const {
|
|
63
|
+
references
|
|
64
|
+
} = context.sourceCode.getScope(node);
|
|
65
|
+
if (!isCss(node.callee, references, importSources) && !isStyled(node.callee, references, importSources) && !isKeyframes(node.callee, references, importSources) && !isCssMap(node.callee, references, importSources) && !isXcss(node.callee, references, importSources)) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (isStyled(node.callee, references, importSources) && (node.parent.type === 'CallExpression' || node.parent.type === 'TaggedTemplateExpression')) {
|
|
69
|
+
/**
|
|
70
|
+
* If it is of the form styled(Base)({}) we don't want to lint the inner function arguments.
|
|
71
|
+
*/
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const linter = new Linter(context, node);
|
|
75
|
+
linter.run();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
export default rule;
|