@atlaskit/eslint-plugin-design-system 8.36.0 → 8.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +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/color.js +5 -0
- 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/index.js +1 -1
- package/dist/cjs/rules/utils/is-node.js +28 -6
- package/dist/es2019/rules/consistent-css-prop-usage/index.js +8 -1
- package/dist/es2019/rules/ensure-design-token-usage/color.js +6 -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/index.js +6 -8
- package/dist/es2019/rules/utils/is-node.js +27 -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/color.js +6 -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/index.js +1 -1
- package/dist/esm/rules/utils/is-node.js +27 -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 +2 -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 +2 -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.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#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.
|
|
8
|
+
- [#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.
|
|
9
|
+
- [#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-…`
|
|
10
|
+
|
|
11
|
+
## 8.36.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#79810](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/79810) [`8c6e96aa3cf0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8c6e96aa3cf0) - Fixed an issue with `ensure-design-token-usage` where color props on primitive components could report an error.
|
|
16
|
+
|
|
3
17
|
## 8.36.0
|
|
4
18
|
|
|
5
19
|
### Minor 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',
|
|
@@ -143,6 +143,11 @@ var lintJSXLiteralForColor = exports.lintJSXLiteralForColor = function lintJSXLi
|
|
|
143
143
|
if ((0, _isNode.isDecendantOfSvgElement)(node.parent)) {
|
|
144
144
|
return;
|
|
145
145
|
}
|
|
146
|
+
|
|
147
|
+
// Box backgroundColor prop accepts token names directly - don't lint against this
|
|
148
|
+
if ((0, _isNode.isDecendantOfPrimitive)(node.parent, context)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
146
151
|
if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
|
|
147
152
|
return;
|
|
148
153
|
}
|
|
@@ -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 = {
|
|
@@ -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
|
}
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.isPropertyKey = exports.isDecendantOfType = exports.isDecendantOfSvgElement = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = 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
|
+
var _astNodes = require("../../ast-nodes");
|
|
8
9
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
9
10
|
|
|
10
11
|
var isDecendantOfGlobalToken = exports.isDecendantOfGlobalToken = function isDecendantOfGlobalToken(node) {
|
|
@@ -54,6 +55,22 @@ var isDecendantOfSvgElement = exports.isDecendantOfSvgElement = function isDecen
|
|
|
54
55
|
}
|
|
55
56
|
return false;
|
|
56
57
|
};
|
|
58
|
+
var isDecendantOfPrimitive = exports.isDecendantOfPrimitive = function isDecendantOfPrimitive(node, context) {
|
|
59
|
+
var primitivesToCheck = ['Box', 'Text'];
|
|
60
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
if (primitivesToCheck.includes(node.openingElement.name.name)) {
|
|
63
|
+
var importDeclaration = _astNodes.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
64
|
+
if (importDeclaration.length) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (node.parent) {
|
|
70
|
+
return isDecendantOfPrimitive(node.parent, context);
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
};
|
|
57
74
|
var cssInJsCallees = ['css', 'styled', 'styled2'];
|
|
58
75
|
var isCssInJsTemplateNode = exports.isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
|
|
59
76
|
return (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
|
|
@@ -67,6 +84,16 @@ var isCssInJsObjectNode = exports.isCssInJsObjectNode = function isCssInJsObject
|
|
|
67
84
|
var isXcssCallNode = function isXcssCallNode(node) {
|
|
68
85
|
return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'xcss';
|
|
69
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
|
+
};
|
|
70
97
|
var isDecendantOfStyleBlock = exports.isDecendantOfStyleBlock = function isDecendantOfStyleBlock(node) {
|
|
71
98
|
if (node.type === 'VariableDeclarator') {
|
|
72
99
|
if (node.id.type !== 'Identifier') {
|
|
@@ -95,11 +122,6 @@ var isDecendantOfStyleBlock = exports.isDecendantOfStyleBlock = function isDecen
|
|
|
95
122
|
return varName.includes(el);
|
|
96
123
|
});
|
|
97
124
|
}
|
|
98
|
-
|
|
99
|
-
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
100
|
-
if (isXcssCallNode(node)) {
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
125
|
if (isCssInJsCallNode(node) || isCssInJsObjectNode(node) || isCssInJsTemplateNode(node)) {
|
|
104
126
|
return true;
|
|
105
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',
|
|
@@ -4,7 +4,7 @@ import { node as generate, isNodeOfType } from 'eslint-codemod-utils';
|
|
|
4
4
|
import { getIsException } from '../utils/get-is-exception';
|
|
5
5
|
import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
|
|
6
6
|
import { isLegacyElevation } from '../utils/is-elevation';
|
|
7
|
-
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
|
|
7
|
+
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfPrimitive, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
|
|
8
8
|
// TemplateLiteral > Identifier
|
|
9
9
|
export const lintTemplateIdentifierForColor = (node, context, config) => {
|
|
10
10
|
if (node.type !== 'Identifier') {
|
|
@@ -138,6 +138,11 @@ export const lintJSXLiteralForColor = (node, context, config) => {
|
|
|
138
138
|
if (isDecendantOfSvgElement(node.parent)) {
|
|
139
139
|
return;
|
|
140
140
|
}
|
|
141
|
+
|
|
142
|
+
// Box backgroundColor prop accepts token names directly - don't lint against this
|
|
143
|
+
if (isDecendantOfPrimitive(node.parent, context)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
141
146
|
if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
|
|
142
147
|
return;
|
|
143
148
|
}
|
|
@@ -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,
|
|
@@ -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;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
2
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
|
+
import { Root } from '../../ast-nodes';
|
|
4
5
|
export const isDecendantOfGlobalToken = node => {
|
|
5
6
|
if (isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'token' || node.callee.name === 'getTokenValue')) {
|
|
6
7
|
return true;
|
|
@@ -47,11 +48,37 @@ export const isDecendantOfSvgElement = node => {
|
|
|
47
48
|
}
|
|
48
49
|
return false;
|
|
49
50
|
};
|
|
51
|
+
export const isDecendantOfPrimitive = (node, context) => {
|
|
52
|
+
const primitivesToCheck = ['Box', 'Text'];
|
|
53
|
+
if (isNodeOfType(node, 'JSXElement')) {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
if (primitivesToCheck.includes(node.openingElement.name.name)) {
|
|
56
|
+
const importDeclaration = Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
57
|
+
if (importDeclaration.length) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (node.parent) {
|
|
63
|
+
return isDecendantOfPrimitive(node.parent, context);
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
50
67
|
const cssInJsCallees = ['css', 'styled', 'styled2'];
|
|
51
68
|
export const isCssInJsTemplateNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
|
|
52
69
|
export const isCssInJsCallNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && cssInJsCallees.includes(node.callee.name);
|
|
53
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);
|
|
54
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
|
+
};
|
|
55
82
|
export const isDecendantOfStyleBlock = node => {
|
|
56
83
|
if (node.type === 'VariableDeclarator') {
|
|
57
84
|
if (node.id.type !== 'Identifier') {
|
|
@@ -76,11 +103,6 @@ export const isDecendantOfStyleBlock = node => {
|
|
|
76
103
|
const varName = node.id.name.toLowerCase();
|
|
77
104
|
return ['style', 'css', 'theme'].some(el => varName.includes(el));
|
|
78
105
|
}
|
|
79
|
-
|
|
80
|
-
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
81
|
-
if (isXcssCallNode(node)) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
106
|
if (isCssInJsCallNode(node) || isCssInJsObjectNode(node) || isCssInJsTemplateNode(node)) {
|
|
85
107
|
return true;
|
|
86
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 { node as generate, isNodeOfType } from 'eslint-codemod-utils';
|
|
|
4
4
|
import { getIsException } from '../utils/get-is-exception';
|
|
5
5
|
import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
|
|
6
6
|
import { isLegacyElevation } from '../utils/is-elevation';
|
|
7
|
-
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
|
|
7
|
+
import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfPrimitive, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
|
|
8
8
|
// TemplateLiteral > Identifier
|
|
9
9
|
export var lintTemplateIdentifierForColor = function lintTemplateIdentifierForColor(node, context, config) {
|
|
10
10
|
if (node.type !== 'Identifier') {
|
|
@@ -137,6 +137,11 @@ export var lintJSXLiteralForColor = function lintJSXLiteralForColor(node, contex
|
|
|
137
137
|
if (isDecendantOfSvgElement(node.parent)) {
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
+
|
|
141
|
+
// Box backgroundColor prop accepts token names directly - don't lint against this
|
|
142
|
+
if (isDecendantOfPrimitive(node.parent, context)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
140
145
|
if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
|
|
141
146
|
return;
|
|
142
147
|
}
|
|
@@ -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;
|
|
@@ -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
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
2
|
|
|
3
3
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
|
+
import { Root } from '../../ast-nodes';
|
|
4
5
|
export var isDecendantOfGlobalToken = function isDecendantOfGlobalToken(node) {
|
|
5
6
|
if (isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'token' || node.callee.name === 'getTokenValue')) {
|
|
6
7
|
return true;
|
|
@@ -48,6 +49,22 @@ export var isDecendantOfSvgElement = function isDecendantOfSvgElement(node) {
|
|
|
48
49
|
}
|
|
49
50
|
return false;
|
|
50
51
|
};
|
|
52
|
+
export var isDecendantOfPrimitive = function isDecendantOfPrimitive(node, context) {
|
|
53
|
+
var primitivesToCheck = ['Box', 'Text'];
|
|
54
|
+
if (isNodeOfType(node, 'JSXElement')) {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
if (primitivesToCheck.includes(node.openingElement.name.name)) {
|
|
57
|
+
var importDeclaration = Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
|
|
58
|
+
if (importDeclaration.length) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (node.parent) {
|
|
64
|
+
return isDecendantOfPrimitive(node.parent, context);
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
51
68
|
var cssInJsCallees = ['css', 'styled', 'styled2'];
|
|
52
69
|
export var isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
|
|
53
70
|
return (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
|
|
@@ -61,6 +78,16 @@ export var isCssInJsObjectNode = function isCssInJsObjectNode(node) {
|
|
|
61
78
|
var isXcssCallNode = function isXcssCallNode(node) {
|
|
62
79
|
return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'xcss';
|
|
63
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
|
+
};
|
|
64
91
|
export var isDecendantOfStyleBlock = function isDecendantOfStyleBlock(node) {
|
|
65
92
|
if (node.type === 'VariableDeclarator') {
|
|
66
93
|
if (node.id.type !== 'Identifier') {
|
|
@@ -89,11 +116,6 @@ export var isDecendantOfStyleBlock = function isDecendantOfStyleBlock(node) {
|
|
|
89
116
|
return varName.includes(el);
|
|
90
117
|
});
|
|
91
118
|
}
|
|
92
|
-
|
|
93
|
-
// xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
|
|
94
|
-
if (isXcssCallNode(node)) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
119
|
if (isCssInJsCallNode(node) || isCssInJsObjectNode(node) || isCssInJsTemplateNode(node)) {
|
|
98
120
|
return true;
|
|
99
121
|
}
|
|
@@ -5,8 +5,10 @@ export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'
|
|
|
5
5
|
export declare const isPropertyKey: (node: Rule.Node) => boolean;
|
|
6
6
|
export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
|
|
7
7
|
export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
|
|
8
|
+
export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.RuleContext) => boolean;
|
|
8
9
|
export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
|
|
9
10
|
export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
|
|
10
11
|
export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
|
|
12
|
+
export declare const isDecendantOfXcssBlock: (node: Rule.Node) => boolean;
|
|
11
13
|
export declare const isDecendantOfStyleBlock: (node: Rule.Node) => boolean;
|
|
12
14
|
export declare const isChildOfType: (node: Rule.Node, type: Rule.Node['type']) => boolean;
|
|
@@ -5,8 +5,10 @@ export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'
|
|
|
5
5
|
export declare const isPropertyKey: (node: Rule.Node) => boolean;
|
|
6
6
|
export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
|
|
7
7
|
export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
|
|
8
|
+
export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.RuleContext) => boolean;
|
|
8
9
|
export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
|
|
9
10
|
export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
|
|
10
11
|
export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
|
|
12
|
+
export declare const isDecendantOfXcssBlock: (node: Rule.Node) => boolean;
|
|
11
13
|
export declare const isDecendantOfStyleBlock: (node: Rule.Node) => boolean;
|
|
12
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.2",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"registry": "https://registry.npmjs.org/"
|