@atlaskit/eslint-plugin-design-system 8.36.1 → 8.36.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 +14 -0
- package/constellation/consistent-css-prop-usage/usage.mdx +12 -2
- package/dist/cjs/rules/consistent-css-prop-usage/index.js +8 -1
- package/dist/cjs/rules/ensure-design-token-usage/index.js +3 -0
- package/dist/cjs/rules/ensure-design-token-usage/shape.js +0 -1
- package/dist/cjs/rules/no-deprecated-imports/index.js +25 -25
- package/dist/cjs/rules/prefer-primitives/index.js +0 -1
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/convert-jsx-call-site.js +2 -2
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/find-valid-styled-component-call.js +2 -2
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/index.js +2 -2
- package/dist/cjs/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js +2 -2
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/index.js +2 -2
- package/dist/cjs/rules/use-primitives/transformers/emotion-css/upsert-import-declaration.js +2 -2
- package/dist/cjs/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +2 -3
- package/dist/cjs/rules/use-primitives-text/transformers/common.js +2 -2
- package/dist/cjs/rules/use-primitives-text/transformers/emphasis-elements.js +2 -2
- package/dist/cjs/rules/use-primitives-text/transformers/paragraph-elements.js +2 -2
- package/dist/cjs/rules/use-primitives-text/transformers/span-elements.js +2 -2
- package/dist/cjs/rules/use-primitives-text/transformers/strong-elements.js +2 -2
- package/dist/cjs/rules/utils/create-no-tagged-template-expression-rule/generate.js +4 -1
- package/dist/cjs/rules/utils/create-no-tagged-template-expression-rule/index.js +1 -1
- package/dist/cjs/rules/utils/create-no-tagged-template-expression-rule/to-arguments.js +15 -4
- package/dist/cjs/rules/utils/is-node.js +11 -6
- package/dist/es2019/rules/consistent-css-prop-usage/index.js +8 -1
- package/dist/es2019/rules/ensure-design-token-usage/index.js +4 -1
- package/dist/es2019/rules/ensure-design-token-usage/shape.js +0 -1
- package/dist/es2019/rules/prefer-primitives/index.js +0 -1
- package/dist/es2019/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +0 -1
- package/dist/es2019/rules/use-primitives-text/transformers/paragraph-elements.js +0 -1
- package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/generate.js +6 -1
- package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/index.js +6 -8
- package/dist/es2019/rules/utils/create-no-tagged-template-expression-rule/to-arguments.js +13 -2
- package/dist/es2019/rules/utils/is-node.js +10 -5
- package/dist/es2019/rules/utils/is-supported-import.js +1 -0
- package/dist/esm/rules/consistent-css-prop-usage/index.js +8 -1
- package/dist/esm/rules/ensure-design-token-usage/index.js +4 -1
- package/dist/esm/rules/ensure-design-token-usage/shape.js +0 -1
- package/dist/esm/rules/prefer-primitives/index.js +0 -1
- package/dist/esm/rules/use-primitives/utils/is-valid-css-properties-to-transform.js +0 -1
- package/dist/esm/rules/utils/create-no-tagged-template-expression-rule/generate.js +4 -1
- package/dist/esm/rules/utils/create-no-tagged-template-expression-rule/index.js +1 -1
- package/dist/esm/rules/utils/create-no-tagged-template-expression-rule/to-arguments.js +15 -4
- package/dist/esm/rules/utils/is-node.js +10 -5
- package/dist/esm/rules/utils/is-supported-import.js +1 -0
- package/dist/types/rules/consistent-css-prop-usage/types.d.ts +1 -0
- package/dist/types/rules/utils/is-node.d.ts +1 -0
- package/dist/types-ts4.5/rules/consistent-css-prop-usage/types.d.ts +1 -0
- package/dist/types-ts4.5/rules/utils/is-node.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 8.36.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#77172](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/77172) [`0e9162a7371a`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0e9162a7371a) - Fixes issues with CSS var and content string handling for the `no-*-tagged-template-expression` rules
|
|
8
|
+
|
|
9
|
+
## 8.36.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#80471](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/80471) [`bf21a3bfe85e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bf21a3bfe85e) - Add `autoFixNames` option to `consistent-css-prop-usage`. When set to false, the autofix naming that enforces style variables ending in the word "Styles" will be turned off. True by default.
|
|
14
|
+
- [#80469](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/80469) [`0b4b7268ef16`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0b4b7268ef16) - Fixed an issue with `ensure-design-token-usage` where styles inside xcss could be incorrectly linted against.
|
|
15
|
+
- [#80518](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/80518) [`0f90b6e17490`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0f90b6e17490) - Ignore function-like interpolations in selectors for `no-css-tagged-template-expression`, `no-styled-…`, and `no-keyframes-…`
|
|
16
|
+
|
|
3
17
|
## 8.36.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -181,13 +181,23 @@ Whether to exclude `css` attributes of React components from being affected by t
|
|
|
181
181
|
|
|
182
182
|
This is `false` by default.
|
|
183
183
|
|
|
184
|
-
###
|
|
184
|
+
### autoFixNames
|
|
185
185
|
|
|
186
|
-
When
|
|
186
|
+
When set to `true`, this rule will _turn on_ an autofixer that adds `Styles` at the end of existing style variables.
|
|
187
187
|
|
|
188
188
|
```tsx
|
|
189
189
|
// vvvvv will be renamed to `myCssStyles`
|
|
190
190
|
const myCss = { color: 'blue' };
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
+
Note that when hoisting styles, the name of the newly created style variable follows its own naming scheme (`styles`, `styles_1`, `styles_2`, ...) and is not affected by the value of `autoFixNames`.
|
|
194
|
+
|
|
195
|
+
This is `true` by default.
|
|
196
|
+
|
|
197
|
+
### fixNamesOnly
|
|
198
|
+
|
|
199
|
+
When set to `true`, this rule will _turn off_ all autofixers other than the autofixer adding `Styles` to the end of existing style variables (which is controlled by `autoFixNames`). In other words, styles will no longer be hoisted and styles will no longer be wrapped in a `css`/`xcss` function call.
|
|
200
|
+
|
|
193
201
|
This is `false` by default.
|
|
202
|
+
|
|
203
|
+
If `autoFixNames` is `false` and `fixNamesOnly` is `true`, all autofixers will be turned off.
|
|
@@ -455,7 +455,8 @@ var defaultConfig = {
|
|
|
455
455
|
cssImportSource: _isSupportedImport.CSS_IN_JS_IMPORTS.compiled,
|
|
456
456
|
xcssImportSource: _isSupportedImport.CSS_IN_JS_IMPORTS.atlaskitPrimitives,
|
|
457
457
|
excludeReactComponents: false,
|
|
458
|
-
fixNamesOnly: false
|
|
458
|
+
fixNamesOnly: false,
|
|
459
|
+
autoFixNames: true
|
|
459
460
|
};
|
|
460
461
|
var rule = (0, _createRule.createLintRule)({
|
|
461
462
|
meta: {
|
|
@@ -499,6 +500,9 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
499
500
|
excludeReactComponents: {
|
|
500
501
|
type: 'boolean'
|
|
501
502
|
},
|
|
503
|
+
autoFixNames: {
|
|
504
|
+
type: 'boolean'
|
|
505
|
+
},
|
|
502
506
|
fixNamesOnly: {
|
|
503
507
|
type: 'boolean'
|
|
504
508
|
}
|
|
@@ -524,6 +528,9 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
524
528
|
// Already prefixed! Nothing to do.
|
|
525
529
|
return;
|
|
526
530
|
}
|
|
531
|
+
if (!mergedConfig.autoFixNames) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
527
534
|
context.report({
|
|
528
535
|
node: identifier,
|
|
529
536
|
messageId: 'shouldEndInStyles',
|
|
@@ -73,6 +73,9 @@ var createWithConfig = exports.createWithConfig = function createWithConfig(init
|
|
|
73
73
|
if (parentNode.parent.type === 'Property') {
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
+
if ((0, _isNode.isDecendantOfXcssBlock)(parentNode)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
76
79
|
if (!(0, _isNode.isDecendantOfStyleBlock)(parentNode) && !(0, _isNode.isDecendantOfType)(parentNode, 'JSXExpressionContainer')) {
|
|
77
80
|
return;
|
|
78
81
|
}
|
|
@@ -24,7 +24,6 @@ var radiusValueToToken = exports.radiusValueToToken = Object.fromEntries(_tokens
|
|
|
24
24
|
}).concat([['3px', 'border.radius']]) // add in an extra entry to resolve 3px to border.radius (normally 4px)
|
|
25
25
|
.concat([['50%', 'border.radius.circle']]) // add in an extra entry to resolve 50% to border.radius.circle (normally 2002rem)
|
|
26
26
|
);
|
|
27
|
-
|
|
28
27
|
var borderWidthValueToToken = exports.borderWidthValueToToken = Object.fromEntries(_tokensRaw.shape.filter(function (t) {
|
|
29
28
|
return t.name.startsWith('border.width');
|
|
30
29
|
}).map(function (t) {
|
|
@@ -12,31 +12,31 @@ var _types = require("../utils/types");
|
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
15
|
+
* Forked from original `no-restricted-imports` although the source has been substantially changed.
|
|
16
|
+
*
|
|
17
|
+
* To ensure compliance the license from eslint has been included and the original attribution.
|
|
18
|
+
* @author Guy Ellis
|
|
19
|
+
*
|
|
20
|
+
* Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
|
|
21
|
+
*
|
|
22
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
23
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
24
|
+
* in the Software without restriction, including without limitation the rights
|
|
25
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
26
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
27
|
+
* furnished to do so, subject to the following conditions:
|
|
28
|
+
*
|
|
29
|
+
* The above copyright notice and this permission notice shall be included in
|
|
30
|
+
* all copies or substantial portions of the Software.
|
|
31
|
+
*
|
|
32
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
33
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
34
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
35
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
36
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
37
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
38
|
+
* THE SOFTWARE.
|
|
39
|
+
*/
|
|
40
40
|
var name = exports.name = 'no-deprecated-imports';
|
|
41
41
|
var importNameWithCustomMessageId = exports.importNameWithCustomMessageId = 'importNameWithCustomMessage';
|
|
42
42
|
var pathWithCustomMessageId = exports.pathWithCustomMessageId = 'pathWithCustomMessage';
|
|
@@ -83,7 +83,6 @@ var rule = (0, _createRule.createLintRule)({
|
|
|
83
83
|
if (typeof argValue === 'string') {
|
|
84
84
|
var suggest = _utils.validPrimitiveElements.has(argValue.replaceAll("'", '') // argValue will have '' around the element name, strip it out for this test
|
|
85
85
|
);
|
|
86
|
-
|
|
87
86
|
if (suggest) {
|
|
88
87
|
var styledIdentifier = node.callee.name;
|
|
89
88
|
var elementName = argValue;
|
|
@@ -9,8 +9,8 @@ exports.convertJsxCallSite = void 0;
|
|
|
9
9
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
10
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
11
|
var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
|
|
12
|
-
function _getRequireWildcardCache(
|
|
13
|
-
function _interopRequireWildcard(
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
/**
|
|
15
15
|
* Transforms a JSXElement from:
|
|
16
16
|
* ```
|
|
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.findValidStyledComponentCall = void 0;
|
|
8
8
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
9
9
|
var supported = _interopRequireWildcard(require("./supported"));
|
|
10
|
-
function _getRequireWildcardCache(
|
|
11
|
-
function _interopRequireWildcard(
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
12
|
/**
|
|
13
13
|
* returns a variable reference if preconditions are favourable for
|
|
14
14
|
* the transformation to proceed, undefined otherwise.
|
|
@@ -15,8 +15,8 @@ var _convertStyledComponentCallToJsx = require("./convert-styled-component-call-
|
|
|
15
15
|
var _findValidJsxUsageToTransform = require("./find-valid-jsx-usage-to-transform");
|
|
16
16
|
var _findValidStyledComponentCall = require("./find-valid-styled-component-call");
|
|
17
17
|
var _upsertImportDeclaration = require("./upsert-import-declaration");
|
|
18
|
-
function _getRequireWildcardCache(
|
|
19
|
-
function _interopRequireWildcard(
|
|
18
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
19
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
20
|
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
21
21
|
|
|
22
22
|
var CompiledStyled = exports.CompiledStyled = {
|
package/dist/cjs/rules/use-primitives/transformers/compiled-styled/upsert-import-declaration.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.upsertImportDeclaration = void 0;
|
|
8
8
|
var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
|
|
9
|
-
function _getRequireWildcardCache(
|
|
10
|
-
function _interopRequireWildcard(
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
11
|
/**
|
|
12
12
|
* Currently this is defined here because it's not very general purpose.
|
|
13
13
|
* If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
|
|
@@ -13,8 +13,8 @@ var _utils = require("../../utils");
|
|
|
13
13
|
var _cssToXcss = require("../css-to-xcss");
|
|
14
14
|
var supported = _interopRequireWildcard(require("./supported"));
|
|
15
15
|
var _upsertImportDeclaration = require("./upsert-import-declaration");
|
|
16
|
-
function _getRequireWildcardCache(
|
|
17
|
-
function _interopRequireWildcard(
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
18
|
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
19
19
|
|
|
20
20
|
var EmotionCSS = exports.EmotionCSS = {
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.upsertImportDeclaration = void 0;
|
|
8
8
|
var ast = _interopRequireWildcard(require("../../../../ast-nodes"));
|
|
9
|
-
function _getRequireWildcardCache(
|
|
10
|
-
function _interopRequireWildcard(
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
11
|
/**
|
|
12
12
|
* Currently this is defined here because it's not very general purpose.
|
|
13
13
|
* If we were to move this to `ast-nodes`, half the implementation would be in `Root`,
|
|
@@ -13,8 +13,8 @@ var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
|
13
13
|
var _cssToXcss = require("../transformers/css-to-xcss");
|
|
14
14
|
var _convertAstObjectExpressionToJsObject = require("./convert-ast-object-expression-to-js-object");
|
|
15
15
|
var _excluded = ["unsupported"];
|
|
16
|
-
function _getRequireWildcardCache(
|
|
17
|
-
function _interopRequireWildcard(
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
18
|
var isValidCssPropertiesToTransform = exports.isValidCssPropertiesToTransform = function isValidCssPropertiesToTransform(node, config) {
|
|
19
19
|
if (!node) {
|
|
20
20
|
return false;
|
|
@@ -80,7 +80,6 @@ var isValidCssPropertiesToTransform = exports.isValidCssPropertiesToTransform =
|
|
|
80
80
|
;
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
|
-
|
|
84
83
|
if (!containsOnlyValidStyles) {
|
|
85
84
|
return false;
|
|
86
85
|
}
|
|
@@ -10,8 +10,8 @@ exports.hasTextChildrenOnly = hasTextChildrenOnly;
|
|
|
10
10
|
exports.updateTestIdAttributeFix = updateTestIdAttributeFix;
|
|
11
11
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
12
12
|
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
13
|
-
function _getRequireWildcardCache(
|
|
14
|
-
function _interopRequireWildcard(
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
15
|
// Rename data-testid prop to testId if present
|
|
16
16
|
function updateTestIdAttributeFix(node, fixer) {
|
|
17
17
|
var testIdAttr = ast.JSXElement.getAttributeByName(node, 'data-testid');
|
|
@@ -11,8 +11,8 @@ var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
|
11
11
|
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
12
12
|
var _upsertImportDeclaration = require("../../use-primitives/transformers/emotion-css/upsert-import-declaration");
|
|
13
13
|
var _common = require("./common");
|
|
14
|
-
function _getRequireWildcardCache(
|
|
15
|
-
function _interopRequireWildcard(
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
16
|
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
17
17
|
|
|
18
18
|
var EmphasisElements = exports.EmphasisElements = {
|
|
@@ -11,8 +11,8 @@ var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
|
11
11
|
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
12
12
|
var _upsertImportDeclaration = require("../../use-primitives/transformers/emotion-css/upsert-import-declaration");
|
|
13
13
|
var _common = require("./common");
|
|
14
|
-
function _getRequireWildcardCache(
|
|
15
|
-
function _interopRequireWildcard(
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
16
|
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
17
17
|
|
|
18
18
|
var ParagraphElements = exports.ParagraphElements = {
|
|
@@ -11,8 +11,8 @@ var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
|
11
11
|
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
12
12
|
var _upsertImportDeclaration = require("../../use-primitives/transformers/emotion-css/upsert-import-declaration");
|
|
13
13
|
var _common = require("./common");
|
|
14
|
-
function _getRequireWildcardCache(
|
|
15
|
-
function _interopRequireWildcard(
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
16
|
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
17
17
|
|
|
18
18
|
var SpanElements = exports.SpanElements = {
|
|
@@ -11,8 +11,8 @@ var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
|
11
11
|
var ast = _interopRequireWildcard(require("../../../ast-nodes"));
|
|
12
12
|
var _upsertImportDeclaration = require("../../use-primitives/transformers/emotion-css/upsert-import-declaration");
|
|
13
13
|
var _common = require("./common");
|
|
14
|
-
function _getRequireWildcardCache(
|
|
15
|
-
function _interopRequireWildcard(
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
16
|
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
17
17
|
|
|
18
18
|
var StrongElements = exports.StrongElements = {
|
|
@@ -28,7 +28,10 @@ var createKey = function createKey(key) {
|
|
|
28
28
|
return "[`".concat(key, "`]");
|
|
29
29
|
};
|
|
30
30
|
var addQuotes = function addQuotes(literal) {
|
|
31
|
-
|
|
31
|
+
if (literal[0] === "\"") {
|
|
32
|
+
return "'".concat(literal.replace(/'/g, "\\'"), "'");
|
|
33
|
+
}
|
|
34
|
+
return "\"".concat(literal.replace(/"/g, "\\\""), "\"");
|
|
32
35
|
};
|
|
33
36
|
var createValue = function createValue(value) {
|
|
34
37
|
var type = value.type;
|
|
@@ -95,7 +95,7 @@ var createNoTaggedTemplateExpressionRule = exports.createNoTaggedTemplateExpress
|
|
|
95
95
|
}
|
|
96
96
|
return _context.abrupt("return");
|
|
97
97
|
case 16:
|
|
98
|
-
if (!(isSC && /\$\{.*:[\s]*\{/.test(newCode))) {
|
|
98
|
+
if (!(isSC && /\$\{.*:[\s]*\{/.test(newCode) || /\$\{.*\(.*:[\s]*\{/.test(newCode))) {
|
|
99
99
|
_context.next = 18;
|
|
100
100
|
break;
|
|
101
101
|
}
|
|
@@ -119,14 +119,25 @@ var getArguments = function getArguments(chars) {
|
|
|
119
119
|
};
|
|
120
120
|
args.push({
|
|
121
121
|
type: 'declaration',
|
|
122
|
-
|
|
123
|
-
property: property.trim().replace(/-[a-z]/g, function (match) {
|
|
124
|
-
return match[1].toUpperCase();
|
|
125
|
-
}),
|
|
122
|
+
property: getPropertyForDeclaration(property),
|
|
126
123
|
value: getValue()
|
|
127
124
|
});
|
|
128
125
|
return args;
|
|
129
126
|
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Trims the property value. Converts it to camelCase if it isn't a variable.
|
|
130
|
+
*/
|
|
131
|
+
var getPropertyForDeclaration = function getPropertyForDeclaration(property) {
|
|
132
|
+
var trimmed = property.trim();
|
|
133
|
+
if (trimmed.startsWith('--')) {
|
|
134
|
+
return trimmed;
|
|
135
|
+
}
|
|
136
|
+
// Make the property camelCase if it isn't a CSS variable
|
|
137
|
+
return trimmed.replace(/-[a-z]/g, function (match) {
|
|
138
|
+
return match[1].toUpperCase();
|
|
139
|
+
});
|
|
140
|
+
};
|
|
130
141
|
var getSelectorValue = function getSelectorValue(chars, expressions) {
|
|
131
142
|
// If no variable, returns chars immediately.
|
|
132
143
|
// i.e. `.foo { color: red }` returns '.foo'
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isPropertyKey = exports.isDecendantOfType = exports.isDecendantOfSvgElement = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfPrimitive = exports.isDecendantOfGlobalToken = exports.isCssInJsTemplateNode = exports.isCssInJsObjectNode = exports.isCssInJsCallNode = exports.isChildOfType = void 0;
|
|
6
|
+
exports.isPropertyKey = exports.isDecendantOfXcssBlock = exports.isDecendantOfType = exports.isDecendantOfSvgElement = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfPrimitive = exports.isDecendantOfGlobalToken = exports.isCssInJsTemplateNode = exports.isCssInJsObjectNode = exports.isCssInJsCallNode = exports.isChildOfType = void 0;
|
|
7
7
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
8
|
var _astNodes = require("../../ast-nodes");
|
|
9
9
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
@@ -84,6 +84,16 @@ var isCssInJsObjectNode = exports.isCssInJsObjectNode = function isCssInJsObject
|
|
|
84
84
|
var isXcssCallNode = function isXcssCallNode(node) {
|
|
85
85
|
return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'xcss';
|
|
86
86
|
};
|
|
87
|
+
var isDecendantOfXcssBlock = exports.isDecendantOfXcssBlock = function isDecendantOfXcssBlock(node) {
|
|
88
|
+
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
89
|
+
if (isXcssCallNode(node)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
if (node.parent) {
|
|
93
|
+
return isDecendantOfXcssBlock(node.parent);
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
};
|
|
87
97
|
var isDecendantOfStyleBlock = exports.isDecendantOfStyleBlock = function isDecendantOfStyleBlock(node) {
|
|
88
98
|
if (node.type === 'VariableDeclarator') {
|
|
89
99
|
if (node.id.type !== 'Identifier') {
|
|
@@ -112,11 +122,6 @@ var isDecendantOfStyleBlock = exports.isDecendantOfStyleBlock = function isDecen
|
|
|
112
122
|
return varName.includes(el);
|
|
113
123
|
});
|
|
114
124
|
}
|
|
115
|
-
|
|
116
|
-
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
117
|
-
if (isXcssCallNode(node)) {
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
125
|
if (isCssInJsCallNode(node) || isCssInJsObjectNode(node) || isCssInJsTemplateNode(node)) {
|
|
121
126
|
return true;
|
|
122
127
|
}
|
|
@@ -404,7 +404,8 @@ const defaultConfig = {
|
|
|
404
404
|
cssImportSource: CSS_IN_JS_IMPORTS.compiled,
|
|
405
405
|
xcssImportSource: CSS_IN_JS_IMPORTS.atlaskitPrimitives,
|
|
406
406
|
excludeReactComponents: false,
|
|
407
|
-
fixNamesOnly: false
|
|
407
|
+
fixNamesOnly: false,
|
|
408
|
+
autoFixNames: true
|
|
408
409
|
};
|
|
409
410
|
const rule = createLintRule({
|
|
410
411
|
meta: {
|
|
@@ -448,6 +449,9 @@ const rule = createLintRule({
|
|
|
448
449
|
excludeReactComponents: {
|
|
449
450
|
type: 'boolean'
|
|
450
451
|
},
|
|
452
|
+
autoFixNames: {
|
|
453
|
+
type: 'boolean'
|
|
454
|
+
},
|
|
451
455
|
fixNamesOnly: {
|
|
452
456
|
type: 'boolean'
|
|
453
457
|
}
|
|
@@ -471,6 +475,9 @@ const rule = createLintRule({
|
|
|
471
475
|
// Already prefixed! Nothing to do.
|
|
472
476
|
return;
|
|
473
477
|
}
|
|
478
|
+
if (!mergedConfig.autoFixNames) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
474
481
|
context.report({
|
|
475
482
|
node: identifier,
|
|
476
483
|
messageId: 'shouldEndInStyles',
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
4
|
import { createLintRule } from '../utils/create-rule';
|
|
5
5
|
import { includesHardCodedColor } from '../utils/is-color';
|
|
6
|
-
import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType } from '../utils/is-node';
|
|
6
|
+
import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType, isDecendantOfXcssBlock } from '../utils/is-node';
|
|
7
7
|
import { lintJSXIdentifierForColor, lintJSXLiteralForColor, lintJSXMemberForColor, lintObjectForColor, lintTemplateIdentifierForColor } from './color';
|
|
8
8
|
import { errorBoundary } from './error-boundary';
|
|
9
9
|
import ruleMeta from './rule-meta';
|
|
@@ -51,6 +51,9 @@ const createWithConfig = initialConfig => context => {
|
|
|
51
51
|
if (parentNode.parent.type === 'Property') {
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
+
if (isDecendantOfXcssBlock(parentNode)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
54
57
|
if (!isDecendantOfStyleBlock(parentNode) && !isDecendantOfType(parentNode, 'JSXExpressionContainer')) {
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
@@ -9,7 +9,6 @@ export const radiusValueToToken = Object.fromEntries(shapeTokens.filter(t => t.n
|
|
|
9
9
|
}).concat([['3px', 'border.radius']]) // add in an extra entry to resolve 3px to border.radius (normally 4px)
|
|
10
10
|
.concat([['50%', 'border.radius.circle']]) // add in an extra entry to resolve 50% to border.radius.circle (normally 2002rem)
|
|
11
11
|
);
|
|
12
|
-
|
|
13
12
|
export const borderWidthValueToToken = Object.fromEntries(shapeTokens.filter(t => t.name.startsWith('border.width')).map(t => [t.value, t.cleanName]).concat([['2px', 'border.width']]));
|
|
14
13
|
export function isRadiusProperty(propertyName) {
|
|
15
14
|
return shapeProperties.includes(propertyName);
|
|
@@ -78,7 +78,6 @@ const rule = createLintRule({
|
|
|
78
78
|
if (typeof argValue === 'string') {
|
|
79
79
|
const suggest = validPrimitiveElements.has(argValue.replaceAll(`'`, '') // argValue will have '' around the element name, strip it out for this test
|
|
80
80
|
);
|
|
81
|
-
|
|
82
81
|
if (suggest) {
|
|
83
82
|
const styledIdentifier = node.callee.name;
|
|
84
83
|
const elementName = argValue;
|
|
@@ -166,7 +166,6 @@ export const ParagraphElements = {
|
|
|
166
166
|
return [importFix, ...elementNameFixes, asAttributeFix, colorAttributeFix, testAttributeFix].filter(fix => Boolean(fix)); // Some of the transformers can return arrays with undefined, so filter them out
|
|
167
167
|
};
|
|
168
168
|
},
|
|
169
|
-
|
|
170
169
|
_fixMultiple(node, {
|
|
171
170
|
context,
|
|
172
171
|
config,
|
|
@@ -16,7 +16,12 @@ const createKey = key => {
|
|
|
16
16
|
}
|
|
17
17
|
return `[\`${key}\`]`;
|
|
18
18
|
};
|
|
19
|
-
const addQuotes = literal =>
|
|
19
|
+
const addQuotes = literal => {
|
|
20
|
+
if (literal[0] === `"`) {
|
|
21
|
+
return `'${literal.replace(/'/g, `\\'`)}'`;
|
|
22
|
+
}
|
|
23
|
+
return `"${literal.replace(/"/g, `\\"`)}"`;
|
|
24
|
+
};
|
|
20
25
|
const createValue = value => {
|
|
21
26
|
const {
|
|
22
27
|
type
|
|
@@ -79,23 +79,21 @@ export const createNoTaggedTemplateExpressionRule = (isUsage, messageId) => cont
|
|
|
79
79
|
|
|
80
80
|
// TODO: We might want to similarly disallow `styled.div({ color: props => props.color })` for SC as it's broken too (both type and functionality)
|
|
81
81
|
// Alternatively, autofix it to `styled.div(props => ({ color: props.color }))`?
|
|
82
|
-
if (isSC && /\$\{.*:[\s]*\{/.test(newCode)) {
|
|
82
|
+
if (isSC && /\$\{.*:[\s]*\{/.test(newCode) || /\$\{.*\(.*:[\s]*\{/.test(newCode)) {
|
|
83
83
|
/**
|
|
84
84
|
* If we find a variable in a selector when migrating `styled-components` code, we skip it.
|
|
85
85
|
* This is because `styled-components@3.x` does not support the syntax.
|
|
86
86
|
*
|
|
87
|
-
* @
|
|
87
|
+
* @examples
|
|
88
88
|
* ```tsx
|
|
89
89
|
* const Component = styled.div`
|
|
90
90
|
* & + ${Button} { color: red; }
|
|
91
91
|
* `;
|
|
92
92
|
* ```
|
|
93
|
-
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* color: 'red',
|
|
98
|
-
* });
|
|
93
|
+
*```tsx
|
|
94
|
+
* const Component = styled.div`
|
|
95
|
+
* ${mixin()} button { color: red; }
|
|
96
|
+
* `;
|
|
99
97
|
* ```
|
|
100
98
|
*/
|
|
101
99
|
return;
|
|
@@ -92,12 +92,23 @@ const getArguments = (chars, expressions = []) => {
|
|
|
92
92
|
};
|
|
93
93
|
args.push({
|
|
94
94
|
type: 'declaration',
|
|
95
|
-
|
|
96
|
-
property: property.trim().replace(/-[a-z]/g, match => match[1].toUpperCase()),
|
|
95
|
+
property: getPropertyForDeclaration(property),
|
|
97
96
|
value: getValue()
|
|
98
97
|
});
|
|
99
98
|
return args;
|
|
100
99
|
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Trims the property value. Converts it to camelCase if it isn't a variable.
|
|
103
|
+
*/
|
|
104
|
+
const getPropertyForDeclaration = property => {
|
|
105
|
+
const trimmed = property.trim();
|
|
106
|
+
if (trimmed.startsWith('--')) {
|
|
107
|
+
return trimmed;
|
|
108
|
+
}
|
|
109
|
+
// Make the property camelCase if it isn't a CSS variable
|
|
110
|
+
return trimmed.replace(/-[a-z]/g, match => match[1].toUpperCase());
|
|
111
|
+
};
|
|
101
112
|
const getSelectorValue = (chars, expressions) => {
|
|
102
113
|
// If no variable, returns chars immediately.
|
|
103
114
|
// i.e. `.foo { color: red }` returns '.foo'
|
|
@@ -69,6 +69,16 @@ export const isCssInJsTemplateNode = node => (node === null || node === void 0 ?
|
|
|
69
69
|
export const isCssInJsCallNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && cssInJsCallees.includes(node.callee.name);
|
|
70
70
|
export const isCssInJsObjectNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && cssInJsCallees.includes(node.callee.object.name);
|
|
71
71
|
const isXcssCallNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'xcss';
|
|
72
|
+
export const isDecendantOfXcssBlock = node => {
|
|
73
|
+
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
74
|
+
if (isXcssCallNode(node)) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (node.parent) {
|
|
78
|
+
return isDecendantOfXcssBlock(node.parent);
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
};
|
|
72
82
|
export const isDecendantOfStyleBlock = node => {
|
|
73
83
|
if (node.type === 'VariableDeclarator') {
|
|
74
84
|
if (node.id.type !== 'Identifier') {
|
|
@@ -93,11 +103,6 @@ export const isDecendantOfStyleBlock = node => {
|
|
|
93
103
|
const varName = node.id.name.toLowerCase();
|
|
94
104
|
return ['style', 'css', 'theme'].some(el => varName.includes(el));
|
|
95
105
|
}
|
|
96
|
-
|
|
97
|
-
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
98
|
-
if (isXcssCallNode(node)) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
106
|
if (isCssInJsCallNode(node) || isCssInJsObjectNode(node) || isCssInJsTemplateNode(node)) {
|
|
102
107
|
return true;
|
|
103
108
|
}
|
|
@@ -448,7 +448,8 @@ var defaultConfig = {
|
|
|
448
448
|
cssImportSource: CSS_IN_JS_IMPORTS.compiled,
|
|
449
449
|
xcssImportSource: CSS_IN_JS_IMPORTS.atlaskitPrimitives,
|
|
450
450
|
excludeReactComponents: false,
|
|
451
|
-
fixNamesOnly: false
|
|
451
|
+
fixNamesOnly: false,
|
|
452
|
+
autoFixNames: true
|
|
452
453
|
};
|
|
453
454
|
var rule = createLintRule({
|
|
454
455
|
meta: {
|
|
@@ -492,6 +493,9 @@ var rule = createLintRule({
|
|
|
492
493
|
excludeReactComponents: {
|
|
493
494
|
type: 'boolean'
|
|
494
495
|
},
|
|
496
|
+
autoFixNames: {
|
|
497
|
+
type: 'boolean'
|
|
498
|
+
},
|
|
495
499
|
fixNamesOnly: {
|
|
496
500
|
type: 'boolean'
|
|
497
501
|
}
|
|
@@ -517,6 +521,9 @@ var rule = createLintRule({
|
|
|
517
521
|
// Already prefixed! Nothing to do.
|
|
518
522
|
return;
|
|
519
523
|
}
|
|
524
|
+
if (!mergedConfig.autoFixNames) {
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
520
527
|
context.report({
|
|
521
528
|
node: identifier,
|
|
522
529
|
messageId: 'shouldEndInStyles',
|
|
@@ -4,7 +4,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
4
4
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
5
5
|
import { createLintRule } from '../utils/create-rule';
|
|
6
6
|
import { includesHardCodedColor } from '../utils/is-color';
|
|
7
|
-
import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType } from '../utils/is-node';
|
|
7
|
+
import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType, isDecendantOfXcssBlock } from '../utils/is-node';
|
|
8
8
|
import { lintJSXIdentifierForColor, lintJSXLiteralForColor, lintJSXMemberForColor, lintObjectForColor, lintTemplateIdentifierForColor } from './color';
|
|
9
9
|
import { errorBoundary } from './error-boundary';
|
|
10
10
|
import ruleMeta from './rule-meta';
|
|
@@ -66,6 +66,9 @@ var createWithConfig = function createWithConfig(initialConfig) {
|
|
|
66
66
|
if (parentNode.parent.type === 'Property') {
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
+
if (isDecendantOfXcssBlock(parentNode)) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
69
72
|
if (!isDecendantOfStyleBlock(parentNode) && !isDecendantOfType(parentNode, 'JSXExpressionContainer')) {
|
|
70
73
|
return;
|
|
71
74
|
}
|
|
@@ -13,7 +13,6 @@ export var radiusValueToToken = Object.fromEntries(shapeTokens.filter(function (
|
|
|
13
13
|
}).concat([['3px', 'border.radius']]) // add in an extra entry to resolve 3px to border.radius (normally 4px)
|
|
14
14
|
.concat([['50%', 'border.radius.circle']]) // add in an extra entry to resolve 50% to border.radius.circle (normally 2002rem)
|
|
15
15
|
);
|
|
16
|
-
|
|
17
16
|
export var borderWidthValueToToken = Object.fromEntries(shapeTokens.filter(function (t) {
|
|
18
17
|
return t.name.startsWith('border.width');
|
|
19
18
|
}).map(function (t) {
|
|
@@ -77,7 +77,6 @@ var rule = createLintRule({
|
|
|
77
77
|
if (typeof argValue === 'string') {
|
|
78
78
|
var suggest = validPrimitiveElements.has(argValue.replaceAll("'", '') // argValue will have '' around the element name, strip it out for this test
|
|
79
79
|
);
|
|
80
|
-
|
|
81
80
|
if (suggest) {
|
|
82
81
|
var styledIdentifier = node.callee.name;
|
|
83
82
|
var elementName = argValue;
|
|
@@ -21,7 +21,10 @@ var createKey = function createKey(key) {
|
|
|
21
21
|
return "[`".concat(key, "`]");
|
|
22
22
|
};
|
|
23
23
|
var addQuotes = function addQuotes(literal) {
|
|
24
|
-
|
|
24
|
+
if (literal[0] === "\"") {
|
|
25
|
+
return "'".concat(literal.replace(/'/g, "\\'"), "'");
|
|
26
|
+
}
|
|
27
|
+
return "\"".concat(literal.replace(/"/g, "\\\""), "\"");
|
|
25
28
|
};
|
|
26
29
|
var createValue = function createValue(value) {
|
|
27
30
|
var type = value.type;
|
|
@@ -88,7 +88,7 @@ export var createNoTaggedTemplateExpressionRule = function createNoTaggedTemplat
|
|
|
88
88
|
}
|
|
89
89
|
return _context.abrupt("return");
|
|
90
90
|
case 16:
|
|
91
|
-
if (!(isSC && /\$\{.*:[\s]*\{/.test(newCode))) {
|
|
91
|
+
if (!(isSC && /\$\{.*:[\s]*\{/.test(newCode) || /\$\{.*\(.*:[\s]*\{/.test(newCode))) {
|
|
92
92
|
_context.next = 18;
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
@@ -112,14 +112,25 @@ var getArguments = function getArguments(chars) {
|
|
|
112
112
|
};
|
|
113
113
|
args.push({
|
|
114
114
|
type: 'declaration',
|
|
115
|
-
|
|
116
|
-
property: property.trim().replace(/-[a-z]/g, function (match) {
|
|
117
|
-
return match[1].toUpperCase();
|
|
118
|
-
}),
|
|
115
|
+
property: getPropertyForDeclaration(property),
|
|
119
116
|
value: getValue()
|
|
120
117
|
});
|
|
121
118
|
return args;
|
|
122
119
|
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Trims the property value. Converts it to camelCase if it isn't a variable.
|
|
123
|
+
*/
|
|
124
|
+
var getPropertyForDeclaration = function getPropertyForDeclaration(property) {
|
|
125
|
+
var trimmed = property.trim();
|
|
126
|
+
if (trimmed.startsWith('--')) {
|
|
127
|
+
return trimmed;
|
|
128
|
+
}
|
|
129
|
+
// Make the property camelCase if it isn't a CSS variable
|
|
130
|
+
return trimmed.replace(/-[a-z]/g, function (match) {
|
|
131
|
+
return match[1].toUpperCase();
|
|
132
|
+
});
|
|
133
|
+
};
|
|
123
134
|
var getSelectorValue = function getSelectorValue(chars, expressions) {
|
|
124
135
|
// If no variable, returns chars immediately.
|
|
125
136
|
// i.e. `.foo { color: red }` returns '.foo'
|
|
@@ -78,6 +78,16 @@ export var isCssInJsObjectNode = function isCssInJsObjectNode(node) {
|
|
|
78
78
|
var isXcssCallNode = function isXcssCallNode(node) {
|
|
79
79
|
return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'xcss';
|
|
80
80
|
};
|
|
81
|
+
export var isDecendantOfXcssBlock = function isDecendantOfXcssBlock(node) {
|
|
82
|
+
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
83
|
+
if (isXcssCallNode(node)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (node.parent) {
|
|
87
|
+
return isDecendantOfXcssBlock(node.parent);
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
};
|
|
81
91
|
export var isDecendantOfStyleBlock = function isDecendantOfStyleBlock(node) {
|
|
82
92
|
if (node.type === 'VariableDeclarator') {
|
|
83
93
|
if (node.id.type !== 'Identifier') {
|
|
@@ -106,11 +116,6 @@ export var isDecendantOfStyleBlock = function isDecendantOfStyleBlock(node) {
|
|
|
106
116
|
return varName.includes(el);
|
|
107
117
|
});
|
|
108
118
|
}
|
|
109
|
-
|
|
110
|
-
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
111
|
-
if (isXcssCallNode(node)) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
119
|
if (isCssInJsCallNode(node) || isCssInJsObjectNode(node) || isCssInJsTemplateNode(node)) {
|
|
115
120
|
return true;
|
|
116
121
|
}
|
|
@@ -9,5 +9,6 @@ export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.Rul
|
|
|
9
9
|
export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
|
|
10
10
|
export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
|
|
11
11
|
export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
|
|
12
|
+
export declare const isDecendantOfXcssBlock: (node: Rule.Node) => boolean;
|
|
12
13
|
export declare const isDecendantOfStyleBlock: (node: Rule.Node) => boolean;
|
|
13
14
|
export declare const isChildOfType: (node: Rule.Node, type: Rule.Node['type']) => boolean;
|
|
@@ -9,5 +9,6 @@ export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.Rul
|
|
|
9
9
|
export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
|
|
10
10
|
export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
|
|
11
11
|
export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
|
|
12
|
+
export declare const isDecendantOfXcssBlock: (node: Rule.Node) => boolean;
|
|
12
13
|
export declare const isDecendantOfStyleBlock: (node: Rule.Node) => boolean;
|
|
13
14
|
export declare const isChildOfType: (node: Rule.Node, type: Rule.Node['type']) => boolean;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-design-system",
|
|
3
3
|
"description": "The essential plugin for use with the Atlassian Design System.",
|
|
4
|
-
"version": "8.36.
|
|
4
|
+
"version": "8.36.3",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|