@atlaskit/eslint-plugin-ui-styling-standard 1.4.1 → 1.4.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 +17 -0
- package/README.md +1 -1
- package/dist/cjs/index.js +1 -2
- package/dist/cjs/presets/all-flat.codegen.js +1 -2
- package/dist/cjs/presets/recommended-flat.codegen.js +1 -2
- package/dist/cjs/rules/enforce-style-prop/index.js +65 -49
- package/dist/cjs/rules/no-array-arguments/index.js +1 -1
- package/dist/cjs/rules/no-container-queries/index.js +0 -2
- package/dist/cjs/rules/no-dynamic-styles/index.js +1 -1
- package/dist/cjs/rules/no-exported-styles/index.js +0 -2
- package/dist/cjs/rules/no-imported-style-values/index.js +1 -2
- package/dist/cjs/rules/no-nested-selectors/index.js +1 -2
- package/dist/cjs/rules/no-unsafe-values/index.js +0 -2
- package/dist/cjs/rules/no-unsafe-values/messages.js +2 -2
- package/dist/cjs/rules/use-compiled/index.js +4 -3
- package/dist/es2019/rules/enforce-style-prop/index.js +59 -43
- package/dist/es2019/rules/no-array-arguments/index.js +0 -2
- package/dist/es2019/rules/no-container-queries/index.js +0 -2
- package/dist/es2019/rules/no-dynamic-styles/index.js +0 -1
- package/dist/es2019/rules/no-exported-styles/index.js +0 -2
- package/dist/es2019/rules/no-imported-style-values/index.js +0 -4
- package/dist/es2019/rules/no-unsafe-values/index.js +0 -2
- package/dist/es2019/rules/use-compiled/index.js +4 -3
- package/dist/esm/rules/enforce-style-prop/index.js +61 -45
- package/dist/esm/rules/no-array-arguments/index.js +0 -2
- package/dist/esm/rules/no-container-queries/index.js +0 -2
- package/dist/esm/rules/no-dynamic-styles/index.js +0 -1
- package/dist/esm/rules/no-exported-styles/index.js +0 -2
- package/dist/esm/rules/no-imported-style-values/index.js +0 -4
- package/dist/esm/rules/no-unsafe-values/index.js +0 -2
- package/dist/esm/rules/no-unsafe-values/messages.js +2 -2
- package/dist/esm/rules/use-compiled/index.js +4 -3
- package/dist/types/rules/no-unsafe-values/utils.d.ts +1 -1
- package/dist/types-ts4.5/rules/no-unsafe-values/utils.d.ts +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 1.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#192710](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/192710)
|
|
8
|
+
[`b3b30f3bc4453`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b3b30f3bc4453) -
|
|
9
|
+
Internal changes to how border radius and border width values are applied. No visual change.
|
|
10
|
+
|
|
11
|
+
## 1.4.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#120084](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/120084)
|
|
16
|
+
[`ee978d7b2ba83`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ee978d7b2ba83) -
|
|
17
|
+
Support BinaryExpression and ConditionalExpression logic when inspecting if an Identifier is
|
|
18
|
+
static.
|
|
19
|
+
|
|
3
20
|
## 1.4.1
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ module.exports = {
|
|
|
58
58
|
| <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-styled/README.md">no-styled</a> | Disallows usage of the `styled` imports | Yes | | |
|
|
59
59
|
| <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-unsafe-selectors/README.md">no-unsafe-selectors</a> | Disallows use of nested styles in `css` functions. | Yes | Yes | Yes |
|
|
60
60
|
| <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/no-unsafe-values/README.md">no-unsafe-values</a> | Disallows styles that are difficult/impossible to statically anaylze. | Yes | | |
|
|
61
|
-
| <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries
|
|
61
|
+
| <a href="./packages/design-system/eslint-plugin-ui-styling-standard/src/rules/use-compiled/README.md">use-compiled</a> | Ensures usage of `@compiled/react` or `@atlaskit/css` instead of other CSS-in-JS libraries | Yes | Yes | |
|
|
62
62
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/consistent-css-prop-usage/usage">@atlaskit/design-system/consistent-css-prop-usage</a> | Ensures consistency with `css` and `xcss` prop usages | Yes | Yes | |
|
|
63
63
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-css-tagged-template-expression/usage">@atlaskit/design-system/no-css-tagged-template-expression</a> | Disallows any `css` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
|
64
64
|
| <a href="https://atlassian.design/components/eslint-plugin-ui-styling-standard/no-keyframes-tagged-template-expression/usage">@atlaskit/design-system/no-keyframes-tagged-template-expression</a> | Disallows any `keyframe` tagged template expressions that originate from Emotion, Styled Components or Compiled | Yes | Yes | |
|
package/dist/cjs/index.js
CHANGED
|
@@ -35,5 +35,4 @@ Object.defineProperty(exports, "rules", {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
var _index = _interopRequireWildcard(require("./index.codegen"));
|
|
38
|
-
function
|
|
39
|
-
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 && {}.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; }
|
|
38
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/eslint-plugin-design-system"));
|
|
9
|
-
function
|
|
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 && {}.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; }
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
11
10
|
/**
|
|
12
11
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
13
12
|
* @codegen <<SignedSource::4595bc1a07f9da4186e2df84cea56831>>
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/eslint-plugin-design-system"));
|
|
9
|
-
function
|
|
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 && {}.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; }
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
11
10
|
/**
|
|
12
11
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
13
12
|
* @codegen <<SignedSource::4595bc1a07f9da4186e2df84cea56831>>
|
|
@@ -7,70 +7,86 @@ exports.rule = exports.default = void 0;
|
|
|
7
7
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
8
|
var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
|
|
9
9
|
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
10
|
-
var
|
|
10
|
+
var _findVariable2 = require("@atlaskit/eslint-utils/find-variable");
|
|
11
11
|
var _createRule = require("../utils/create-rule");
|
|
12
|
-
var
|
|
13
|
-
var _findVariable;
|
|
14
|
-
var definitions = (_findVariable = (0, _findVariable3.findVariable)({
|
|
15
|
-
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
16
|
-
identifier: identifier
|
|
17
|
-
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
18
|
-
if (!definitions || !definitions.length) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
var result = definitions[0];
|
|
22
|
-
return result.type === 'Parameter';
|
|
23
|
-
};
|
|
24
|
-
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
12
|
+
var _isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
25
13
|
var _variable$identifiers;
|
|
26
|
-
var variable = (0,
|
|
14
|
+
var variable = (0, _findVariable2.findVariable)({
|
|
27
15
|
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
28
16
|
identifier: identifier
|
|
29
17
|
});
|
|
30
18
|
if (!variable) {
|
|
31
19
|
return false;
|
|
32
20
|
}
|
|
33
|
-
var variableDefinition = variable.defs[0].node;
|
|
34
21
|
|
|
35
22
|
// If identifier is a RestElement, report warning
|
|
36
23
|
if (((_variable$identifiers = variable.identifiers[0]) === null || _variable$identifiers === void 0 || (_variable$identifiers = _variable$identifiers.parent) === null || _variable$identifiers === void 0 ? void 0 : _variable$identifiers.type) === 'RestElement') {
|
|
37
24
|
return false;
|
|
38
25
|
}
|
|
26
|
+
var firstDef = variable.defs[0];
|
|
27
|
+
if (firstDef.type === 'Parameter') {
|
|
28
|
+
// This ultimately comes from a function parameter, eg. `const value = props.value`
|
|
29
|
+
// ultimately finds this `function (props)` or `function({ width })` and those are parameters
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (firstDef.type !== 'Variable') {
|
|
33
|
+
// If this isn't a variable, eg. not `const value = props.value`, it's not an identifier we can track
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
var variableDefinition = firstDef.node;
|
|
37
|
+
if (variableDefinition.type !== 'VariableDeclarator') {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
39
40
|
|
|
40
41
|
// Checking if identifier has been destructured from props within function
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
42
|
+
// If it's a `let var = …`, ignore, we assume it's dynamically set (but it could be static)
|
|
43
|
+
if ('kind' in variableDefinition.parent && variableDefinition.parent.kind === 'let') {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
// Allow for `const { width } = props as Props` (etc)
|
|
48
|
+
var init = variableDefinition.init;
|
|
49
|
+
|
|
50
|
+
// This is not typed for TS types
|
|
51
|
+
if (init.type === 'TSAsExpression' && 'expression' in init && typeof init.expression !== 'boolean') {
|
|
52
|
+
init = init.expression;
|
|
53
|
+
}
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// If it's initialised by a call expression, ignore
|
|
56
|
+
if (init.type === 'CallExpression') {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (init.type === 'BinaryExpression') {
|
|
60
|
+
// If it's initialized like `const var = 1 * props.value`, validate either side
|
|
61
|
+
if (init.left.type === 'MemberExpression') {
|
|
62
|
+
return _isIdentifierAllowed(context, init.left.object);
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (((_init3 = init) === null || _init3 === void 0 ? void 0 : _init3.type) === 'MemberExpression') {
|
|
61
|
-
return isParameter(context, init.object);
|
|
64
|
+
if (init.right.type === 'MemberExpression') {
|
|
65
|
+
return _isIdentifierAllowed(context, init.right.object);
|
|
62
66
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
}
|
|
68
|
+
if (init.type === 'ConditionalExpression') {
|
|
69
|
+
// If it's initialized like `const var = props.value ? 42 : 1`, validate either side
|
|
70
|
+
if (init.test.type === 'MemberExpression') {
|
|
71
|
+
return _isIdentifierAllowed(context, init.test.object);
|
|
72
|
+
}
|
|
73
|
+
if (init.consequent.type === 'MemberExpression') {
|
|
74
|
+
return _isIdentifierAllowed(context, init.consequent.object);
|
|
75
|
+
}
|
|
76
|
+
if (init.alternate.type === 'MemberExpression') {
|
|
77
|
+
return _isIdentifierAllowed(context, init.alternate.object);
|
|
67
78
|
}
|
|
68
|
-
// Destructured from object pattern
|
|
69
|
-
// e.g. const { width } = props
|
|
70
|
-
return isParameter(context, init);
|
|
71
79
|
}
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
|
|
81
|
+
// Destructured from member expression
|
|
82
|
+
// e.g. const width = props.width
|
|
83
|
+
if (init.type === 'MemberExpression') {
|
|
84
|
+
return _isIdentifierAllowed(context, init.object);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Destructured from object pattern
|
|
88
|
+
// e.g. const { width } = props
|
|
89
|
+
return _isIdentifierAllowed(context, init);
|
|
74
90
|
};
|
|
75
91
|
function isPropertyValueAllowed(property, context) {
|
|
76
92
|
if (property.type === 'SpreadElement') {
|
|
@@ -81,9 +97,9 @@ function isPropertyValueAllowed(property, context) {
|
|
|
81
97
|
if (property.value.type === 'Literal') {
|
|
82
98
|
return false;
|
|
83
99
|
} else if (property.value.type === 'Identifier') {
|
|
84
|
-
return
|
|
100
|
+
return _isIdentifierAllowed(context, property.value);
|
|
85
101
|
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
86
|
-
var variable = (0,
|
|
102
|
+
var variable = (0, _findVariable2.findVariable)({
|
|
87
103
|
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
88
104
|
identifier: property.value.callee
|
|
89
105
|
});
|
|
@@ -96,11 +112,11 @@ function isPropertyValueAllowed(property, context) {
|
|
|
96
112
|
return false;
|
|
97
113
|
}
|
|
98
114
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
99
|
-
var
|
|
100
|
-
var definitions = (
|
|
115
|
+
var _findVariable;
|
|
116
|
+
var definitions = (_findVariable = (0, _findVariable2.findVariable)({
|
|
101
117
|
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
102
118
|
identifier: property.value.object
|
|
103
|
-
})) === null ||
|
|
119
|
+
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
104
120
|
if (!definitions || !definitions.length) {
|
|
105
121
|
return false;
|
|
106
122
|
}
|
|
@@ -170,7 +186,7 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
170
186
|
* <div style={style} />
|
|
171
187
|
* ```
|
|
172
188
|
*/
|
|
173
|
-
var variable = (0,
|
|
189
|
+
var variable = (0, _findVariable2.findVariable)({
|
|
174
190
|
sourceCode: (0, _contextCompat.getSourceCode)(context),
|
|
175
191
|
identifier: node.expression
|
|
176
192
|
});
|
|
@@ -9,7 +9,7 @@ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
|
9
9
|
var _createRule = require("../utils/create-rule");
|
|
10
10
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
11
11
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
12
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
12
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
13
13
|
var schema = [{
|
|
14
14
|
type: 'object',
|
|
15
15
|
properties: {
|
|
@@ -9,8 +9,6 @@ var _estraverse = _interopRequireDefault(require("estraverse"));
|
|
|
9
9
|
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
10
10
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
11
11
|
var _createRule = require("../utils/create-rule");
|
|
12
|
-
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
13
|
-
|
|
14
12
|
var schema = [{
|
|
15
13
|
type: 'object',
|
|
16
14
|
properties: {
|
|
@@ -11,7 +11,7 @@ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
|
11
11
|
var _createRule = require("../utils/create-rule");
|
|
12
12
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
13
13
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
14
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
14
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
15
|
var schema = [{
|
|
16
16
|
type: 'object',
|
|
17
17
|
properties: {
|
|
@@ -7,8 +7,6 @@ exports.rule = exports.default = void 0;
|
|
|
7
7
|
var _createNoExportedRule = require("@atlaskit/eslint-utils/create-no-exported-rule");
|
|
8
8
|
var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
9
9
|
var _createRule = require("../utils/create-rule");
|
|
10
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
11
|
-
|
|
12
10
|
var schema = [{
|
|
13
11
|
type: 'object',
|
|
14
12
|
properties: {
|
|
@@ -14,8 +14,7 @@ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
|
14
14
|
var _createRule = require("../utils/create-rule");
|
|
15
15
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
16
16
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
17
|
-
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
18
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
17
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
19
18
|
var schema = [{
|
|
20
19
|
type: 'object',
|
|
21
20
|
properties: {
|
|
@@ -12,8 +12,7 @@ var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
|
12
12
|
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
13
13
|
var _walkStyleProperties = require("@atlaskit/eslint-utils/walk-style-properties");
|
|
14
14
|
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
15
|
-
function
|
|
16
|
-
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 && {}.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
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
17
16
|
var getCssSelector = function getCssSelector(key) {
|
|
18
17
|
if (key.type === 'Literal' && typeof key.value === 'string') {
|
|
19
18
|
return key.value;
|
|
@@ -9,8 +9,6 @@ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
|
|
|
9
9
|
var _createRule = require("../utils/create-rule");
|
|
10
10
|
var _messages = require("./messages");
|
|
11
11
|
var _utils = require("./utils");
|
|
12
|
-
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
13
|
-
|
|
14
12
|
var schema = [{
|
|
15
13
|
type: 'object',
|
|
16
14
|
additionalProperties: false,
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.messages = void 0;
|
|
8
8
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
9
9
|
var _outdent = _interopRequireDefault(require("outdent"));
|
|
10
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9,
|
|
10
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject0;
|
|
11
11
|
var whereToGetHelp = "If you think this should be allowed, or if you're running into issues, reach out in #help-ui-styling-standard";
|
|
12
12
|
var messages = exports.messages = {
|
|
13
13
|
'no-array-values': (0, _outdent.default)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n Arrays are not allowed in style objects. Support is inconsistent between styling libraries.\n\n Compose styles with the css prop instead.\n\n ", "\n "])), whereToGetHelp),
|
|
@@ -20,5 +20,5 @@ var messages = exports.messages = {
|
|
|
20
20
|
'no-spread-elements': (0, _outdent.default)(_templateObject8 || (_templateObject8 = (0, _taggedTemplateLiteral2.default)(["\n Spread elements are not allowed in style objects.\n\n Compose styles with the css prop instead.\n\n ", "\n "])), whereToGetHelp),
|
|
21
21
|
// Fallback case if a more specific message is not applicable
|
|
22
22
|
'no-unsafe-values': (0, _outdent.default)(_templateObject9 || (_templateObject9 = (0, _taggedTemplateLiteral2.default)(["\n Unsafe values are not allowed in style objects.\n\n ", "\n "])), whereToGetHelp),
|
|
23
|
-
'no-variables': (0, _outdent.default)(
|
|
23
|
+
'no-variables': (0, _outdent.default)(_templateObject0 || (_templateObject0 = (0, _taggedTemplateLiteral2.default)(["\n Variables are not allowed in style objects, unless they:\n\n - Have a simple, static value.\n - Are defined in the same file.\n\n Use the style prop to apply dynamic values instead.\n\n ", "\n "])), whereToGetHelp)
|
|
24
24
|
};
|
|
@@ -51,12 +51,12 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
51
51
|
type: 'problem',
|
|
52
52
|
fixable: 'code',
|
|
53
53
|
docs: {
|
|
54
|
-
description: 'Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries',
|
|
54
|
+
description: 'Ensures usage of `@compiled/react` or `@atlaskit/css` instead of other CSS-in-JS libraries',
|
|
55
55
|
recommended: true,
|
|
56
56
|
severity: 'error'
|
|
57
57
|
},
|
|
58
58
|
messages: {
|
|
59
|
-
'use-compiled': "Use '@compiled/react' instead of '{{importSource}}'"
|
|
59
|
+
'use-compiled': "Use '@atlaskit/css' or '@compiled/react' instead of '{{importSource}}'"
|
|
60
60
|
},
|
|
61
61
|
schema: schema
|
|
62
62
|
},
|
|
@@ -105,7 +105,8 @@ var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
|
105
105
|
case 7:
|
|
106
106
|
_context.next = 9;
|
|
107
107
|
return fixer.replaceText(
|
|
108
|
-
//
|
|
108
|
+
// TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
|
|
109
|
+
// @ts-ignore - types don't accept comment nodes
|
|
109
110
|
pragma, "/** @jsxImportSource @compiled/react */");
|
|
110
111
|
case 9:
|
|
111
112
|
case "end":
|
|
@@ -3,18 +3,6 @@ import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint
|
|
|
3
3
|
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
4
4
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
5
5
|
import { createLintRule } from '../utils/create-rule';
|
|
6
|
-
const isParameter = (context, identifier) => {
|
|
7
|
-
var _findVariable;
|
|
8
|
-
const definitions = (_findVariable = findVariable({
|
|
9
|
-
sourceCode: getSourceCode(context),
|
|
10
|
-
identifier: identifier
|
|
11
|
-
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
12
|
-
if (!definitions || !definitions.length) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
const result = definitions[0];
|
|
16
|
-
return result.type === 'Parameter';
|
|
17
|
-
};
|
|
18
6
|
const isIdentifierAllowed = (context, identifier) => {
|
|
19
7
|
var _variable$identifiers, _variable$identifiers2;
|
|
20
8
|
const variable = findVariable({
|
|
@@ -24,47 +12,75 @@ const isIdentifierAllowed = (context, identifier) => {
|
|
|
24
12
|
if (!variable) {
|
|
25
13
|
return false;
|
|
26
14
|
}
|
|
27
|
-
const variableDefinition = variable.defs[0].node;
|
|
28
15
|
|
|
29
16
|
// If identifier is a RestElement, report warning
|
|
30
17
|
if (((_variable$identifiers = variable.identifiers[0]) === null || _variable$identifiers === void 0 ? void 0 : (_variable$identifiers2 = _variable$identifiers.parent) === null || _variable$identifiers2 === void 0 ? void 0 : _variable$identifiers2.type) === 'RestElement') {
|
|
31
18
|
return false;
|
|
32
19
|
}
|
|
20
|
+
const firstDef = variable.defs[0];
|
|
21
|
+
if (firstDef.type === 'Parameter') {
|
|
22
|
+
// This ultimately comes from a function parameter, eg. `const value = props.value`
|
|
23
|
+
// ultimately finds this `function (props)` or `function({ width })` and those are parameters
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (firstDef.type !== 'Variable') {
|
|
27
|
+
// If this isn't a variable, eg. not `const value = props.value`, it's not an identifier we can track
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const variableDefinition = firstDef.node;
|
|
31
|
+
if (variableDefinition.type !== 'VariableDeclarator') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
33
34
|
|
|
34
35
|
// Checking if identifier has been destructured from props within function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
36
|
+
// If it's a `let var = …`, ignore, we assume it's dynamically set (but it could be static)
|
|
37
|
+
if ('kind' in variableDefinition.parent && variableDefinition.parent.kind === 'let') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
// Allow for `const { width } = props as Props` (etc)
|
|
42
|
+
let init = variableDefinition.init;
|
|
43
|
+
|
|
44
|
+
// This is not typed for TS types
|
|
45
|
+
if (init.type === 'TSAsExpression' && 'expression' in init && typeof init.expression !== 'boolean') {
|
|
46
|
+
init = init.expression;
|
|
47
|
+
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
// If it's initialised by a call expression, ignore
|
|
50
|
+
if (init.type === 'CallExpression') {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (init.type === 'BinaryExpression') {
|
|
54
|
+
// If it's initialized like `const var = 1 * props.value`, validate either side
|
|
55
|
+
if (init.left.type === 'MemberExpression') {
|
|
56
|
+
return isIdentifierAllowed(context, init.left.object);
|
|
51
57
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (((_init3 = init) === null || _init3 === void 0 ? void 0 : _init3.type) === 'MemberExpression') {
|
|
55
|
-
return isParameter(context, init.object);
|
|
58
|
+
if (init.right.type === 'MemberExpression') {
|
|
59
|
+
return isIdentifierAllowed(context, init.right.object);
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
}
|
|
62
|
+
if (init.type === 'ConditionalExpression') {
|
|
63
|
+
// If it's initialized like `const var = props.value ? 42 : 1`, validate either side
|
|
64
|
+
if (init.test.type === 'MemberExpression') {
|
|
65
|
+
return isIdentifierAllowed(context, init.test.object);
|
|
66
|
+
}
|
|
67
|
+
if (init.consequent.type === 'MemberExpression') {
|
|
68
|
+
return isIdentifierAllowed(context, init.consequent.object);
|
|
69
|
+
}
|
|
70
|
+
if (init.alternate.type === 'MemberExpression') {
|
|
71
|
+
return isIdentifierAllowed(context, init.alternate.object);
|
|
61
72
|
}
|
|
62
|
-
// Destructured from object pattern
|
|
63
|
-
// e.g. const { width } = props
|
|
64
|
-
return isParameter(context, init);
|
|
65
73
|
}
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
|
|
75
|
+
// Destructured from member expression
|
|
76
|
+
// e.g. const width = props.width
|
|
77
|
+
if (init.type === 'MemberExpression') {
|
|
78
|
+
return isIdentifierAllowed(context, init.object);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Destructured from object pattern
|
|
82
|
+
// e.g. const { width } = props
|
|
83
|
+
return isIdentifierAllowed(context, init);
|
|
68
84
|
};
|
|
69
85
|
function isPropertyValueAllowed(property, context) {
|
|
70
86
|
if (property.type === 'SpreadElement') {
|
|
@@ -90,11 +106,11 @@ function isPropertyValueAllowed(property, context) {
|
|
|
90
106
|
return false;
|
|
91
107
|
}
|
|
92
108
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
93
|
-
var
|
|
94
|
-
const definitions = (
|
|
109
|
+
var _findVariable;
|
|
110
|
+
const definitions = (_findVariable = findVariable({
|
|
95
111
|
sourceCode: getSourceCode(context),
|
|
96
112
|
identifier: property.value.object
|
|
97
|
-
})) === null ||
|
|
113
|
+
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
98
114
|
if (!definitions || !definitions.length) {
|
|
99
115
|
return false;
|
|
100
116
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
2
|
-
|
|
3
1
|
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
4
2
|
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
3
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
2
|
-
|
|
3
1
|
import estraverse from 'estraverse';
|
|
4
2
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
3
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
2
1
|
import esquery from 'esquery';
|
|
3
2
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
4
3
|
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
2
|
-
|
|
3
1
|
import { createNoExportedRule } from '@atlaskit/eslint-utils/create-no-exported-rule';
|
|
4
2
|
import { isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
3
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
2
|
-
|
|
3
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
4
|
-
|
|
5
1
|
import esquery from 'esquery';
|
|
6
2
|
import estraverse from 'estraverse';
|
|
7
3
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
2
|
-
|
|
3
1
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
4
2
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
3
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -39,12 +39,12 @@ export const rule = createLintRule({
|
|
|
39
39
|
type: 'problem',
|
|
40
40
|
fixable: 'code',
|
|
41
41
|
docs: {
|
|
42
|
-
description: 'Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries',
|
|
42
|
+
description: 'Ensures usage of `@compiled/react` or `@atlaskit/css` instead of other CSS-in-JS libraries',
|
|
43
43
|
recommended: true,
|
|
44
44
|
severity: 'error'
|
|
45
45
|
},
|
|
46
46
|
messages: {
|
|
47
|
-
'use-compiled': `Use '@compiled/react' instead of '{{importSource}}'`
|
|
47
|
+
'use-compiled': `Use '@atlaskit/css' or '@compiled/react' instead of '{{importSource}}'`
|
|
48
48
|
},
|
|
49
49
|
schema
|
|
50
50
|
},
|
|
@@ -77,7 +77,8 @@ export const rule = createLintRule({
|
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
yield fixer.replaceText(
|
|
80
|
-
//
|
|
80
|
+
// TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
|
|
81
|
+
// @ts-ignore - types don't accept comment nodes
|
|
81
82
|
pragma, `/** @jsxImportSource @compiled/react */`);
|
|
82
83
|
}
|
|
83
84
|
});
|
|
@@ -3,19 +3,7 @@ import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint
|
|
|
3
3
|
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
4
4
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
5
5
|
import { createLintRule } from '../utils/create-rule';
|
|
6
|
-
var
|
|
7
|
-
var _findVariable;
|
|
8
|
-
var definitions = (_findVariable = findVariable({
|
|
9
|
-
sourceCode: getSourceCode(context),
|
|
10
|
-
identifier: identifier
|
|
11
|
-
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
12
|
-
if (!definitions || !definitions.length) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
var result = definitions[0];
|
|
16
|
-
return result.type === 'Parameter';
|
|
17
|
-
};
|
|
18
|
-
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
6
|
+
var _isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
19
7
|
var _variable$identifiers;
|
|
20
8
|
var variable = findVariable({
|
|
21
9
|
sourceCode: getSourceCode(context),
|
|
@@ -24,47 +12,75 @@ var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
|
24
12
|
if (!variable) {
|
|
25
13
|
return false;
|
|
26
14
|
}
|
|
27
|
-
var variableDefinition = variable.defs[0].node;
|
|
28
15
|
|
|
29
16
|
// If identifier is a RestElement, report warning
|
|
30
17
|
if (((_variable$identifiers = variable.identifiers[0]) === null || _variable$identifiers === void 0 || (_variable$identifiers = _variable$identifiers.parent) === null || _variable$identifiers === void 0 ? void 0 : _variable$identifiers.type) === 'RestElement') {
|
|
31
18
|
return false;
|
|
32
19
|
}
|
|
20
|
+
var firstDef = variable.defs[0];
|
|
21
|
+
if (firstDef.type === 'Parameter') {
|
|
22
|
+
// This ultimately comes from a function parameter, eg. `const value = props.value`
|
|
23
|
+
// ultimately finds this `function (props)` or `function({ width })` and those are parameters
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
if (firstDef.type !== 'Variable') {
|
|
27
|
+
// If this isn't a variable, eg. not `const value = props.value`, it's not an identifier we can track
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
var variableDefinition = firstDef.node;
|
|
31
|
+
if (variableDefinition.type !== 'VariableDeclarator') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
33
34
|
|
|
34
35
|
// Checking if identifier has been destructured from props within function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
36
|
+
// If it's a `let var = …`, ignore, we assume it's dynamically set (but it could be static)
|
|
37
|
+
if ('kind' in variableDefinition.parent && variableDefinition.parent.kind === 'let') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
// Allow for `const { width } = props as Props` (etc)
|
|
42
|
+
var init = variableDefinition.init;
|
|
43
|
+
|
|
44
|
+
// This is not typed for TS types
|
|
45
|
+
if (init.type === 'TSAsExpression' && 'expression' in init && typeof init.expression !== 'boolean') {
|
|
46
|
+
init = init.expression;
|
|
47
|
+
}
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
// If it's initialised by a call expression, ignore
|
|
50
|
+
if (init.type === 'CallExpression') {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (init.type === 'BinaryExpression') {
|
|
54
|
+
// If it's initialized like `const var = 1 * props.value`, validate either side
|
|
55
|
+
if (init.left.type === 'MemberExpression') {
|
|
56
|
+
return _isIdentifierAllowed(context, init.left.object);
|
|
51
57
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (((_init3 = init) === null || _init3 === void 0 ? void 0 : _init3.type) === 'MemberExpression') {
|
|
55
|
-
return isParameter(context, init.object);
|
|
58
|
+
if (init.right.type === 'MemberExpression') {
|
|
59
|
+
return _isIdentifierAllowed(context, init.right.object);
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
}
|
|
62
|
+
if (init.type === 'ConditionalExpression') {
|
|
63
|
+
// If it's initialized like `const var = props.value ? 42 : 1`, validate either side
|
|
64
|
+
if (init.test.type === 'MemberExpression') {
|
|
65
|
+
return _isIdentifierAllowed(context, init.test.object);
|
|
66
|
+
}
|
|
67
|
+
if (init.consequent.type === 'MemberExpression') {
|
|
68
|
+
return _isIdentifierAllowed(context, init.consequent.object);
|
|
69
|
+
}
|
|
70
|
+
if (init.alternate.type === 'MemberExpression') {
|
|
71
|
+
return _isIdentifierAllowed(context, init.alternate.object);
|
|
61
72
|
}
|
|
62
|
-
// Destructured from object pattern
|
|
63
|
-
// e.g. const { width } = props
|
|
64
|
-
return isParameter(context, init);
|
|
65
73
|
}
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
|
|
75
|
+
// Destructured from member expression
|
|
76
|
+
// e.g. const width = props.width
|
|
77
|
+
if (init.type === 'MemberExpression') {
|
|
78
|
+
return _isIdentifierAllowed(context, init.object);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Destructured from object pattern
|
|
82
|
+
// e.g. const { width } = props
|
|
83
|
+
return _isIdentifierAllowed(context, init);
|
|
68
84
|
};
|
|
69
85
|
function isPropertyValueAllowed(property, context) {
|
|
70
86
|
if (property.type === 'SpreadElement') {
|
|
@@ -75,7 +91,7 @@ function isPropertyValueAllowed(property, context) {
|
|
|
75
91
|
if (property.value.type === 'Literal') {
|
|
76
92
|
return false;
|
|
77
93
|
} else if (property.value.type === 'Identifier') {
|
|
78
|
-
return
|
|
94
|
+
return _isIdentifierAllowed(context, property.value);
|
|
79
95
|
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
80
96
|
var variable = findVariable({
|
|
81
97
|
sourceCode: getSourceCode(context),
|
|
@@ -90,11 +106,11 @@ function isPropertyValueAllowed(property, context) {
|
|
|
90
106
|
return false;
|
|
91
107
|
}
|
|
92
108
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
93
|
-
var
|
|
94
|
-
var definitions = (
|
|
109
|
+
var _findVariable;
|
|
110
|
+
var definitions = (_findVariable = findVariable({
|
|
95
111
|
sourceCode: getSourceCode(context),
|
|
96
112
|
identifier: property.value.object
|
|
97
|
-
})) === null ||
|
|
113
|
+
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
98
114
|
if (!definitions || !definitions.length) {
|
|
99
115
|
return false;
|
|
100
116
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
2
2
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
|
-
|
|
6
4
|
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
7
5
|
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
8
6
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
2
|
-
|
|
3
1
|
import estraverse from 'estraverse';
|
|
4
2
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
5
3
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
2
2
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
4
|
import esquery from 'esquery';
|
|
6
5
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
7
6
|
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
2
|
-
|
|
3
1
|
import { createNoExportedRule } from '@atlaskit/eslint-utils/create-no-exported-rule';
|
|
4
2
|
import { isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
3
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
2
2
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
3
3
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
4
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line @atlassian/tangerine/import/entry-points
|
|
7
|
-
|
|
8
4
|
import esquery from 'esquery';
|
|
9
5
|
import estraverse from 'estraverse';
|
|
10
6
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
2
|
-
|
|
3
1
|
import { getScope } from '@atlaskit/eslint-utils/context-compat';
|
|
4
2
|
import { getImportSources, isCss, isCssMap, isKeyframes, isStyled, isXcss } from '@atlaskit/eslint-utils/is-supported-import';
|
|
5
3
|
import { createLintRule } from '../utils/create-rule';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
2
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9,
|
|
2
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject0;
|
|
3
3
|
import outdent from 'outdent';
|
|
4
4
|
var whereToGetHelp = "If you think this should be allowed, or if you're running into issues, reach out in #help-ui-styling-standard";
|
|
5
5
|
export var messages = {
|
|
@@ -13,5 +13,5 @@ export var messages = {
|
|
|
13
13
|
'no-spread-elements': outdent(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n Spread elements are not allowed in style objects.\n\n Compose styles with the css prop instead.\n\n ", "\n "])), whereToGetHelp),
|
|
14
14
|
// Fallback case if a more specific message is not applicable
|
|
15
15
|
'no-unsafe-values': outdent(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n Unsafe values are not allowed in style objects.\n\n ", "\n "])), whereToGetHelp),
|
|
16
|
-
'no-variables': outdent(
|
|
16
|
+
'no-variables': outdent(_templateObject0 || (_templateObject0 = _taggedTemplateLiteral(["\n Variables are not allowed in style objects, unless they:\n\n - Have a simple, static value.\n - Are defined in the same file.\n\n Use the style prop to apply dynamic values instead.\n\n ", "\n "])), whereToGetHelp)
|
|
17
17
|
};
|
|
@@ -44,12 +44,12 @@ export var rule = createLintRule({
|
|
|
44
44
|
type: 'problem',
|
|
45
45
|
fixable: 'code',
|
|
46
46
|
docs: {
|
|
47
|
-
description: 'Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries',
|
|
47
|
+
description: 'Ensures usage of `@compiled/react` or `@atlaskit/css` instead of other CSS-in-JS libraries',
|
|
48
48
|
recommended: true,
|
|
49
49
|
severity: 'error'
|
|
50
50
|
},
|
|
51
51
|
messages: {
|
|
52
|
-
'use-compiled': "Use '@compiled/react' instead of '{{importSource}}'"
|
|
52
|
+
'use-compiled': "Use '@atlaskit/css' or '@compiled/react' instead of '{{importSource}}'"
|
|
53
53
|
},
|
|
54
54
|
schema: schema
|
|
55
55
|
},
|
|
@@ -98,7 +98,8 @@ export var rule = createLintRule({
|
|
|
98
98
|
case 7:
|
|
99
99
|
_context.next = 9;
|
|
100
100
|
return fixer.replaceText(
|
|
101
|
-
//
|
|
101
|
+
// TODO: JFP-2823 - this type cast was added due to Jira's ESLint v9 migration
|
|
102
|
+
// @ts-ignore - types don't accept comment nodes
|
|
102
103
|
pragma, "/** @jsxImportSource @compiled/react */");
|
|
103
104
|
case 9:
|
|
104
105
|
case "end":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"./package.json": "./package.json"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@atlaskit/eslint-plugin-design-system": "^13.
|
|
43
|
+
"@atlaskit/eslint-plugin-design-system": "^13.19.0",
|
|
44
44
|
"@atlaskit/eslint-utils": "^2.0.0",
|
|
45
45
|
"@babel/runtime": "^7.0.0",
|
|
46
46
|
"@typescript-eslint/utils": "^7.1.0",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"postcss-selector-parser": "^6.0.16"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@af/formatting": "
|
|
58
|
-
"@atlaskit/ds-lib": "^
|
|
59
|
-
"@atlassian/codegen": "
|
|
60
|
-
"@atlassian/ts-loader": "
|
|
57
|
+
"@af/formatting": "workspace:^",
|
|
58
|
+
"@atlaskit/ds-lib": "^5.0.0",
|
|
59
|
+
"@atlassian/codegen": "^0.1.0",
|
|
60
|
+
"@atlassian/ts-loader": "^0.1.0",
|
|
61
61
|
"@eslint/eslintrc": "^3.0.2",
|
|
62
62
|
"@types/eslint": "^8.56.6",
|
|
63
63
|
"@types/eslint__eslintrc": "^2.1.2",
|