@atlaskit/eslint-plugin-ui-styling-standard 0.8.1 → 0.8.3
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 +12 -0
- package/dist/cjs/rules/convert-props-syntax/index.js +30 -3
- package/dist/cjs/rules/no-nested-selectors/index.js +2 -2
- package/dist/es2019/rules/convert-props-syntax/index.js +21 -2
- package/dist/es2019/rules/no-nested-selectors/index.js +3 -3
- package/dist/esm/rules/convert-props-syntax/index.js +30 -3
- package/dist/esm/rules/no-nested-selectors/index.js +3 -3
- package/package.json +2 -2
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +82 -2
- package/src/rules/convert-props-syntax/index.tsx +22 -3
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +49 -0
- package/src/rules/no-nested-selectors/index.tsx +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.8.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#87496](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/87496) [`d5b439e94043`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d5b439e94043) - Improve coverage of `convert-props-syntax` rule. Previously cases such as `css()` and `styled(BaseComponent)()` were not covered by the rule.
|
|
8
|
+
|
|
9
|
+
## 0.8.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#88753](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/88753) [`df5cbd4957ea`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/df5cbd4957ea) - Fixed no nested selectors rule to skip @ queries, cssMap and keyFrames calls
|
|
14
|
+
|
|
3
15
|
## 0.8.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -9,6 +9,7 @@ var _eslintScope = require("eslint-scope");
|
|
|
9
9
|
var _createRule = require("../utils/create-rule");
|
|
10
10
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
11
11
|
var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
12
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
12
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; } } }; }
|
|
13
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); }
|
|
14
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; }
|
|
@@ -224,7 +225,11 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
224
225
|
}
|
|
225
226
|
allProps.push(propNames);
|
|
226
227
|
}
|
|
227
|
-
}
|
|
228
|
+
},
|
|
229
|
+
/**
|
|
230
|
+
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
|
231
|
+
*/
|
|
232
|
+
fallback: 'iteration'
|
|
228
233
|
});
|
|
229
234
|
}
|
|
230
235
|
}
|
|
@@ -380,7 +385,16 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
380
385
|
},
|
|
381
386
|
create: function create(context) {
|
|
382
387
|
return {
|
|
383
|
-
|
|
388
|
+
CallExpression: function (_CallExpression) {
|
|
389
|
+
function CallExpression(_x) {
|
|
390
|
+
return _CallExpression.apply(this, arguments);
|
|
391
|
+
}
|
|
392
|
+
CallExpression.toString = function () {
|
|
393
|
+
return _CallExpression.toString();
|
|
394
|
+
};
|
|
395
|
+
return CallExpression;
|
|
396
|
+
}(function (node) {
|
|
397
|
+
var _node$parent, _node$parent2;
|
|
384
398
|
var references = context.getScope().references;
|
|
385
399
|
|
|
386
400
|
// Rule should ignore .attrs() calls
|
|
@@ -391,8 +405,21 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
391
405
|
if (!(0, _isSupportedImport.isStyledComponents)(callee, references) && !(0, _isSupportedImport.isEmotion)(callee, references)) {
|
|
392
406
|
return;
|
|
393
407
|
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* We only want to lint the second set of arguments in the following cases:
|
|
411
|
+
*
|
|
412
|
+
* 1. styled(BaseComponent)({ ... })
|
|
413
|
+
* 2. styled(BaseComponent)``
|
|
414
|
+
*/
|
|
415
|
+
if (
|
|
416
|
+
// Using this type assertion to cast into a more useful type
|
|
417
|
+
// For some reason the estree types are missing useful things like `parent`
|
|
418
|
+
(0, _eslintCodemodUtils.isNodeOfType)(node, 'CallExpression') && (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === 'CallExpression' || ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.type) === 'TaggedTemplateExpression')) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
394
421
|
lintArguments(context, node.arguments);
|
|
395
|
-
}
|
|
422
|
+
})
|
|
396
423
|
};
|
|
397
424
|
}
|
|
398
425
|
});
|
|
@@ -54,7 +54,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
54
54
|
references = _context$getScope.references;
|
|
55
55
|
var ancestors = context.getAncestors();
|
|
56
56
|
if (ancestors.every(function (ancestor) {
|
|
57
|
-
return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !((0, _isSupportedImport.isCss)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isStyled)(ancestor.callee, references, importSources) || (0, _isSupportedImport.
|
|
57
|
+
return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !((0, _isSupportedImport.isCss)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isStyled)(ancestor.callee, references, importSources) || (0, _isSupportedImport.isXcss)(ancestor.callee, references, importSources));
|
|
58
58
|
})) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
@@ -67,7 +67,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
var tokens = cssSelector.split(/[, ]+/);
|
|
70
|
-
if (!tokens.every(function (token) {
|
|
70
|
+
if (!cssSelector.includes('@') && !tokens.every(function (token) {
|
|
71
71
|
return token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&');
|
|
72
72
|
})) {
|
|
73
73
|
context.report({
|
|
@@ -2,6 +2,7 @@ import { analyze } from 'eslint-scope';
|
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
3
|
import { isStyledComponents, isEmotion } from '@atlaskit/eslint-utils/is-supported-import';
|
|
4
4
|
import ESTraverse from 'estraverse';
|
|
5
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Represents some information about single line that contains some props, e.g.
|
|
@@ -168,7 +169,11 @@ const lintArguments = (context, args) => {
|
|
|
168
169
|
}
|
|
169
170
|
allProps.push(propNames);
|
|
170
171
|
}
|
|
171
|
-
}
|
|
172
|
+
},
|
|
173
|
+
/**
|
|
174
|
+
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
|
175
|
+
*/
|
|
176
|
+
fallback: 'iteration'
|
|
172
177
|
});
|
|
173
178
|
}
|
|
174
179
|
}
|
|
@@ -276,7 +281,8 @@ export const rule = createLintRule({
|
|
|
276
281
|
},
|
|
277
282
|
create(context) {
|
|
278
283
|
return {
|
|
279
|
-
|
|
284
|
+
CallExpression: node => {
|
|
285
|
+
var _node$parent, _node$parent2;
|
|
280
286
|
const references = context.getScope().references;
|
|
281
287
|
|
|
282
288
|
// Rule should ignore .attrs() calls
|
|
@@ -287,6 +293,19 @@ export const rule = createLintRule({
|
|
|
287
293
|
if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
|
|
288
294
|
return;
|
|
289
295
|
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* We only want to lint the second set of arguments in the following cases:
|
|
299
|
+
*
|
|
300
|
+
* 1. styled(BaseComponent)({ ... })
|
|
301
|
+
* 2. styled(BaseComponent)``
|
|
302
|
+
*/
|
|
303
|
+
if (
|
|
304
|
+
// Using this type assertion to cast into a more useful type
|
|
305
|
+
// For some reason the estree types are missing useful things like `parent`
|
|
306
|
+
isNodeOfType(node, 'CallExpression') && (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === 'CallExpression' || ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.type) === 'TaggedTemplateExpression')) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
290
309
|
lintArguments(context, node.arguments);
|
|
291
310
|
}
|
|
292
311
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isStyled, isCss,
|
|
1
|
+
import { isStyled, isCss, isXcss, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
3
|
const schema = [{
|
|
4
4
|
type: 'object',
|
|
@@ -46,7 +46,7 @@ export const rule = createLintRule({
|
|
|
46
46
|
references
|
|
47
47
|
} = context.getScope();
|
|
48
48
|
const ancestors = context.getAncestors();
|
|
49
|
-
if (ancestors.every(ancestor => ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) ||
|
|
49
|
+
if (ancestors.every(ancestor => ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) || isXcss(ancestor.callee, references, importSources)))) {
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
if (node.value.type !== 'ObjectExpression') {
|
|
@@ -58,7 +58,7 @@ export const rule = createLintRule({
|
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
60
|
const tokens = cssSelector.split(/[, ]+/);
|
|
61
|
-
if (!tokens.every(token => token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&'))) {
|
|
61
|
+
if (!cssSelector.includes('@') && !tokens.every(token => token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&'))) {
|
|
62
62
|
context.report({
|
|
63
63
|
messageId: 'no-nested-selectors',
|
|
64
64
|
node: node.key
|
|
@@ -5,6 +5,7 @@ import { analyze } from 'eslint-scope';
|
|
|
5
5
|
import { createLintRule } from '../utils/create-rule';
|
|
6
6
|
import { isStyledComponents, isEmotion } from '@atlaskit/eslint-utils/is-supported-import';
|
|
7
7
|
import ESTraverse from 'estraverse';
|
|
8
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Represents some information about single line that contains some props, e.g.
|
|
@@ -218,7 +219,11 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
218
219
|
}
|
|
219
220
|
allProps.push(propNames);
|
|
220
221
|
}
|
|
221
|
-
}
|
|
222
|
+
},
|
|
223
|
+
/**
|
|
224
|
+
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
|
225
|
+
*/
|
|
226
|
+
fallback: 'iteration'
|
|
222
227
|
});
|
|
223
228
|
}
|
|
224
229
|
}
|
|
@@ -374,7 +379,16 @@ export var rule = createLintRule({
|
|
|
374
379
|
},
|
|
375
380
|
create: function create(context) {
|
|
376
381
|
return {
|
|
377
|
-
|
|
382
|
+
CallExpression: function (_CallExpression) {
|
|
383
|
+
function CallExpression(_x) {
|
|
384
|
+
return _CallExpression.apply(this, arguments);
|
|
385
|
+
}
|
|
386
|
+
CallExpression.toString = function () {
|
|
387
|
+
return _CallExpression.toString();
|
|
388
|
+
};
|
|
389
|
+
return CallExpression;
|
|
390
|
+
}(function (node) {
|
|
391
|
+
var _node$parent, _node$parent2;
|
|
378
392
|
var references = context.getScope().references;
|
|
379
393
|
|
|
380
394
|
// Rule should ignore .attrs() calls
|
|
@@ -385,8 +399,21 @@ export var rule = createLintRule({
|
|
|
385
399
|
if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
|
|
386
400
|
return;
|
|
387
401
|
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* We only want to lint the second set of arguments in the following cases:
|
|
405
|
+
*
|
|
406
|
+
* 1. styled(BaseComponent)({ ... })
|
|
407
|
+
* 2. styled(BaseComponent)``
|
|
408
|
+
*/
|
|
409
|
+
if (
|
|
410
|
+
// Using this type assertion to cast into a more useful type
|
|
411
|
+
// For some reason the estree types are missing useful things like `parent`
|
|
412
|
+
isNodeOfType(node, 'CallExpression') && (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === 'CallExpression' || ((_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.type) === 'TaggedTemplateExpression')) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
388
415
|
lintArguments(context, node.arguments);
|
|
389
|
-
}
|
|
416
|
+
})
|
|
390
417
|
};
|
|
391
418
|
}
|
|
392
419
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isStyled, isCss,
|
|
1
|
+
import { isStyled, isCss, isXcss, getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
3
|
var schema = [{
|
|
4
4
|
type: 'object',
|
|
@@ -48,7 +48,7 @@ export var rule = createLintRule({
|
|
|
48
48
|
references = _context$getScope.references;
|
|
49
49
|
var ancestors = context.getAncestors();
|
|
50
50
|
if (ancestors.every(function (ancestor) {
|
|
51
|
-
return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) ||
|
|
51
|
+
return ancestor.type !== 'CallExpression' || !(ancestor !== null && ancestor !== void 0 && ancestor.callee) || !(isCss(ancestor.callee, references, importSources) || isStyled(ancestor.callee, references, importSources) || isXcss(ancestor.callee, references, importSources));
|
|
52
52
|
})) {
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
@@ -61,7 +61,7 @@ export var rule = createLintRule({
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
var tokens = cssSelector.split(/[, ]+/);
|
|
64
|
-
if (!tokens.every(function (token) {
|
|
64
|
+
if (!cssSelector.includes('@') && !tokens.every(function (token) {
|
|
65
65
|
return token.length === 0 || token.startsWith('&') || token.startsWith(':') || token.includes('+') || token.includes('~') || token.endsWith('&');
|
|
66
66
|
})) {
|
|
67
67
|
context.report({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@atlaskit/ds-lib": "^2.2.0",
|
|
48
|
-
"@atlaskit/eslint-plugin-design-system": "^9.
|
|
48
|
+
"@atlaskit/eslint-plugin-design-system": "^9.4.0",
|
|
49
49
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
50
50
|
"@atlassian/codegen": "*",
|
|
51
51
|
"@compiled/eslint-plugin": "^0.13.6",
|
|
@@ -107,7 +107,7 @@ typescriptEslintTester.run(
|
|
|
107
107
|
name: 'ignores styled(...).attrs() call',
|
|
108
108
|
code: `
|
|
109
109
|
import { styled } from 'styled-components';
|
|
110
|
-
|
|
110
|
+
|
|
111
111
|
const StyledMinimized = styled(Minimized).attrs({
|
|
112
112
|
className: (props) => props.transitionClass,
|
|
113
113
|
})\`
|
|
@@ -119,7 +119,7 @@ typescriptEslintTester.run(
|
|
|
119
119
|
name: 'ignores styled.div.attrs<...>() call',
|
|
120
120
|
code: `
|
|
121
121
|
import { styled } from '@compiled/react';
|
|
122
|
-
|
|
122
|
+
|
|
123
123
|
export const ModalAnchorOld = styled.div.attrs<ModalAnchorProps>({
|
|
124
124
|
style: ({ left, top }: ModalAnchorProps) => ({
|
|
125
125
|
left,
|
|
@@ -155,6 +155,46 @@ typescriptEslintTester.run(
|
|
|
155
155
|
\`;
|
|
156
156
|
`,
|
|
157
157
|
},
|
|
158
|
+
{
|
|
159
|
+
name: 'ignores options passed to base components',
|
|
160
|
+
code: `
|
|
161
|
+
import styled from '@emotion/styled';
|
|
162
|
+
import { token } from 'some-package';
|
|
163
|
+
import { someFallback } from 'other-package';
|
|
164
|
+
|
|
165
|
+
styled(BaseComponent, {
|
|
166
|
+
// This should not get flagged
|
|
167
|
+
shouldForwardProp: prop => prop !== 'seen'
|
|
168
|
+
})({
|
|
169
|
+
color: token('some-token', someFallback),
|
|
170
|
+
});
|
|
171
|
+
`,
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'ignores options passed to base components when using template string',
|
|
175
|
+
code: `
|
|
176
|
+
import styled from '@emotion/styled';
|
|
177
|
+
import { token } from 'some-package';
|
|
178
|
+
import { someFallback } from 'other-package';
|
|
179
|
+
|
|
180
|
+
styled(Link, {
|
|
181
|
+
// This should not get flagged
|
|
182
|
+
shouldForwardProp: prop => prop !== 'seen',
|
|
183
|
+
})<{ seen?: boolean }>\`
|
|
184
|
+
cursor: pointer;
|
|
185
|
+
\`;
|
|
186
|
+
`,
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'No error on TSAsExpression node type when using ESTraverse',
|
|
190
|
+
code: `
|
|
191
|
+
import styled from '@emotion/styled';
|
|
192
|
+
|
|
193
|
+
const Component = styled.div({
|
|
194
|
+
color: token('color.text') as string,
|
|
195
|
+
});
|
|
196
|
+
`,
|
|
197
|
+
},
|
|
158
198
|
],
|
|
159
199
|
invalid: [
|
|
160
200
|
{
|
|
@@ -499,6 +539,46 @@ typescriptEslintTester.run(
|
|
|
499
539
|
`,
|
|
500
540
|
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
501
541
|
},
|
|
542
|
+
{
|
|
543
|
+
name: 'converts styled-components props argument when extending existing component',
|
|
544
|
+
code: `
|
|
545
|
+
import styled from 'styled-components';
|
|
546
|
+
|
|
547
|
+
styled(BaseComponent)({
|
|
548
|
+
color: (props) => props.color,
|
|
549
|
+
backgroundColor: (props) => props.backgroundColor,
|
|
550
|
+
});
|
|
551
|
+
`,
|
|
552
|
+
output: `
|
|
553
|
+
import styled from 'styled-components';
|
|
554
|
+
|
|
555
|
+
styled(BaseComponent)((props) => ({
|
|
556
|
+
color: props.color,
|
|
557
|
+
backgroundColor: props.backgroundColor,
|
|
558
|
+
}));
|
|
559
|
+
`,
|
|
560
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
name: 'converts styled-components props argument when using css function',
|
|
564
|
+
code: `
|
|
565
|
+
import { css } from 'styled-components';
|
|
566
|
+
|
|
567
|
+
css({
|
|
568
|
+
color: (props) => props.color,
|
|
569
|
+
backgroundColor: (props) => props.backgroundColor,
|
|
570
|
+
});
|
|
571
|
+
`,
|
|
572
|
+
output: `
|
|
573
|
+
import { css } from 'styled-components';
|
|
574
|
+
|
|
575
|
+
css((props) => ({
|
|
576
|
+
color: props.color,
|
|
577
|
+
backgroundColor: props.backgroundColor,
|
|
578
|
+
}));
|
|
579
|
+
`,
|
|
580
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
581
|
+
},
|
|
502
582
|
],
|
|
503
583
|
},
|
|
504
584
|
);
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
15
15
|
import type { Rule, Scope, SourceCode } from 'eslint';
|
|
16
16
|
import ESTraverse from 'estraverse';
|
|
17
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
17
18
|
|
|
18
19
|
type PropInfo = {
|
|
19
20
|
/**
|
|
@@ -227,6 +228,10 @@ const lintArguments = (
|
|
|
227
228
|
allProps.push(propNames);
|
|
228
229
|
}
|
|
229
230
|
},
|
|
231
|
+
/**
|
|
232
|
+
* This is needed to handle unknown node types. Otherwise an error is thrown.
|
|
233
|
+
*/
|
|
234
|
+
fallback: 'iteration',
|
|
230
235
|
});
|
|
231
236
|
}
|
|
232
237
|
}
|
|
@@ -390,9 +395,7 @@ export const rule = createLintRule({
|
|
|
390
395
|
},
|
|
391
396
|
create(context) {
|
|
392
397
|
return {
|
|
393
|
-
|
|
394
|
-
node: CallExpression,
|
|
395
|
-
) => {
|
|
398
|
+
CallExpression: (node: CallExpression) => {
|
|
396
399
|
const references = context.getScope().references;
|
|
397
400
|
|
|
398
401
|
// Rule should ignore .attrs() calls
|
|
@@ -416,6 +419,22 @@ export const rule = createLintRule({
|
|
|
416
419
|
return;
|
|
417
420
|
}
|
|
418
421
|
|
|
422
|
+
/**
|
|
423
|
+
* We only want to lint the second set of arguments in the following cases:
|
|
424
|
+
*
|
|
425
|
+
* 1. styled(BaseComponent)({ ... })
|
|
426
|
+
* 2. styled(BaseComponent)``
|
|
427
|
+
*/
|
|
428
|
+
if (
|
|
429
|
+
// Using this type assertion to cast into a more useful type
|
|
430
|
+
// For some reason the estree types are missing useful things like `parent`
|
|
431
|
+
isNodeOfType(node, 'CallExpression') &&
|
|
432
|
+
(node.parent?.type === 'CallExpression' ||
|
|
433
|
+
node.parent?.type === 'TaggedTemplateExpression')
|
|
434
|
+
) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
419
438
|
lintArguments(context, node.arguments);
|
|
420
439
|
},
|
|
421
440
|
};
|
|
@@ -94,6 +94,55 @@ typescriptEslintTester.run(
|
|
|
94
94
|
});
|
|
95
95
|
`,
|
|
96
96
|
},
|
|
97
|
+
{
|
|
98
|
+
name: 'Skips @ queries',
|
|
99
|
+
code: `
|
|
100
|
+
import { css } from '@compiled/react';
|
|
101
|
+
const styles = css({
|
|
102
|
+
'@container (width > 400px)': {
|
|
103
|
+
fontSize: '1.5rem',
|
|
104
|
+
},
|
|
105
|
+
'@media (max-width: 1200px)': {
|
|
106
|
+
gridTemplateColumns: 'repeat(1, 1fr)',
|
|
107
|
+
justifyItems: 'center',
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
`,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'Skip cssMap call',
|
|
114
|
+
code: `
|
|
115
|
+
import { cssMap } from '@atlaskit/css';
|
|
116
|
+
|
|
117
|
+
const styles = cssMap({
|
|
118
|
+
success: {
|
|
119
|
+
color: 'var(--ds-text-inverse)',
|
|
120
|
+
backgroundColor: 'var(--ds-background-success-bold)',
|
|
121
|
+
'&:hover': {
|
|
122
|
+
backgroundColor: 'var(--ds-background-success-bold-hovered)',
|
|
123
|
+
},
|
|
124
|
+
'&:active': {
|
|
125
|
+
backgroundColor: 'var(--ds-background-success-bold-pressed)',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
`,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: 'Skip keyframes call',
|
|
133
|
+
code: `
|
|
134
|
+
import { keyframes } from '@emotion/react';
|
|
135
|
+
|
|
136
|
+
const keyFrameStyles = keyframes({
|
|
137
|
+
'from, to': {
|
|
138
|
+
opacity: 0,
|
|
139
|
+
},
|
|
140
|
+
'50%': {
|
|
141
|
+
opacity: 1,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
`,
|
|
145
|
+
},
|
|
97
146
|
],
|
|
98
147
|
invalid: [
|
|
99
148
|
{
|
|
@@ -3,8 +3,6 @@ import type { Property } from 'estree';
|
|
|
3
3
|
import {
|
|
4
4
|
isStyled,
|
|
5
5
|
isCss,
|
|
6
|
-
isKeyframes,
|
|
7
|
-
isCssMap,
|
|
8
6
|
isXcss,
|
|
9
7
|
getImportSources,
|
|
10
8
|
} from '@atlaskit/eslint-utils/is-supported-import';
|
|
@@ -70,8 +68,6 @@ export const rule = createLintRule({
|
|
|
70
68
|
!(
|
|
71
69
|
isCss(ancestor.callee, references, importSources) ||
|
|
72
70
|
isStyled(ancestor.callee, references, importSources) ||
|
|
73
|
-
isKeyframes(ancestor.callee, references, importSources) ||
|
|
74
|
-
isCssMap(ancestor.callee, references, importSources) ||
|
|
75
71
|
isXcss(ancestor.callee, references, importSources)
|
|
76
72
|
),
|
|
77
73
|
)
|
|
@@ -92,6 +88,7 @@ export const rule = createLintRule({
|
|
|
92
88
|
const tokens = cssSelector.split(/[, ]+/);
|
|
93
89
|
|
|
94
90
|
if (
|
|
91
|
+
!cssSelector.includes('@') &&
|
|
95
92
|
!tokens.every(
|
|
96
93
|
(token) =>
|
|
97
94
|
token.length === 0 ||
|