@atlaskit/eslint-plugin-ui-styling-standard 0.6.1 → 0.6.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/constellation/convert-props-syntax/usage.mdx +5 -5
- package/dist/cjs/rules/convert-props-syntax/index.js +6 -8
- package/dist/cjs/rules/utils/is-supported-import.js +5 -2
- package/dist/es2019/rules/convert-props-syntax/index.js +7 -8
- package/dist/es2019/rules/utils/is-supported-import.js +7 -2
- package/dist/esm/rules/convert-props-syntax/index.js +7 -8
- package/dist/esm/rules/utils/is-supported-import.js +5 -2
- package/dist/types/rules/utils/create-rule.d.ts +1 -1
- package/dist/types/rules/utils/is-supported-import.d.ts +4 -4
- package/dist/types-ts4.5/rules/utils/create-rule.d.ts +1 -1
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +4 -4
- package/package.json +3 -3
- package/src/rules/convert-props-syntax/README.md +5 -5
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +4 -4
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +44 -14
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +5 -5
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +3 -3
- package/src/rules/convert-props-syntax/index.tsx +12 -14
- package/src/rules/utils/is-supported-import.tsx +13 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#83463](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83463) [`fee29cf1335a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/fee29cf1335a) - Extend convert-props-syntax to Emotion as well as it has a type issue.
|
|
8
|
+
|
|
9
|
+
## 0.6.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#83116](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/83116) [`8d4e99057fe0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8d4e99057fe0) - Upgrade Typescript from `4.9.5` to `5.4.2`
|
|
14
|
+
|
|
3
15
|
## 0.6.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# convert-props-syntax
|
|
2
2
|
|
|
3
|
-
Convert props syntax that
|
|
3
|
+
Convert props syntax that are unsupported by `styled-components@<4` and `@emotion/styled` to a 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 that results in a type error.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
These libraries do not support having an arrow function inside a CSS value:
|
|
6
6
|
|
|
7
7
|
```js
|
|
8
8
|
styled.div({
|
|
@@ -20,7 +20,7 @@ styled.div((props) => ({
|
|
|
20
20
|
}));
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
This ESLint rule will only run on usages of the `styled` API when imported from
|
|
23
|
+
This ESLint rule will only run on usages of the `styled` API when imported from libraries that are known to have this problem.
|
|
24
24
|
|
|
25
25
|
## About the autofixer
|
|
26
26
|
|
|
@@ -98,7 +98,7 @@ styled.div({
|
|
|
98
98
|
### Correct
|
|
99
99
|
|
|
100
100
|
```js
|
|
101
|
-
import styled from 'styled
|
|
101
|
+
import styled from '@emotion/styled';
|
|
102
102
|
|
|
103
103
|
styled.div((props) => ({
|
|
104
104
|
color: props.myColor,
|
|
@@ -112,4 +112,4 @@ styled.div((props) => ({
|
|
|
112
112
|
|
|
113
113
|
## When not to use it
|
|
114
114
|
|
|
115
|
-
You do not need this rule if you are not using a codebase that has
|
|
115
|
+
You do not need this rule if you are not using a codebase that has a violating library as it will never do anything.
|
|
@@ -12,8 +12,6 @@ var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
|
12
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
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
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
15
|
/**
|
|
18
16
|
* Represents some information about single line that contains some props, e.g.
|
|
19
17
|
* the arrow function in
|
|
@@ -243,7 +241,7 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
243
241
|
})) {
|
|
244
242
|
context.report({
|
|
245
243
|
node: argument,
|
|
246
|
-
messageId: 'unsupported-
|
|
244
|
+
messageId: 'unsupported-prop-syntax-no-autofixer'
|
|
247
245
|
});
|
|
248
246
|
return {
|
|
249
247
|
v: void 0
|
|
@@ -251,7 +249,7 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
251
249
|
}
|
|
252
250
|
context.report({
|
|
253
251
|
node: argument,
|
|
254
|
-
messageId: 'unsupported-
|
|
252
|
+
messageId: 'unsupported-prop-syntax',
|
|
255
253
|
fix: function fix(fixer) {
|
|
256
254
|
var sourceCode = context.getSourceCode();
|
|
257
255
|
return fixPropsObjectUsages(fixer, sourceCode, argument,
|
|
@@ -369,14 +367,14 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
369
367
|
meta: {
|
|
370
368
|
name: 'convert-props-syntax',
|
|
371
369
|
docs: {
|
|
372
|
-
description: 'Convert props syntax that is unsupported by
|
|
370
|
+
description: 'Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled 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 those libraries.',
|
|
373
371
|
recommended: true,
|
|
374
372
|
severity: 'error'
|
|
375
373
|
},
|
|
376
374
|
fixable: 'code',
|
|
377
375
|
messages: {
|
|
378
|
-
'unsupported-
|
|
379
|
-
'unsupported-
|
|
376
|
+
'unsupported-prop-syntax': 'This syntax is not supported by styled-components@<4 or @emotion/styled 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.',
|
|
377
|
+
'unsupported-prop-syntax-no-autofixer': 'This syntax is not supported by styled-components@<4 or @emotion/styled 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
378
|
},
|
|
381
379
|
type: 'problem'
|
|
382
380
|
},
|
|
@@ -385,7 +383,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
385
383
|
'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
|
|
386
384
|
var references = context.getScope().references;
|
|
387
385
|
var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
|
|
388
|
-
if (!(0, _isSupportedImport.isStyledComponents)(callee, references,
|
|
386
|
+
if (!(0, _isSupportedImport.isStyledComponents)(callee, references) && !(0, _isSupportedImport.isEmotion)(callee, references)) {
|
|
389
387
|
return;
|
|
390
388
|
}
|
|
391
389
|
lintArguments(context, node.arguments);
|
|
@@ -128,8 +128,11 @@ var isStyled = exports.isStyled = isSupportedImportWrapper('styled', ['styled-co
|
|
|
128
128
|
var isXcss = exports.isXcss = isSupportedImportWrapper('xcss');
|
|
129
129
|
var isImportedFrom = exports.isImportedFrom = function isImportedFrom(moduleName) {
|
|
130
130
|
var exactMatch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
131
|
-
return function (nodeToCheck, referencesInScope
|
|
132
|
-
|
|
131
|
+
return function (nodeToCheck, referencesInScope) {
|
|
132
|
+
var importSources = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
133
|
+
if (importSources && !importSources.some(function (importSource) {
|
|
134
|
+
return importSource === moduleName || !exactMatch && importSource.startsWith(moduleName);
|
|
135
|
+
})) {
|
|
133
136
|
// Don't go through the trouble of checking the import sources does not include this
|
|
134
137
|
// We'll assume this is skipped elsewhere.
|
|
135
138
|
return false;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { analyze } from 'eslint-scope';
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
|
-
import {
|
|
3
|
+
import { isStyledComponents, isEmotion } from '../utils/is-supported-import';
|
|
4
4
|
import ESTraverse from 'estraverse';
|
|
5
|
-
const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.styledComponents];
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Represents some information about single line that contains some props, e.g.
|
|
@@ -179,13 +178,13 @@ const lintArguments = (context, args) => {
|
|
|
179
178
|
if (allProps.some(propUsage => !propUsage.valid)) {
|
|
180
179
|
context.report({
|
|
181
180
|
node: argument,
|
|
182
|
-
messageId: 'unsupported-
|
|
181
|
+
messageId: 'unsupported-prop-syntax-no-autofixer'
|
|
183
182
|
});
|
|
184
183
|
return;
|
|
185
184
|
}
|
|
186
185
|
context.report({
|
|
187
186
|
node: argument,
|
|
188
|
-
messageId: 'unsupported-
|
|
187
|
+
messageId: 'unsupported-prop-syntax',
|
|
189
188
|
fix(fixer) {
|
|
190
189
|
const sourceCode = context.getSourceCode();
|
|
191
190
|
return fixPropsObjectUsages(fixer, sourceCode, argument,
|
|
@@ -264,14 +263,14 @@ export const rule = createLintRule({
|
|
|
264
263
|
meta: {
|
|
265
264
|
name: 'convert-props-syntax',
|
|
266
265
|
docs: {
|
|
267
|
-
description: 'Convert props syntax that is unsupported by
|
|
266
|
+
description: 'Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled 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 those libraries.',
|
|
268
267
|
recommended: true,
|
|
269
268
|
severity: 'error'
|
|
270
269
|
},
|
|
271
270
|
fixable: 'code',
|
|
272
271
|
messages: {
|
|
273
|
-
'unsupported-
|
|
274
|
-
'unsupported-
|
|
272
|
+
'unsupported-prop-syntax': 'This syntax is not supported by styled-components@<4 or @emotion/styled 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.',
|
|
273
|
+
'unsupported-prop-syntax-no-autofixer': 'This syntax is not supported by styled-components@<4 or @emotion/styled 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.'
|
|
275
274
|
},
|
|
276
275
|
type: 'problem'
|
|
277
276
|
},
|
|
@@ -280,7 +279,7 @@ export const rule = createLintRule({
|
|
|
280
279
|
'CallExpression[callee.type="MemberExpression"]': node => {
|
|
281
280
|
const references = context.getScope().references;
|
|
282
281
|
const callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
|
|
283
|
-
if (!isStyledComponents(callee, references,
|
|
282
|
+
if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
|
|
284
283
|
return;
|
|
285
284
|
}
|
|
286
285
|
lintArguments(context, node.arguments);
|
|
@@ -117,8 +117,13 @@ export const isKeyframes = isSupportedImportWrapper('keyframes');
|
|
|
117
117
|
// `styled` is also the explicit default of `styled-components` and `@emotion/styled`, so we also match on default imports generally
|
|
118
118
|
export const isStyled = isSupportedImportWrapper('styled', ['styled-components', '@emotion/styled']);
|
|
119
119
|
export const isXcss = isSupportedImportWrapper('xcss');
|
|
120
|
-
export const isImportedFrom = (moduleName, exactMatch = true) => (nodeToCheck, referencesInScope,
|
|
121
|
-
|
|
120
|
+
export const isImportedFrom = (moduleName, exactMatch = true) => (nodeToCheck, referencesInScope,
|
|
121
|
+
/**
|
|
122
|
+
* If we strictly have specific import sources in the config scope, pass them to make this more performant.
|
|
123
|
+
* Pass `null` if you don't care if its configured or not.
|
|
124
|
+
*/
|
|
125
|
+
importSources = null) => {
|
|
126
|
+
if (importSources && !importSources.some(importSource => importSource === moduleName || !exactMatch && importSource.startsWith(moduleName))) {
|
|
122
127
|
// Don't go through the trouble of checking the import sources does not include this
|
|
123
128
|
// We'll assume this is skipped elsewhere.
|
|
124
129
|
return false;
|
|
@@ -3,9 +3,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
3
3
|
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; }
|
|
4
4
|
import { analyze } from 'eslint-scope';
|
|
5
5
|
import { createLintRule } from '../utils/create-rule';
|
|
6
|
-
import {
|
|
6
|
+
import { isStyledComponents, isEmotion } from '../utils/is-supported-import';
|
|
7
7
|
import ESTraverse from 'estraverse';
|
|
8
|
-
var IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.styledComponents];
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
10
|
* Represents some information about single line that contains some props, e.g.
|
|
@@ -236,7 +235,7 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
236
235
|
})) {
|
|
237
236
|
context.report({
|
|
238
237
|
node: argument,
|
|
239
|
-
messageId: 'unsupported-
|
|
238
|
+
messageId: 'unsupported-prop-syntax-no-autofixer'
|
|
240
239
|
});
|
|
241
240
|
return {
|
|
242
241
|
v: void 0
|
|
@@ -244,7 +243,7 @@ var lintArguments = function lintArguments(context, args) {
|
|
|
244
243
|
}
|
|
245
244
|
context.report({
|
|
246
245
|
node: argument,
|
|
247
|
-
messageId: 'unsupported-
|
|
246
|
+
messageId: 'unsupported-prop-syntax',
|
|
248
247
|
fix: function fix(fixer) {
|
|
249
248
|
var sourceCode = context.getSourceCode();
|
|
250
249
|
return fixPropsObjectUsages(fixer, sourceCode, argument,
|
|
@@ -362,14 +361,14 @@ export var rule = createLintRule({
|
|
|
362
361
|
meta: {
|
|
363
362
|
name: 'convert-props-syntax',
|
|
364
363
|
docs: {
|
|
365
|
-
description: 'Convert props syntax that is unsupported by
|
|
364
|
+
description: 'Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled 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 those libraries.',
|
|
366
365
|
recommended: true,
|
|
367
366
|
severity: 'error'
|
|
368
367
|
},
|
|
369
368
|
fixable: 'code',
|
|
370
369
|
messages: {
|
|
371
|
-
'unsupported-
|
|
372
|
-
'unsupported-
|
|
370
|
+
'unsupported-prop-syntax': 'This syntax is not supported by styled-components@<4 or @emotion/styled 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.',
|
|
371
|
+
'unsupported-prop-syntax-no-autofixer': 'This syntax is not supported by styled-components@<4 or @emotion/styled 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.'
|
|
373
372
|
},
|
|
374
373
|
type: 'problem'
|
|
375
374
|
},
|
|
@@ -378,7 +377,7 @@ export var rule = createLintRule({
|
|
|
378
377
|
'CallExpression[callee.type="MemberExpression"]': function CallExpressionCalleeTypeMemberExpression(node) {
|
|
379
378
|
var references = context.getScope().references;
|
|
380
379
|
var callee = node.callee.type === 'MemberExpression' ? node.callee.object : node.callee;
|
|
381
|
-
if (!isStyledComponents(callee, references,
|
|
380
|
+
if (!isStyledComponents(callee, references) && !isEmotion(callee, references)) {
|
|
382
381
|
return;
|
|
383
382
|
}
|
|
384
383
|
lintArguments(context, node.arguments);
|
|
@@ -122,8 +122,11 @@ export var isStyled = isSupportedImportWrapper('styled', ['styled-components', '
|
|
|
122
122
|
export var isXcss = isSupportedImportWrapper('xcss');
|
|
123
123
|
export var isImportedFrom = function isImportedFrom(moduleName) {
|
|
124
124
|
var exactMatch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
125
|
-
return function (nodeToCheck, referencesInScope
|
|
126
|
-
|
|
125
|
+
return function (nodeToCheck, referencesInScope) {
|
|
126
|
+
var importSources = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
127
|
+
if (importSources && !importSources.some(function (importSource) {
|
|
128
|
+
return importSource === moduleName || !exactMatch && importSource.startsWith(moduleName);
|
|
129
|
+
})) {
|
|
127
130
|
// Don't go through the trouble of checking the import sources does not include this
|
|
128
131
|
// We'll assume this is skipped elsewhere.
|
|
129
132
|
return false;
|
|
@@ -9,7 +9,7 @@ import type { Rule } from 'eslint';
|
|
|
9
9
|
* @private
|
|
10
10
|
* @deprecated
|
|
11
11
|
*/
|
|
12
|
-
export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint
|
|
12
|
+
export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<TMessageIds, TOptions, TRuleListener>;
|
|
13
13
|
export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
|
|
14
14
|
/**
|
|
15
15
|
* Including this for backwards compat moving from the typescript-eslint util.
|
|
@@ -32,7 +32,7 @@ export declare const isCssMap: SupportedNameChecker;
|
|
|
32
32
|
export declare const isKeyframes: SupportedNameChecker;
|
|
33
33
|
export declare const isStyled: SupportedNameChecker;
|
|
34
34
|
export declare const isXcss: SupportedNameChecker;
|
|
35
|
-
export declare const isImportedFrom: (moduleName: string, exactMatch?: boolean) => (nodeToCheck: Callee, referencesInScope: Reference[], importSources
|
|
35
|
+
export declare const isImportedFrom: (moduleName: string, exactMatch?: boolean) => (nodeToCheck: Callee, referencesInScope: Reference[], importSources?: ImportSource[] | null) => boolean;
|
|
36
36
|
/**
|
|
37
37
|
* Determine if this node is specifically from a `'styled-components'` import.
|
|
38
38
|
* This is because `styled-components@3.4` APIs are not consistent with Emotion and Compiled,
|
|
@@ -40,7 +40,7 @@ export declare const isImportedFrom: (moduleName: string, exactMatch?: boolean)
|
|
|
40
40
|
*
|
|
41
41
|
* This can be cleaned up when `'styled-components'` is no longer a valid ImportSource.
|
|
42
42
|
*/
|
|
43
|
-
export declare const isStyledComponents: (nodeToCheck: Callee, referencesInScope: Reference[], importSources
|
|
44
|
-
export declare const isCompiled: (nodeToCheck: Callee, referencesInScope: Reference[], importSources
|
|
45
|
-
export declare const isEmotion: (nodeToCheck: Callee, referencesInScope: Reference[], importSources
|
|
43
|
+
export declare const isStyledComponents: (nodeToCheck: Callee, referencesInScope: Reference[], importSources?: ImportSource[] | null) => boolean;
|
|
44
|
+
export declare const isCompiled: (nodeToCheck: Callee, referencesInScope: Reference[], importSources?: ImportSource[] | null) => boolean;
|
|
45
|
+
export declare const isEmotion: (nodeToCheck: Callee, referencesInScope: Reference[], importSources?: ImportSource[] | null) => boolean;
|
|
46
46
|
export {};
|
|
@@ -9,7 +9,7 @@ import type { Rule } from 'eslint';
|
|
|
9
9
|
* @private
|
|
10
10
|
* @deprecated
|
|
11
11
|
*/
|
|
12
|
-
export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint
|
|
12
|
+
export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import("@typescript-eslint/utils/dist/ts-eslint").RuleListener = import("@typescript-eslint/utils/dist/ts-eslint").RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import("@typescript-eslint/utils/dist/ts-eslint").RuleModule<TMessageIds, TOptions, TRuleListener>;
|
|
13
13
|
export interface LintRule extends Omit<Rule.RuleModule, 'meta'> {
|
|
14
14
|
/**
|
|
15
15
|
* Including this for backwards compat moving from the typescript-eslint util.
|
|
@@ -32,7 +32,7 @@ export declare const isCssMap: SupportedNameChecker;
|
|
|
32
32
|
export declare const isKeyframes: SupportedNameChecker;
|
|
33
33
|
export declare const isStyled: SupportedNameChecker;
|
|
34
34
|
export declare const isXcss: SupportedNameChecker;
|
|
35
|
-
export declare const isImportedFrom: (moduleName: string, exactMatch?: boolean) => (nodeToCheck: Callee, referencesInScope: Reference[], importSources
|
|
35
|
+
export declare const isImportedFrom: (moduleName: string, exactMatch?: boolean) => (nodeToCheck: Callee, referencesInScope: Reference[], importSources?: ImportSource[] | null) => boolean;
|
|
36
36
|
/**
|
|
37
37
|
* Determine if this node is specifically from a `'styled-components'` import.
|
|
38
38
|
* This is because `styled-components@3.4` APIs are not consistent with Emotion and Compiled,
|
|
@@ -40,7 +40,7 @@ export declare const isImportedFrom: (moduleName: string, exactMatch?: boolean)
|
|
|
40
40
|
*
|
|
41
41
|
* This can be cleaned up when `'styled-components'` is no longer a valid ImportSource.
|
|
42
42
|
*/
|
|
43
|
-
export declare const isStyledComponents: (nodeToCheck: Callee, referencesInScope: Reference[], importSources
|
|
44
|
-
export declare const isCompiled: (nodeToCheck: Callee, referencesInScope: Reference[], importSources
|
|
45
|
-
export declare const isEmotion: (nodeToCheck: Callee, referencesInScope: Reference[], importSources
|
|
43
|
+
export declare const isStyledComponents: (nodeToCheck: Callee, referencesInScope: Reference[], importSources?: ImportSource[] | null) => boolean;
|
|
44
|
+
export declare const isCompiled: (nodeToCheck: Callee, referencesInScope: Reference[], importSources?: ImportSource[] | null) => boolean;
|
|
45
|
+
export declare const isEmotion: (nodeToCheck: Callee, referencesInScope: Reference[], importSources?: ImportSource[] | null) => boolean;
|
|
46
46
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.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",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@atlaskit/ds-lib": "^2.2.0",
|
|
47
|
-
"@atlaskit/eslint-plugin-design-system": "^8.
|
|
47
|
+
"@atlaskit/eslint-plugin-design-system": "^8.38.0",
|
|
48
48
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
49
49
|
"@atlassian/codegen": "*",
|
|
50
50
|
"@compiled/eslint-plugin": "^0.13.6",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"prettier": "^2.8.0",
|
|
57
57
|
"ts-node": "^10.9.1",
|
|
58
58
|
"tsconfig-paths": "^4.2.0",
|
|
59
|
-
"typescript": "~4.
|
|
59
|
+
"typescript": "~5.4.2"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"codegen": "ts-node -r tsconfig-paths/register ./scripts/codegen.tsx"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Convert props syntax that
|
|
1
|
+
Convert props syntax that are unsupported by `styled-components@<4` and `@emotion/styled` to a 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 that results in a type error.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
These libraries do not support having an arrow function inside a CSS value:
|
|
4
4
|
|
|
5
5
|
```js
|
|
6
6
|
styled.div({
|
|
@@ -18,7 +18,7 @@ styled.div((props) => ({
|
|
|
18
18
|
}));
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
This ESLint rule will only run on usages of the `styled` API when imported from
|
|
21
|
+
This ESLint rule will only run on usages of the `styled` API when imported from libraries that are known to have this problem.
|
|
22
22
|
|
|
23
23
|
## About the autofixer
|
|
24
24
|
|
|
@@ -96,7 +96,7 @@ styled.div({
|
|
|
96
96
|
### Correct
|
|
97
97
|
|
|
98
98
|
```js
|
|
99
|
-
import styled from 'styled
|
|
99
|
+
import styled from '@emotion/styled';
|
|
100
100
|
|
|
101
101
|
styled.div((props) => ({
|
|
102
102
|
color: props.myColor,
|
|
@@ -110,4 +110,4 @@ styled.div((props) => ({
|
|
|
110
110
|
|
|
111
111
|
## When not to use it
|
|
112
112
|
|
|
113
|
-
You do not need this rule if you are not using a codebase that has
|
|
113
|
+
You do not need this rule if you are not using a codebase that has a violating library as it will never do anything.
|
|
@@ -22,7 +22,7 @@ typescriptEslintTester.run(
|
|
|
22
22
|
`,
|
|
23
23
|
errors: [
|
|
24
24
|
{
|
|
25
|
-
messageId: 'unsupported-
|
|
25
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
26
26
|
},
|
|
27
27
|
],
|
|
28
28
|
},
|
|
@@ -37,7 +37,7 @@ typescriptEslintTester.run(
|
|
|
37
37
|
`,
|
|
38
38
|
errors: [
|
|
39
39
|
{
|
|
40
|
-
messageId: 'unsupported-
|
|
40
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
},
|
|
@@ -52,7 +52,7 @@ typescriptEslintTester.run(
|
|
|
52
52
|
`,
|
|
53
53
|
errors: [
|
|
54
54
|
{
|
|
55
|
-
messageId: 'unsupported-
|
|
55
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
56
56
|
},
|
|
57
57
|
],
|
|
58
58
|
},
|
|
@@ -67,7 +67,7 @@ typescriptEslintTester.run(
|
|
|
67
67
|
`,
|
|
68
68
|
errors: [
|
|
69
69
|
{
|
|
70
|
-
messageId: 'unsupported-
|
|
70
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
71
71
|
},
|
|
72
72
|
],
|
|
73
73
|
},
|
|
@@ -17,6 +17,16 @@ typescriptEslintTester.run(
|
|
|
17
17
|
}));
|
|
18
18
|
`,
|
|
19
19
|
},
|
|
20
|
+
{
|
|
21
|
+
name: 'ignores @emotion/styled usages using supported props syntax',
|
|
22
|
+
code: `
|
|
23
|
+
import styled from '@emotion/styled';
|
|
24
|
+
|
|
25
|
+
styled.div((props) => ({
|
|
26
|
+
color: props.color,
|
|
27
|
+
}));
|
|
28
|
+
`,
|
|
29
|
+
},
|
|
20
30
|
{
|
|
21
31
|
name: 'ignores styled-components usages already using supported props syntax (with logical operator)',
|
|
22
32
|
code: `
|
|
@@ -95,6 +105,26 @@ typescriptEslintTester.run(
|
|
|
95
105
|
},
|
|
96
106
|
],
|
|
97
107
|
invalid: [
|
|
108
|
+
{
|
|
109
|
+
name: 'converts @emotion/styled props argument',
|
|
110
|
+
code: `
|
|
111
|
+
import styled from '@emotion/styled';
|
|
112
|
+
|
|
113
|
+
styled.div({
|
|
114
|
+
color: (props) => props.color,
|
|
115
|
+
backgroundColor: (props) => props.backgroundColor,
|
|
116
|
+
});
|
|
117
|
+
`,
|
|
118
|
+
output: `
|
|
119
|
+
import styled from '@emotion/styled';
|
|
120
|
+
|
|
121
|
+
styled.div((props) => ({
|
|
122
|
+
color: props.color,
|
|
123
|
+
backgroundColor: props.backgroundColor,
|
|
124
|
+
}));
|
|
125
|
+
`,
|
|
126
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
127
|
+
},
|
|
98
128
|
{
|
|
99
129
|
name: 'converts styled-components props argument',
|
|
100
130
|
code: `
|
|
@@ -113,7 +143,7 @@ typescriptEslintTester.run(
|
|
|
113
143
|
backgroundColor: props.backgroundColor,
|
|
114
144
|
}));
|
|
115
145
|
`,
|
|
116
|
-
errors: [{ messageId: 'unsupported-
|
|
146
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
117
147
|
},
|
|
118
148
|
{
|
|
119
149
|
name: 'converts styled-components destructured props',
|
|
@@ -133,7 +163,7 @@ typescriptEslintTester.run(
|
|
|
133
163
|
backgroundColor: props.backgroundColor,
|
|
134
164
|
}));
|
|
135
165
|
`,
|
|
136
|
-
errors: [{ messageId: 'unsupported-
|
|
166
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
137
167
|
},
|
|
138
168
|
{
|
|
139
169
|
name: 'converts mixture of props argument and destructured props',
|
|
@@ -153,7 +183,7 @@ typescriptEslintTester.run(
|
|
|
153
183
|
backgroundColor: props.backgroundColor,
|
|
154
184
|
}));
|
|
155
185
|
`,
|
|
156
|
-
errors: [{ messageId: 'unsupported-
|
|
186
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
157
187
|
},
|
|
158
188
|
{
|
|
159
189
|
name: 'converts mix of valid props syntax and invalid props syntax',
|
|
@@ -183,7 +213,7 @@ typescriptEslintTester.run(
|
|
|
183
213
|
})
|
|
184
214
|
);
|
|
185
215
|
`,
|
|
186
|
-
errors: [{ messageId: 'unsupported-
|
|
216
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
187
217
|
},
|
|
188
218
|
{
|
|
189
219
|
name: 'converts mix of renamed props argument and destructured props',
|
|
@@ -205,7 +235,7 @@ typescriptEslintTester.run(
|
|
|
205
235
|
height: props.customHeight,
|
|
206
236
|
}));
|
|
207
237
|
`,
|
|
208
|
-
errors: [{ messageId: 'unsupported-
|
|
238
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
209
239
|
},
|
|
210
240
|
{
|
|
211
241
|
name: 'converts props with same name',
|
|
@@ -227,7 +257,7 @@ typescriptEslintTester.run(
|
|
|
227
257
|
height: props.customHeight,
|
|
228
258
|
}));
|
|
229
259
|
`,
|
|
230
|
-
errors: [{ messageId: 'unsupported-
|
|
260
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
231
261
|
},
|
|
232
262
|
{
|
|
233
263
|
name: 'converts props with same name (variant two)',
|
|
@@ -249,7 +279,7 @@ typescriptEslintTester.run(
|
|
|
249
279
|
height: props.customHeight,
|
|
250
280
|
}));
|
|
251
281
|
`,
|
|
252
|
-
errors: [{ messageId: 'unsupported-
|
|
282
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
253
283
|
},
|
|
254
284
|
{
|
|
255
285
|
name: 'converts props with same name (variant three)',
|
|
@@ -271,7 +301,7 @@ typescriptEslintTester.run(
|
|
|
271
301
|
height: props.customHeight,
|
|
272
302
|
}));
|
|
273
303
|
`,
|
|
274
|
-
errors: [{ messageId: 'unsupported-
|
|
304
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
275
305
|
},
|
|
276
306
|
{
|
|
277
307
|
name: 'converts props inside template literal',
|
|
@@ -291,7 +321,7 @@ typescriptEslintTester.run(
|
|
|
291
321
|
backgroundSize: 'cover',
|
|
292
322
|
}));
|
|
293
323
|
`,
|
|
294
|
-
errors: [{ messageId: 'unsupported-
|
|
324
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
295
325
|
},
|
|
296
326
|
{
|
|
297
327
|
name: 'converts props with complicated expressions',
|
|
@@ -313,7 +343,7 @@ typescriptEslintTester.run(
|
|
|
313
343
|
padding: \`\${props.width}px \${props.width + 3}px \${props.width + 2}px\`,
|
|
314
344
|
}));
|
|
315
345
|
`,
|
|
316
|
-
errors: [{ messageId: 'unsupported-
|
|
346
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
317
347
|
},
|
|
318
348
|
{
|
|
319
349
|
name: 'converts props with overlapping names',
|
|
@@ -333,7 +363,7 @@ typescriptEslintTester.run(
|
|
|
333
363
|
width: props.height + props.oldHeight,
|
|
334
364
|
}));
|
|
335
365
|
`,
|
|
336
|
-
errors: [{ messageId: 'unsupported-
|
|
366
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
337
367
|
},
|
|
338
368
|
{
|
|
339
369
|
name: 'converts props mixed with token function',
|
|
@@ -353,7 +383,7 @@ typescriptEslintTester.run(
|
|
|
353
383
|
padding: \`\${token('some-token', someFallback)} \${props.myPadding}\`,
|
|
354
384
|
}));
|
|
355
385
|
`,
|
|
356
|
-
errors: [{ messageId: 'unsupported-
|
|
386
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
357
387
|
},
|
|
358
388
|
{
|
|
359
389
|
name: 'converts mix of styled variable arguments and object arguments',
|
|
@@ -393,7 +423,7 @@ typescriptEslintTester.run(
|
|
|
393
423
|
})
|
|
394
424
|
);
|
|
395
425
|
`,
|
|
396
|
-
errors: [{ messageId: 'unsupported-
|
|
426
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
397
427
|
},
|
|
398
428
|
{
|
|
399
429
|
name: 'converts mix of props and non-props',
|
|
@@ -415,7 +445,7 @@ typescriptEslintTester.run(
|
|
|
415
445
|
margin: \`2px \${token('some-token')}\`
|
|
416
446
|
}));
|
|
417
447
|
`,
|
|
418
|
-
errors: [{ messageId: 'unsupported-
|
|
448
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
419
449
|
},
|
|
420
450
|
],
|
|
421
451
|
},
|
|
@@ -43,7 +43,7 @@ typescriptEslintTester.run(
|
|
|
43
43
|
backgroundColor: props.backgroundColor,
|
|
44
44
|
}));
|
|
45
45
|
`,
|
|
46
|
-
errors: [{ messageId: 'unsupported-
|
|
46
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
name: 'converts styled usages with type annotation on the outside (as a variable)',
|
|
@@ -71,7 +71,7 @@ typescriptEslintTester.run(
|
|
|
71
71
|
backgroundColor: props.backgroundColor,
|
|
72
72
|
}));
|
|
73
73
|
`,
|
|
74
|
-
errors: [{ messageId: 'unsupported-
|
|
74
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
77
|
name: 'disables autofixer when type annotation is inside props argument',
|
|
@@ -90,7 +90,7 @@ typescriptEslintTester.run(
|
|
|
90
90
|
`,
|
|
91
91
|
errors: [
|
|
92
92
|
{
|
|
93
|
-
messageId: 'unsupported-
|
|
93
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
94
94
|
},
|
|
95
95
|
],
|
|
96
96
|
},
|
|
@@ -111,7 +111,7 @@ typescriptEslintTester.run(
|
|
|
111
111
|
`,
|
|
112
112
|
errors: [
|
|
113
113
|
{
|
|
114
|
-
messageId: 'unsupported-
|
|
114
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
115
115
|
},
|
|
116
116
|
],
|
|
117
117
|
},
|
|
@@ -131,7 +131,7 @@ typescriptEslintTester.run(
|
|
|
131
131
|
`,
|
|
132
132
|
errors: [
|
|
133
133
|
{
|
|
134
|
-
messageId: 'unsupported-
|
|
134
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
135
135
|
},
|
|
136
136
|
],
|
|
137
137
|
},
|
|
@@ -20,7 +20,7 @@ typescriptEslintTester.run(
|
|
|
20
20
|
`,
|
|
21
21
|
errors: [
|
|
22
22
|
{
|
|
23
|
-
messageId: 'unsupported-
|
|
23
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
24
24
|
},
|
|
25
25
|
],
|
|
26
26
|
},
|
|
@@ -36,7 +36,7 @@ typescriptEslintTester.run(
|
|
|
36
36
|
`,
|
|
37
37
|
errors: [
|
|
38
38
|
{
|
|
39
|
-
messageId: 'unsupported-
|
|
39
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
40
40
|
},
|
|
41
41
|
],
|
|
42
42
|
},
|
|
@@ -62,7 +62,7 @@ typescriptEslintTester.run(
|
|
|
62
62
|
color: props.otherColor,
|
|
63
63
|
}));
|
|
64
64
|
`,
|
|
65
|
-
errors: [{ messageId: 'unsupported-
|
|
65
|
+
errors: [{ messageId: 'unsupported-prop-syntax' }],
|
|
66
66
|
},
|
|
67
67
|
],
|
|
68
68
|
},
|
|
@@ -8,15 +8,10 @@ import type {
|
|
|
8
8
|
ObjectExpression,
|
|
9
9
|
} from 'estree-jsx';
|
|
10
10
|
import { createLintRule } from '../utils/create-rule';
|
|
11
|
-
import {
|
|
12
|
-
CSS_IN_JS_IMPORTS,
|
|
13
|
-
isStyledComponents,
|
|
14
|
-
} from '../utils/is-supported-import';
|
|
11
|
+
import { isStyledComponents, isEmotion } from '../utils/is-supported-import';
|
|
15
12
|
import type { Rule, Scope, SourceCode } from 'eslint';
|
|
16
13
|
import ESTraverse from 'estraverse';
|
|
17
14
|
|
|
18
|
-
const IMPORT_SOURCES = [CSS_IN_JS_IMPORTS.styledComponents];
|
|
19
|
-
|
|
20
15
|
type PropInfo = {
|
|
21
16
|
/**
|
|
22
17
|
* Name of the prop, e.g. props, backgroundColor.
|
|
@@ -240,7 +235,7 @@ const lintArguments = (
|
|
|
240
235
|
if (allProps.some((propUsage) => !propUsage.valid)) {
|
|
241
236
|
context.report({
|
|
242
237
|
node: argument,
|
|
243
|
-
messageId: 'unsupported-
|
|
238
|
+
messageId: 'unsupported-prop-syntax-no-autofixer',
|
|
244
239
|
});
|
|
245
240
|
|
|
246
241
|
return;
|
|
@@ -248,7 +243,7 @@ const lintArguments = (
|
|
|
248
243
|
|
|
249
244
|
context.report({
|
|
250
245
|
node: argument,
|
|
251
|
-
messageId: 'unsupported-
|
|
246
|
+
messageId: 'unsupported-prop-syntax',
|
|
252
247
|
fix(fixer) {
|
|
253
248
|
const sourceCode = context.getSourceCode();
|
|
254
249
|
return fixPropsObjectUsages(
|
|
@@ -376,17 +371,17 @@ export const rule = createLintRule({
|
|
|
376
371
|
name: 'convert-props-syntax',
|
|
377
372
|
docs: {
|
|
378
373
|
description:
|
|
379
|
-
'Convert props syntax that is unsupported by
|
|
374
|
+
'Convert props syntax that is unsupported by styled-components@<4 or @emotion/styled 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 those libraries.',
|
|
380
375
|
recommended: true,
|
|
381
376
|
severity: 'error',
|
|
382
377
|
},
|
|
383
378
|
fixable: 'code',
|
|
384
379
|
messages: {
|
|
385
|
-
'unsupported-
|
|
386
|
-
'This syntax is not supported by styled-components
|
|
380
|
+
'unsupported-prop-syntax':
|
|
381
|
+
'This syntax is not supported by styled-components@<4 or @emotion/styled 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.',
|
|
387
382
|
|
|
388
|
-
'unsupported-
|
|
389
|
-
'This syntax is not supported by styled-components
|
|
383
|
+
'unsupported-prop-syntax-no-autofixer':
|
|
384
|
+
'This syntax is not supported by styled-components@<4 or @emotion/styled 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.',
|
|
390
385
|
},
|
|
391
386
|
type: 'problem',
|
|
392
387
|
},
|
|
@@ -401,7 +396,10 @@ export const rule = createLintRule({
|
|
|
401
396
|
? node.callee.object
|
|
402
397
|
: node.callee;
|
|
403
398
|
|
|
404
|
-
if (
|
|
399
|
+
if (
|
|
400
|
+
!isStyledComponents(callee, references) &&
|
|
401
|
+
!isEmotion(callee, references)
|
|
402
|
+
) {
|
|
405
403
|
return;
|
|
406
404
|
}
|
|
407
405
|
|
|
@@ -177,9 +177,20 @@ export const isImportedFrom =
|
|
|
177
177
|
(
|
|
178
178
|
nodeToCheck: Callee,
|
|
179
179
|
referencesInScope: Reference[],
|
|
180
|
-
|
|
180
|
+
/**
|
|
181
|
+
* If we strictly have specific import sources in the config scope, pass them to make this more performant.
|
|
182
|
+
* Pass `null` if you don't care if its configured or not.
|
|
183
|
+
*/
|
|
184
|
+
importSources: ImportSource[] | null = null,
|
|
181
185
|
): boolean => {
|
|
182
|
-
if (
|
|
186
|
+
if (
|
|
187
|
+
importSources &&
|
|
188
|
+
!importSources.some(
|
|
189
|
+
(importSource) =>
|
|
190
|
+
importSource === moduleName ||
|
|
191
|
+
(!exactMatch && importSource.startsWith(moduleName)),
|
|
192
|
+
)
|
|
193
|
+
) {
|
|
183
194
|
// Don't go through the trouble of checking the import sources does not include this
|
|
184
195
|
// We'll assume this is skipped elsewhere.
|
|
185
196
|
return false;
|