@atlaskit/eslint-plugin-ui-styling-standard 2.1.8 → 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 +10 -0
- package/dist/cjs/rules/no-unsafe-selectors/index.js +99 -14
- package/dist/cjs/rules/no-unsafe-values/utils.js +6 -2
- package/dist/es2019/rules/no-unsafe-selectors/index.js +69 -2
- package/dist/es2019/rules/no-unsafe-values/utils.js +6 -2
- package/dist/esm/rules/no-unsafe-selectors/index.js +99 -14
- package/dist/esm/rules/no-unsafe-values/utils.js +6 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
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
|
+
|
|
3
13
|
## 2.1.8
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -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
|
};
|
|
@@ -115,7 +115,7 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
115
115
|
/**
|
|
116
116
|
* Variables can be used if they resolve to a literal.
|
|
117
117
|
*/
|
|
118
|
-
if (initializer.type === 'Literal') {
|
|
118
|
+
if (unwrapSatisfiesExpression(initializer).type === 'Literal') {
|
|
119
119
|
return;
|
|
120
120
|
}
|
|
121
121
|
|
|
@@ -178,7 +178,11 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
|
|
|
178
178
|
}, {
|
|
179
179
|
key: "isAllowedDynamicKey",
|
|
180
180
|
value: function isAllowedDynamicKey(expression) {
|
|
181
|
-
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
|
+
}
|
|
182
186
|
var identifier = (0, _findIdentifierNode.findIdentifierNode)(expression);
|
|
183
187
|
if (!identifier) {
|
|
184
188
|
return false;
|
|
@@ -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,
|
|
@@ -95,7 +95,7 @@ export class Linter {
|
|
|
95
95
|
/**
|
|
96
96
|
* Variables can be used if they resolve to a literal.
|
|
97
97
|
*/
|
|
98
|
-
if (initializer.type === 'Literal') {
|
|
98
|
+
if (unwrapSatisfiesExpression(initializer).type === 'Literal') {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -147,7 +147,11 @@ export class Linter {
|
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
isAllowedDynamicKey(expression) {
|
|
150
|
-
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
|
+
}
|
|
151
155
|
const identifier = findIdentifierNode(expression);
|
|
152
156
|
if (!identifier) {
|
|
153
157
|
return false;
|
|
@@ -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
|
};
|
|
@@ -108,7 +108,7 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
108
108
|
/**
|
|
109
109
|
* Variables can be used if they resolve to a literal.
|
|
110
110
|
*/
|
|
111
|
-
if (initializer.type === 'Literal') {
|
|
111
|
+
if (unwrapSatisfiesExpression(initializer).type === 'Literal') {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
114
|
|
|
@@ -171,7 +171,11 @@ export var Linter = /*#__PURE__*/function () {
|
|
|
171
171
|
}, {
|
|
172
172
|
key: "isAllowedDynamicKey",
|
|
173
173
|
value: function isAllowedDynamicKey(expression) {
|
|
174
|
-
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
|
+
}
|
|
175
179
|
var identifier = findIdentifierNode(expression);
|
|
176
180
|
if (!identifier) {
|
|
177
181
|
return false;
|
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",
|