@atlaskit/eslint-plugin-ui-styling-standard 2.1.7 → 2.1.9
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 +21 -0
- package/dist/cjs/rules/no-imported-style-values/index.js +7 -0
- package/dist/cjs/rules/no-unsafe-selectors/index.js +99 -14
- package/dist/cjs/rules/no-unsafe-values/utils.js +32 -2
- package/dist/es2019/rules/no-imported-style-values/index.js +7 -0
- package/dist/es2019/rules/no-unsafe-selectors/index.js +69 -2
- package/dist/es2019/rules/no-unsafe-values/utils.js +32 -2
- package/dist/esm/rules/no-imported-style-values/index.js +7 -0
- package/dist/esm/rules/no-unsafe-selectors/index.js +99 -14
- package/dist/esm/rules/no-unsafe-values/utils.js +32 -2
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 2.1.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`a4c26c5edfc0b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a4c26c5edfc0b) -
|
|
8
|
+
Allow local literal style values constrained with TypeScript `satisfies` expressions.
|
|
9
|
+
- [`1715d48a722a2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1715d48a722a2) -
|
|
10
|
+
Migrate responsive styling to typed canonical CSS media-query keys. Allow those keys in the UI
|
|
11
|
+
Styling Standard and report non-canonical queries used with `satisfies`.
|
|
12
|
+
|
|
13
|
+
## 2.1.8
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [`2808e38fa97f7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2808e38fa97f7) -
|
|
18
|
+
Allow static style keys and values annotated with TypeScript `satisfies` expressions
|
|
19
|
+
- [`98d68443fc958`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/98d68443fc958) -
|
|
20
|
+
Handle TypeScript satisfies and assertion wrappers without rejecting safe inline style values or
|
|
21
|
+
imported type references. Update the Platform ESLint plugin's Compiled ESLint dependency to
|
|
22
|
+
^0.20.2 to fix shorthand-property sorting crashes on inline satisfies expressions.
|
|
23
|
+
|
|
3
24
|
## 2.1.7
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
|
@@ -80,6 +80,13 @@ var checkIdentifier = function checkIdentifier(identifier, context, functionAllo
|
|
|
80
80
|
var _ref = identifier,
|
|
81
81
|
parent = _ref.parent;
|
|
82
82
|
|
|
83
|
+
// Type references and `typeof` queries are erased at runtime and are not
|
|
84
|
+
// imported style values. Runtime expressions wrapped by `as` or `satisfies`
|
|
85
|
+
// must still be checked.
|
|
86
|
+
if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
83
90
|
// Even though `member` in `object.member` is syntactically an identifier,
|
|
84
91
|
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
85
92
|
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
@@ -4,15 +4,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
|
|
7
8
|
var _schema = require("@atlaskit/eslint-utils/schema");
|
|
8
9
|
var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
|
|
9
10
|
var _isSimpleSelector = require("../utils/is-simple-selector");
|
|
10
11
|
var _parseSelector = require("../utils/parse-selector");
|
|
11
12
|
var _styleCalls = require("../utils/style-calls");
|
|
12
13
|
var _walkStyleCallProperties = require("../utils/walk-style-call-properties");
|
|
14
|
+
var _constants = require("./constants");
|
|
13
15
|
var _lintSelector = require("./lint-selector");
|
|
14
16
|
var _walkCssMap = require("./walk-css-map");
|
|
15
|
-
var _constants = require("./constants");
|
|
16
17
|
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; } } }; }
|
|
17
18
|
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; } }
|
|
18
19
|
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; }
|
|
@@ -21,6 +22,71 @@ var ignoredAtRules = new Set(['@container',
|
|
|
21
22
|
'@media',
|
|
22
23
|
// ignored because it's covered by `no-nested-styles`
|
|
23
24
|
'@supports', '@property', '@starting-style']);
|
|
25
|
+
var canonicalMediaQueries = new Map([['media-above-xxs', '@media all'], ['media-above-xs', '@media (min-width: 30rem)'], ['media-above-sm', '@media (min-width: 48rem)'], ['media-above-md', '@media (min-width: 64rem)'], ['media-above-lg', '@media (min-width: 90rem)'], ['media-above-xl', '@media (min-width: 110.5rem)'], ['media-below-xs', '@media not all and (min-width: 30rem)'], ['media-below-sm', '@media not all and (min-width: 48rem)'], ['media-below-md', '@media not all and (min-width: 64rem)'], ['media-below-lg', '@media not all and (min-width: 90rem)'], ['media-below-xl', '@media not all and (min-width: 110.5rem)'], ['media-only-xxs', '@media (min-width: 0rem) and (max-width: 29.99rem)'], ['media-only-xs', '@media (min-width: 30rem) and (max-width: 47.99rem)'], ['media-only-sm', '@media (min-width: 48rem) and (max-width: 63.99rem)'], ['media-only-md', '@media (min-width: 64rem) and (max-width: 89.99rem)'], ['media-only-lg', '@media (min-width: 90rem) and (max-width: 110.49rem)'], ['media-only-xl', '@media (min-width: 110.5rem)'], ['media-dark-mode', '@media (prefers-color-scheme: dark)'], ['media-light-mode', '@media (prefers-color-scheme: light)'], ['media-reduced-motion', '@media (prefers-reduced-motion: reduce)'], ['media-reduced-transparency', '@media (prefers-reduced-transparency: reduce)'], ['media-forced-colors-active', '@media screen and (forced-colors: active)'], ['media-legacy-high-contrast', '@media screen and (-ms-high-contrast: active)'], ['media-forced-colors-or-legacy-high-contrast', '@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)']]);
|
|
26
|
+
var unwrapTypeScriptExpression = function unwrapTypeScriptExpression(node) {
|
|
27
|
+
var expression = node;
|
|
28
|
+
while (expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') {
|
|
29
|
+
expression = expression.expression;
|
|
30
|
+
}
|
|
31
|
+
return expression;
|
|
32
|
+
};
|
|
33
|
+
var isCanonicalTypedMediaKey = function isCanonicalTypedMediaKey(node, importedMediaTypes) {
|
|
34
|
+
if (node.type !== 'TSSatisfiesExpression') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
var expression = unwrapTypeScriptExpression(node);
|
|
38
|
+
if (expression.type !== 'Literal' || typeof expression.value !== 'string') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
var satisfiesExpression = node;
|
|
42
|
+
while (((_satisfiesExpression = satisfiesExpression) === null || _satisfiesExpression === void 0 ? void 0 : _satisfiesExpression.type) === 'TSSatisfiesExpression') {
|
|
43
|
+
var _satisfiesExpression, _satisfiesExpression$, _satisfiesExpression$2;
|
|
44
|
+
var typeName = (_satisfiesExpression$ = satisfiesExpression.typeAnnotation) === null || _satisfiesExpression$ === void 0 || (_satisfiesExpression$ = _satisfiesExpression$.typeName) === null || _satisfiesExpression$ === void 0 ? void 0 : _satisfiesExpression$.name;
|
|
45
|
+
if (((_satisfiesExpression$2 = satisfiesExpression.typeAnnotation) === null || _satisfiesExpression$2 === void 0 ? void 0 : _satisfiesExpression$2.type) === 'TSTypeReference' && typeName) {
|
|
46
|
+
var source = importedMediaTypes.get(typeName);
|
|
47
|
+
if (source && canonicalMediaQueries.get(source) === expression.value) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
satisfiesExpression = satisfiesExpression.expression;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
var getImportedMediaTypeSources = function getImportedMediaTypeSources(context) {
|
|
56
|
+
var importedMediaTypes = new Map();
|
|
57
|
+
var _iterator = _createForOfIteratorHelper((0, _contextCompat.getSourceCode)(context).ast.body),
|
|
58
|
+
_step;
|
|
59
|
+
try {
|
|
60
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
61
|
+
var statement = _step.value;
|
|
62
|
+
if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
var match = statement.source.value.match(/^@atlaskit\/css\/at-rules\/(media-[a-z-]+)$/);
|
|
66
|
+
if (match) {
|
|
67
|
+
var _iterator2 = _createForOfIteratorHelper(statement.specifiers),
|
|
68
|
+
_step2;
|
|
69
|
+
try {
|
|
70
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
71
|
+
var specifier = _step2.value;
|
|
72
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
73
|
+
importedMediaTypes.set(specifier.local.name, match[1]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
_iterator2.e(err);
|
|
78
|
+
} finally {
|
|
79
|
+
_iterator2.f();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
_iterator.e(err);
|
|
85
|
+
} finally {
|
|
86
|
+
_iterator.f();
|
|
87
|
+
}
|
|
88
|
+
return importedMediaTypes;
|
|
89
|
+
};
|
|
24
90
|
var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
25
91
|
meta: {
|
|
26
92
|
name: 'no-unsafe-selectors',
|
|
@@ -47,6 +113,7 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
47
113
|
'no-keyframes-at-rules': 'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
|
|
48
114
|
'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
|
|
49
115
|
'no-grouped-at-rules': 'Do not group at-rules. Write flattened at-rules instead.',
|
|
116
|
+
'no-noncanonical-media-query': 'Use the exact media query represented by the imported @atlaskit/css/at-rules type.',
|
|
50
117
|
/**
|
|
51
118
|
* Suggestion messages
|
|
52
119
|
*/
|
|
@@ -67,11 +134,12 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
67
134
|
create: function create(context, config) {
|
|
68
135
|
return {
|
|
69
136
|
Program: function Program() {
|
|
70
|
-
var
|
|
71
|
-
|
|
137
|
+
var importedMediaTypes = getImportedMediaTypeSources(context);
|
|
138
|
+
var _iterator3 = _createForOfIteratorHelper((0, _styleCalls.getStyleCalls)(context)),
|
|
139
|
+
_step3;
|
|
72
140
|
try {
|
|
73
141
|
var _loop = function _loop() {
|
|
74
|
-
var styleCall =
|
|
142
|
+
var styleCall = _step3.value;
|
|
75
143
|
if (!config.importSources.includes(styleCall.importSource)) {
|
|
76
144
|
return 1; // continue
|
|
77
145
|
}
|
|
@@ -95,10 +163,27 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
95
163
|
(0, _walkStyleCallProperties.walkStyleCallProperties)(styleCall, function (_ref) {
|
|
96
164
|
var key = _ref.key,
|
|
97
165
|
value = _ref.value;
|
|
98
|
-
|
|
166
|
+
var keyType = key.type;
|
|
167
|
+
if (value.type !== 'ObjectExpression' || keyType !== 'Literal' && keyType !== 'TSSatisfiesExpression') {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (keyType === 'TSSatisfiesExpression') {
|
|
171
|
+
var unwrappedKey = unwrapTypeScriptExpression(key);
|
|
172
|
+
if (unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
|
|
173
|
+
if (unwrappedKey.value.startsWith('@media') && !isCanonicalTypedMediaKey(key, importedMediaTypes)) {
|
|
174
|
+
context.report({
|
|
175
|
+
node: key,
|
|
176
|
+
messageId: 'no-noncanonical-media-query'
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
99
181
|
return;
|
|
100
182
|
}
|
|
101
183
|
var selectorText = key.value;
|
|
184
|
+
if (typeof selectorText !== 'string') {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
102
187
|
if (selectorText.includes('@')) {
|
|
103
188
|
lintAtRule({
|
|
104
189
|
context: context,
|
|
@@ -115,11 +200,11 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
115
200
|
}
|
|
116
201
|
try {
|
|
117
202
|
var selectorList = (0, _parseSelector.parseSelector)(context, selectorText);
|
|
118
|
-
var
|
|
119
|
-
|
|
203
|
+
var _iterator4 = _createForOfIteratorHelper(selectorList.nodes),
|
|
204
|
+
_step4;
|
|
120
205
|
try {
|
|
121
|
-
for (
|
|
122
|
-
var selector =
|
|
206
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
207
|
+
var selector = _step4.value;
|
|
123
208
|
(0, _lintSelector.lintSelector)({
|
|
124
209
|
context: context,
|
|
125
210
|
sourceNode: key,
|
|
@@ -129,9 +214,9 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
129
214
|
});
|
|
130
215
|
}
|
|
131
216
|
} catch (err) {
|
|
132
|
-
|
|
217
|
+
_iterator4.e(err);
|
|
133
218
|
} finally {
|
|
134
|
-
|
|
219
|
+
_iterator4.f();
|
|
135
220
|
}
|
|
136
221
|
} catch (_unused) {
|
|
137
222
|
context.report({
|
|
@@ -144,13 +229,13 @@ var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
|
|
|
144
229
|
}
|
|
145
230
|
});
|
|
146
231
|
};
|
|
147
|
-
for (
|
|
232
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
148
233
|
if (_loop()) continue;
|
|
149
234
|
}
|
|
150
235
|
} catch (err) {
|
|
151
|
-
|
|
236
|
+
_iterator3.e(err);
|
|
152
237
|
} finally {
|
|
153
|
-
|
|
238
|
+
_iterator3.f();
|
|
154
239
|
}
|
|
155
240
|
}
|
|
156
241
|
};
|
|
@@ -13,6 +13,16 @@ var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
|
13
13
|
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; } } }; }
|
|
14
14
|
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; } }
|
|
15
15
|
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; }
|
|
16
|
+
var unwrapSatisfiesExpression = function unwrapSatisfiesExpression(node) {
|
|
17
|
+
if (node.type !== 'TSSatisfiesExpression') {
|
|
18
|
+
return node;
|
|
19
|
+
}
|
|
20
|
+
var currentNode = node;
|
|
21
|
+
while (['TSAsExpression', 'TSSatisfiesExpression', 'TSTypeAssertion'].includes(currentNode.type)) {
|
|
22
|
+
currentNode = currentNode.expression;
|
|
23
|
+
}
|
|
24
|
+
return currentNode;
|
|
25
|
+
};
|
|
16
26
|
function isReferenceToCssVar(variable) {
|
|
17
27
|
var definitions = variable.defs;
|
|
18
28
|
return definitions.every(function (definition) {
|
|
@@ -105,7 +115,7 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
105
115
|
/**
|
|
106
116
|
* Variables can be used if they resolve to a literal.
|
|
107
117
|
*/
|
|
108
|
-
if (initializer.type === 'Literal') {
|
|
118
|
+
if (unwrapSatisfiesExpression(initializer).type === 'Literal') {
|
|
109
119
|
return;
|
|
110
120
|
}
|
|
111
121
|
|
|
@@ -168,7 +178,11 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
168
178
|
}, {
|
|
169
179
|
key: "isAllowedDynamicKey",
|
|
170
180
|
value: function isAllowedDynamicKey(expression) {
|
|
171
|
-
var _this$context$sourceC2;
|
|
181
|
+
var _typedExpression$expr, _this$context$sourceC2;
|
|
182
|
+
var typedExpression = expression;
|
|
183
|
+
if (typedExpression.type === 'TSSatisfiesExpression' && ((_typedExpression$expr = typedExpression.expression) === null || _typedExpression$expr === void 0 ? void 0 : _typedExpression$expr.type) === 'Literal' && typeof typedExpression.expression.value === 'string') {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
172
186
|
var identifier = (0, _findIdentifierNode.findIdentifierNode)(expression);
|
|
173
187
|
if (!identifier) {
|
|
174
188
|
return false;
|
|
@@ -189,6 +203,16 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
189
203
|
}, {
|
|
190
204
|
key: "lintKey",
|
|
191
205
|
value: function lintKey(property) {
|
|
206
|
+
var key = property.key;
|
|
207
|
+
|
|
208
|
+
// A type-only `satisfies` annotation preserves a static key at runtime.
|
|
209
|
+
// It is safe for the same reason as a directly written string literal.
|
|
210
|
+
var unwrappedKey = unwrapSatisfiesExpression(key);
|
|
211
|
+
var isSatisfiesExpression = unwrappedKey !== key;
|
|
212
|
+
if (property.computed && isSatisfiesExpression && unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
192
216
|
/**
|
|
193
217
|
* If it's not computed then it must be a plain string.
|
|
194
218
|
*
|
|
@@ -280,6 +304,12 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
280
304
|
}, {
|
|
281
305
|
key: "lintValue",
|
|
282
306
|
value: function lintValue(value) {
|
|
307
|
+
var unwrappedValue = unwrapSatisfiesExpression(value);
|
|
308
|
+
if (unwrappedValue !== value) {
|
|
309
|
+
this.lintValue(unwrappedValue);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
|
|
283
313
|
/**
|
|
284
314
|
* Literals are always allowed by this rule.
|
|
285
315
|
*/
|
|
@@ -69,6 +69,13 @@ const checkIdentifier = (identifier, context, functionAllowList, keysAllowList)
|
|
|
69
69
|
parent
|
|
70
70
|
} = identifier;
|
|
71
71
|
|
|
72
|
+
// Type references and `typeof` queries are erased at runtime and are not
|
|
73
|
+
// imported style values. Runtime expressions wrapped by `as` or `satisfies`
|
|
74
|
+
// must still be checked.
|
|
75
|
+
if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
72
79
|
// Even though `member` in `object.member` is syntactically an identifier,
|
|
73
80
|
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
74
81
|
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
@@ -1,17 +1,65 @@
|
|
|
1
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
1
2
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
2
3
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
3
4
|
import { isSimpleSelector } from '../utils/is-simple-selector';
|
|
4
5
|
import { parseSelector } from '../utils/parse-selector';
|
|
5
6
|
import { getStyleCalls } from '../utils/style-calls';
|
|
6
7
|
import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
|
|
8
|
+
import { allowedPseudos } from './constants';
|
|
7
9
|
import { lintSelector } from './lint-selector';
|
|
8
10
|
import { walkCssMapCall } from './walk-css-map';
|
|
9
|
-
import { allowedPseudos } from './constants';
|
|
10
11
|
const ignoredAtRules = new Set(['@container',
|
|
11
12
|
// ignored because it's covered by `no-container-queries`
|
|
12
13
|
'@media',
|
|
13
14
|
// ignored because it's covered by `no-nested-styles`
|
|
14
15
|
'@supports', '@property', '@starting-style']);
|
|
16
|
+
const canonicalMediaQueries = new Map([['media-above-xxs', '@media all'], ['media-above-xs', '@media (min-width: 30rem)'], ['media-above-sm', '@media (min-width: 48rem)'], ['media-above-md', '@media (min-width: 64rem)'], ['media-above-lg', '@media (min-width: 90rem)'], ['media-above-xl', '@media (min-width: 110.5rem)'], ['media-below-xs', '@media not all and (min-width: 30rem)'], ['media-below-sm', '@media not all and (min-width: 48rem)'], ['media-below-md', '@media not all and (min-width: 64rem)'], ['media-below-lg', '@media not all and (min-width: 90rem)'], ['media-below-xl', '@media not all and (min-width: 110.5rem)'], ['media-only-xxs', '@media (min-width: 0rem) and (max-width: 29.99rem)'], ['media-only-xs', '@media (min-width: 30rem) and (max-width: 47.99rem)'], ['media-only-sm', '@media (min-width: 48rem) and (max-width: 63.99rem)'], ['media-only-md', '@media (min-width: 64rem) and (max-width: 89.99rem)'], ['media-only-lg', '@media (min-width: 90rem) and (max-width: 110.49rem)'], ['media-only-xl', '@media (min-width: 110.5rem)'], ['media-dark-mode', '@media (prefers-color-scheme: dark)'], ['media-light-mode', '@media (prefers-color-scheme: light)'], ['media-reduced-motion', '@media (prefers-reduced-motion: reduce)'], ['media-reduced-transparency', '@media (prefers-reduced-transparency: reduce)'], ['media-forced-colors-active', '@media screen and (forced-colors: active)'], ['media-legacy-high-contrast', '@media screen and (-ms-high-contrast: active)'], ['media-forced-colors-or-legacy-high-contrast', '@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)']]);
|
|
17
|
+
const unwrapTypeScriptExpression = node => {
|
|
18
|
+
let expression = node;
|
|
19
|
+
while (expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') {
|
|
20
|
+
expression = expression.expression;
|
|
21
|
+
}
|
|
22
|
+
return expression;
|
|
23
|
+
};
|
|
24
|
+
const isCanonicalTypedMediaKey = (node, importedMediaTypes) => {
|
|
25
|
+
if (node.type !== 'TSSatisfiesExpression') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const expression = unwrapTypeScriptExpression(node);
|
|
29
|
+
if (expression.type !== 'Literal' || typeof expression.value !== 'string') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
let satisfiesExpression = node;
|
|
33
|
+
while (((_satisfiesExpression = satisfiesExpression) === null || _satisfiesExpression === void 0 ? void 0 : _satisfiesExpression.type) === 'TSSatisfiesExpression') {
|
|
34
|
+
var _satisfiesExpression, _satisfiesExpression$, _satisfiesExpression$2, _satisfiesExpression$3;
|
|
35
|
+
const typeName = (_satisfiesExpression$ = satisfiesExpression.typeAnnotation) === null || _satisfiesExpression$ === void 0 ? void 0 : (_satisfiesExpression$2 = _satisfiesExpression$.typeName) === null || _satisfiesExpression$2 === void 0 ? void 0 : _satisfiesExpression$2.name;
|
|
36
|
+
if (((_satisfiesExpression$3 = satisfiesExpression.typeAnnotation) === null || _satisfiesExpression$3 === void 0 ? void 0 : _satisfiesExpression$3.type) === 'TSTypeReference' && typeName) {
|
|
37
|
+
const source = importedMediaTypes.get(typeName);
|
|
38
|
+
if (source && canonicalMediaQueries.get(source) === expression.value) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
satisfiesExpression = satisfiesExpression.expression;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
const getImportedMediaTypeSources = context => {
|
|
47
|
+
const importedMediaTypes = new Map();
|
|
48
|
+
for (const statement of getSourceCode(context).ast.body) {
|
|
49
|
+
if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const match = statement.source.value.match(/^@atlaskit\/css\/at-rules\/(media-[a-z-]+)$/);
|
|
53
|
+
if (match) {
|
|
54
|
+
for (const specifier of statement.specifiers) {
|
|
55
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
56
|
+
importedMediaTypes.set(specifier.local.name, match[1]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return importedMediaTypes;
|
|
62
|
+
};
|
|
15
63
|
const rule = createLintRuleWithTypedConfig({
|
|
16
64
|
meta: {
|
|
17
65
|
name: 'no-unsafe-selectors',
|
|
@@ -38,6 +86,7 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
38
86
|
'no-keyframes-at-rules': 'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
|
|
39
87
|
'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
|
|
40
88
|
'no-grouped-at-rules': 'Do not group at-rules. Write flattened at-rules instead.',
|
|
89
|
+
'no-noncanonical-media-query': 'Use the exact media query represented by the imported @atlaskit/css/at-rules type.',
|
|
41
90
|
/**
|
|
42
91
|
* Suggestion messages
|
|
43
92
|
*/
|
|
@@ -58,6 +107,7 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
58
107
|
create(context, config) {
|
|
59
108
|
return {
|
|
60
109
|
Program() {
|
|
110
|
+
const importedMediaTypes = getImportedMediaTypeSources(context);
|
|
61
111
|
for (const styleCall of getStyleCalls(context)) {
|
|
62
112
|
if (!config.importSources.includes(styleCall.importSource)) {
|
|
63
113
|
continue;
|
|
@@ -85,10 +135,27 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
85
135
|
key,
|
|
86
136
|
value
|
|
87
137
|
}) => {
|
|
88
|
-
|
|
138
|
+
const keyType = key.type;
|
|
139
|
+
if (value.type !== 'ObjectExpression' || keyType !== 'Literal' && keyType !== 'TSSatisfiesExpression') {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (keyType === 'TSSatisfiesExpression') {
|
|
143
|
+
const unwrappedKey = unwrapTypeScriptExpression(key);
|
|
144
|
+
if (unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
|
|
145
|
+
if (unwrappedKey.value.startsWith('@media') && !isCanonicalTypedMediaKey(key, importedMediaTypes)) {
|
|
146
|
+
context.report({
|
|
147
|
+
node: key,
|
|
148
|
+
messageId: 'no-noncanonical-media-query'
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
89
153
|
return;
|
|
90
154
|
}
|
|
91
155
|
const selectorText = key.value;
|
|
156
|
+
if (typeof selectorText !== 'string') {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
92
159
|
if (selectorText.includes('@')) {
|
|
93
160
|
lintAtRule({
|
|
94
161
|
context,
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
2
2
|
import { findIdentifierNode } from '@atlaskit/eslint-utils/find-identifier-node';
|
|
3
3
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
4
|
+
const unwrapSatisfiesExpression = node => {
|
|
5
|
+
if (node.type !== 'TSSatisfiesExpression') {
|
|
6
|
+
return node;
|
|
7
|
+
}
|
|
8
|
+
let currentNode = node;
|
|
9
|
+
while (['TSAsExpression', 'TSSatisfiesExpression', 'TSTypeAssertion'].includes(currentNode.type)) {
|
|
10
|
+
currentNode = currentNode.expression;
|
|
11
|
+
}
|
|
12
|
+
return currentNode;
|
|
13
|
+
};
|
|
4
14
|
function isReferenceToCssVar(variable) {
|
|
5
15
|
const definitions = variable.defs;
|
|
6
16
|
return definitions.every(definition => {
|
|
@@ -85,7 +95,7 @@ export class Linter {
|
|
|
85
95
|
/**
|
|
86
96
|
* Variables can be used if they resolve to a literal.
|
|
87
97
|
*/
|
|
88
|
-
if (initializer.type === 'Literal') {
|
|
98
|
+
if (unwrapSatisfiesExpression(initializer).type === 'Literal') {
|
|
89
99
|
return;
|
|
90
100
|
}
|
|
91
101
|
|
|
@@ -137,7 +147,11 @@ export class Linter {
|
|
|
137
147
|
});
|
|
138
148
|
}
|
|
139
149
|
isAllowedDynamicKey(expression) {
|
|
140
|
-
var _this$context$sourceC2;
|
|
150
|
+
var _typedExpression$expr, _this$context$sourceC2;
|
|
151
|
+
const typedExpression = expression;
|
|
152
|
+
if (typedExpression.type === 'TSSatisfiesExpression' && ((_typedExpression$expr = typedExpression.expression) === null || _typedExpression$expr === void 0 ? void 0 : _typedExpression$expr.type) === 'Literal' && typeof typedExpression.expression.value === 'string') {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
141
155
|
const identifier = findIdentifierNode(expression);
|
|
142
156
|
if (!identifier) {
|
|
143
157
|
return false;
|
|
@@ -156,6 +170,16 @@ export class Linter {
|
|
|
156
170
|
});
|
|
157
171
|
}
|
|
158
172
|
lintKey(property) {
|
|
173
|
+
const key = property.key;
|
|
174
|
+
|
|
175
|
+
// A type-only `satisfies` annotation preserves a static key at runtime.
|
|
176
|
+
// It is safe for the same reason as a directly written string literal.
|
|
177
|
+
const unwrappedKey = unwrapSatisfiesExpression(key);
|
|
178
|
+
const isSatisfiesExpression = unwrappedKey !== key;
|
|
179
|
+
if (property.computed && isSatisfiesExpression && unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
159
183
|
/**
|
|
160
184
|
* If it's not computed then it must be a plain string.
|
|
161
185
|
*
|
|
@@ -228,6 +252,12 @@ export class Linter {
|
|
|
228
252
|
});
|
|
229
253
|
}
|
|
230
254
|
lintValue(value) {
|
|
255
|
+
const unwrappedValue = unwrapSatisfiesExpression(value);
|
|
256
|
+
if (unwrappedValue !== value) {
|
|
257
|
+
this.lintValue(unwrappedValue);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
231
261
|
/**
|
|
232
262
|
* Literals are always allowed by this rule.
|
|
233
263
|
*/
|
|
@@ -73,6 +73,13 @@ var checkIdentifier = function checkIdentifier(identifier, context, functionAllo
|
|
|
73
73
|
var _ref = identifier,
|
|
74
74
|
parent = _ref.parent;
|
|
75
75
|
|
|
76
|
+
// Type references and `typeof` queries are erased at runtime and are not
|
|
77
|
+
// imported style values. Runtime expressions wrapped by `as` or `satisfies`
|
|
78
|
+
// must still be checked.
|
|
79
|
+
if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
76
83
|
// Even though `member` in `object.member` is syntactically an identifier,
|
|
77
84
|
// it should be ignored as `.member` is syntax sugar for `['member']` here.
|
|
78
85
|
// We should still lint `object[member]` (when `parent.computed` === true)
|
|
@@ -1,20 +1,86 @@
|
|
|
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
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
4
5
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
5
6
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
6
7
|
import { isSimpleSelector } from '../utils/is-simple-selector';
|
|
7
8
|
import { parseSelector } from '../utils/parse-selector';
|
|
8
9
|
import { getStyleCalls } from '../utils/style-calls';
|
|
9
10
|
import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
|
|
11
|
+
import { allowedPseudos } from './constants';
|
|
10
12
|
import { lintSelector } from './lint-selector';
|
|
11
13
|
import { walkCssMapCall } from './walk-css-map';
|
|
12
|
-
import { allowedPseudos } from './constants';
|
|
13
14
|
var ignoredAtRules = new Set(['@container',
|
|
14
15
|
// ignored because it's covered by `no-container-queries`
|
|
15
16
|
'@media',
|
|
16
17
|
// ignored because it's covered by `no-nested-styles`
|
|
17
18
|
'@supports', '@property', '@starting-style']);
|
|
19
|
+
var canonicalMediaQueries = new Map([['media-above-xxs', '@media all'], ['media-above-xs', '@media (min-width: 30rem)'], ['media-above-sm', '@media (min-width: 48rem)'], ['media-above-md', '@media (min-width: 64rem)'], ['media-above-lg', '@media (min-width: 90rem)'], ['media-above-xl', '@media (min-width: 110.5rem)'], ['media-below-xs', '@media not all and (min-width: 30rem)'], ['media-below-sm', '@media not all and (min-width: 48rem)'], ['media-below-md', '@media not all and (min-width: 64rem)'], ['media-below-lg', '@media not all and (min-width: 90rem)'], ['media-below-xl', '@media not all and (min-width: 110.5rem)'], ['media-only-xxs', '@media (min-width: 0rem) and (max-width: 29.99rem)'], ['media-only-xs', '@media (min-width: 30rem) and (max-width: 47.99rem)'], ['media-only-sm', '@media (min-width: 48rem) and (max-width: 63.99rem)'], ['media-only-md', '@media (min-width: 64rem) and (max-width: 89.99rem)'], ['media-only-lg', '@media (min-width: 90rem) and (max-width: 110.49rem)'], ['media-only-xl', '@media (min-width: 110.5rem)'], ['media-dark-mode', '@media (prefers-color-scheme: dark)'], ['media-light-mode', '@media (prefers-color-scheme: light)'], ['media-reduced-motion', '@media (prefers-reduced-motion: reduce)'], ['media-reduced-transparency', '@media (prefers-reduced-transparency: reduce)'], ['media-forced-colors-active', '@media screen and (forced-colors: active)'], ['media-legacy-high-contrast', '@media screen and (-ms-high-contrast: active)'], ['media-forced-colors-or-legacy-high-contrast', '@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)']]);
|
|
20
|
+
var unwrapTypeScriptExpression = function unwrapTypeScriptExpression(node) {
|
|
21
|
+
var expression = node;
|
|
22
|
+
while (expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') {
|
|
23
|
+
expression = expression.expression;
|
|
24
|
+
}
|
|
25
|
+
return expression;
|
|
26
|
+
};
|
|
27
|
+
var isCanonicalTypedMediaKey = function isCanonicalTypedMediaKey(node, importedMediaTypes) {
|
|
28
|
+
if (node.type !== 'TSSatisfiesExpression') {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
var expression = unwrapTypeScriptExpression(node);
|
|
32
|
+
if (expression.type !== 'Literal' || typeof expression.value !== 'string') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
var satisfiesExpression = node;
|
|
36
|
+
while (((_satisfiesExpression = satisfiesExpression) === null || _satisfiesExpression === void 0 ? void 0 : _satisfiesExpression.type) === 'TSSatisfiesExpression') {
|
|
37
|
+
var _satisfiesExpression, _satisfiesExpression$, _satisfiesExpression$2;
|
|
38
|
+
var typeName = (_satisfiesExpression$ = satisfiesExpression.typeAnnotation) === null || _satisfiesExpression$ === void 0 || (_satisfiesExpression$ = _satisfiesExpression$.typeName) === null || _satisfiesExpression$ === void 0 ? void 0 : _satisfiesExpression$.name;
|
|
39
|
+
if (((_satisfiesExpression$2 = satisfiesExpression.typeAnnotation) === null || _satisfiesExpression$2 === void 0 ? void 0 : _satisfiesExpression$2.type) === 'TSTypeReference' && typeName) {
|
|
40
|
+
var source = importedMediaTypes.get(typeName);
|
|
41
|
+
if (source && canonicalMediaQueries.get(source) === expression.value) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
satisfiesExpression = satisfiesExpression.expression;
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
};
|
|
49
|
+
var getImportedMediaTypeSources = function getImportedMediaTypeSources(context) {
|
|
50
|
+
var importedMediaTypes = new Map();
|
|
51
|
+
var _iterator = _createForOfIteratorHelper(getSourceCode(context).ast.body),
|
|
52
|
+
_step;
|
|
53
|
+
try {
|
|
54
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
55
|
+
var statement = _step.value;
|
|
56
|
+
if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
var match = statement.source.value.match(/^@atlaskit\/css\/at-rules\/(media-[a-z-]+)$/);
|
|
60
|
+
if (match) {
|
|
61
|
+
var _iterator2 = _createForOfIteratorHelper(statement.specifiers),
|
|
62
|
+
_step2;
|
|
63
|
+
try {
|
|
64
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
65
|
+
var specifier = _step2.value;
|
|
66
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
67
|
+
importedMediaTypes.set(specifier.local.name, match[1]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
} catch (err) {
|
|
71
|
+
_iterator2.e(err);
|
|
72
|
+
} finally {
|
|
73
|
+
_iterator2.f();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
} catch (err) {
|
|
78
|
+
_iterator.e(err);
|
|
79
|
+
} finally {
|
|
80
|
+
_iterator.f();
|
|
81
|
+
}
|
|
82
|
+
return importedMediaTypes;
|
|
83
|
+
};
|
|
18
84
|
var rule = createLintRuleWithTypedConfig({
|
|
19
85
|
meta: {
|
|
20
86
|
name: 'no-unsafe-selectors',
|
|
@@ -41,6 +107,7 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
41
107
|
'no-keyframes-at-rules': 'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
|
|
42
108
|
'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
|
|
43
109
|
'no-grouped-at-rules': 'Do not group at-rules. Write flattened at-rules instead.',
|
|
110
|
+
'no-noncanonical-media-query': 'Use the exact media query represented by the imported @atlaskit/css/at-rules type.',
|
|
44
111
|
/**
|
|
45
112
|
* Suggestion messages
|
|
46
113
|
*/
|
|
@@ -61,11 +128,12 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
61
128
|
create: function create(context, config) {
|
|
62
129
|
return {
|
|
63
130
|
Program: function Program() {
|
|
64
|
-
var
|
|
65
|
-
|
|
131
|
+
var importedMediaTypes = getImportedMediaTypeSources(context);
|
|
132
|
+
var _iterator3 = _createForOfIteratorHelper(getStyleCalls(context)),
|
|
133
|
+
_step3;
|
|
66
134
|
try {
|
|
67
135
|
var _loop = function _loop() {
|
|
68
|
-
var styleCall =
|
|
136
|
+
var styleCall = _step3.value;
|
|
69
137
|
if (!config.importSources.includes(styleCall.importSource)) {
|
|
70
138
|
return 1; // continue
|
|
71
139
|
}
|
|
@@ -89,10 +157,27 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
89
157
|
walkStyleCallProperties(styleCall, function (_ref) {
|
|
90
158
|
var key = _ref.key,
|
|
91
159
|
value = _ref.value;
|
|
92
|
-
|
|
160
|
+
var keyType = key.type;
|
|
161
|
+
if (value.type !== 'ObjectExpression' || keyType !== 'Literal' && keyType !== 'TSSatisfiesExpression') {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (keyType === 'TSSatisfiesExpression') {
|
|
165
|
+
var unwrappedKey = unwrapTypeScriptExpression(key);
|
|
166
|
+
if (unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
|
|
167
|
+
if (unwrappedKey.value.startsWith('@media') && !isCanonicalTypedMediaKey(key, importedMediaTypes)) {
|
|
168
|
+
context.report({
|
|
169
|
+
node: key,
|
|
170
|
+
messageId: 'no-noncanonical-media-query'
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
93
175
|
return;
|
|
94
176
|
}
|
|
95
177
|
var selectorText = key.value;
|
|
178
|
+
if (typeof selectorText !== 'string') {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
96
181
|
if (selectorText.includes('@')) {
|
|
97
182
|
lintAtRule({
|
|
98
183
|
context: context,
|
|
@@ -109,11 +194,11 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
109
194
|
}
|
|
110
195
|
try {
|
|
111
196
|
var selectorList = parseSelector(context, selectorText);
|
|
112
|
-
var
|
|
113
|
-
|
|
197
|
+
var _iterator4 = _createForOfIteratorHelper(selectorList.nodes),
|
|
198
|
+
_step4;
|
|
114
199
|
try {
|
|
115
|
-
for (
|
|
116
|
-
var selector =
|
|
200
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
201
|
+
var selector = _step4.value;
|
|
117
202
|
lintSelector({
|
|
118
203
|
context: context,
|
|
119
204
|
sourceNode: key,
|
|
@@ -123,9 +208,9 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
123
208
|
});
|
|
124
209
|
}
|
|
125
210
|
} catch (err) {
|
|
126
|
-
|
|
211
|
+
_iterator4.e(err);
|
|
127
212
|
} finally {
|
|
128
|
-
|
|
213
|
+
_iterator4.f();
|
|
129
214
|
}
|
|
130
215
|
} catch (_unused) {
|
|
131
216
|
context.report({
|
|
@@ -138,13 +223,13 @@ var rule = createLintRuleWithTypedConfig({
|
|
|
138
223
|
}
|
|
139
224
|
});
|
|
140
225
|
};
|
|
141
|
-
for (
|
|
226
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
142
227
|
if (_loop()) continue;
|
|
143
228
|
}
|
|
144
229
|
} catch (err) {
|
|
145
|
-
|
|
230
|
+
_iterator3.e(err);
|
|
146
231
|
} finally {
|
|
147
|
-
|
|
232
|
+
_iterator3.f();
|
|
148
233
|
}
|
|
149
234
|
}
|
|
150
235
|
};
|
|
@@ -6,6 +6,16 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
6
6
|
import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
7
7
|
import { findIdentifierNode } from '@atlaskit/eslint-utils/find-identifier-node';
|
|
8
8
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
9
|
+
var unwrapSatisfiesExpression = function unwrapSatisfiesExpression(node) {
|
|
10
|
+
if (node.type !== 'TSSatisfiesExpression') {
|
|
11
|
+
return node;
|
|
12
|
+
}
|
|
13
|
+
var currentNode = node;
|
|
14
|
+
while (['TSAsExpression', 'TSSatisfiesExpression', 'TSTypeAssertion'].includes(currentNode.type)) {
|
|
15
|
+
currentNode = currentNode.expression;
|
|
16
|
+
}
|
|
17
|
+
return currentNode;
|
|
18
|
+
};
|
|
9
19
|
function isReferenceToCssVar(variable) {
|
|
10
20
|
var definitions = variable.defs;
|
|
11
21
|
return definitions.every(function (definition) {
|
|
@@ -98,7 +108,7 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
98
108
|
/**
|
|
99
109
|
* Variables can be used if they resolve to a literal.
|
|
100
110
|
*/
|
|
101
|
-
if (initializer.type === 'Literal') {
|
|
111
|
+
if (unwrapSatisfiesExpression(initializer).type === 'Literal') {
|
|
102
112
|
return;
|
|
103
113
|
}
|
|
104
114
|
|
|
@@ -161,7 +171,11 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
161
171
|
}, {
|
|
162
172
|
key: "isAllowedDynamicKey",
|
|
163
173
|
value: function isAllowedDynamicKey(expression) {
|
|
164
|
-
var _this$context$sourceC2;
|
|
174
|
+
var _typedExpression$expr, _this$context$sourceC2;
|
|
175
|
+
var typedExpression = expression;
|
|
176
|
+
if (typedExpression.type === 'TSSatisfiesExpression' && ((_typedExpression$expr = typedExpression.expression) === null || _typedExpression$expr === void 0 ? void 0 : _typedExpression$expr.type) === 'Literal' && typeof typedExpression.expression.value === 'string') {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
165
179
|
var identifier = findIdentifierNode(expression);
|
|
166
180
|
if (!identifier) {
|
|
167
181
|
return false;
|
|
@@ -182,6 +196,16 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
182
196
|
}, {
|
|
183
197
|
key: "lintKey",
|
|
184
198
|
value: function lintKey(property) {
|
|
199
|
+
var key = property.key;
|
|
200
|
+
|
|
201
|
+
// A type-only `satisfies` annotation preserves a static key at runtime.
|
|
202
|
+
// It is safe for the same reason as a directly written string literal.
|
|
203
|
+
var unwrappedKey = unwrapSatisfiesExpression(key);
|
|
204
|
+
var isSatisfiesExpression = unwrappedKey !== key;
|
|
205
|
+
if (property.computed && isSatisfiesExpression && unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
185
209
|
/**
|
|
186
210
|
* If it's not computed then it must be a plain string.
|
|
187
211
|
*
|
|
@@ -273,6 +297,12 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
273
297
|
}, {
|
|
274
298
|
key: "lintValue",
|
|
275
299
|
value: function lintValue(value) {
|
|
300
|
+
var unwrappedValue = unwrapSatisfiesExpression(value);
|
|
301
|
+
if (unwrappedValue !== value) {
|
|
302
|
+
this.lintValue(unwrappedValue);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
276
306
|
/**
|
|
277
307
|
* Literals are always allowed by this rule.
|
|
278
308
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.9",
|
|
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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
],
|
|
29
29
|
"atlaskit:src": "src/index.tsx",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@atlaskit/eslint-plugin-design-system": "^16.
|
|
31
|
+
"@atlaskit/eslint-plugin-design-system": "^16.13.0",
|
|
32
32
|
"@atlaskit/eslint-utils": "^3.1.0",
|
|
33
33
|
"@babel/runtime": "^7.0.0",
|
|
34
34
|
"@typescript-eslint/utils": "^8.64.0",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"@types/eslint": "^8.56.6",
|
|
51
51
|
"@types/eslint__eslintrc": "^2.1.2",
|
|
52
52
|
"@types/estraverse": "^5.1.7",
|
|
53
|
+
"@types/estree": "1.0.5",
|
|
53
54
|
"@types/json-schema": "^7.0.15",
|
|
54
55
|
"eslint": "^8.57.0",
|
|
55
56
|
"lodash": "^4.17.21"
|