@atlaskit/eslint-plugin-ui-styling-standard 2.1.8 → 2.1.10

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.
Files changed (36) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/index.codegen.js +2 -2
  4. package/dist/cjs/presets/all-flat.codegen.js +2 -2
  5. package/dist/cjs/presets/all.codegen.js +2 -2
  6. package/dist/cjs/presets/recommended-flat.codegen.js +2 -2
  7. package/dist/cjs/presets/recommended.codegen.js +2 -2
  8. package/dist/cjs/rules/atlaskit-theme/index.js +159 -52
  9. package/dist/cjs/rules/index.codegen.js +2 -2
  10. package/dist/cjs/rules/no-unsafe-selectors/index.js +99 -14
  11. package/dist/cjs/rules/no-unsafe-values/utils.js +6 -2
  12. package/dist/es2019/index.codegen.js +2 -2
  13. package/dist/es2019/presets/all-flat.codegen.js +2 -2
  14. package/dist/es2019/presets/all.codegen.js +2 -2
  15. package/dist/es2019/presets/recommended-flat.codegen.js +2 -2
  16. package/dist/es2019/presets/recommended.codegen.js +2 -2
  17. package/dist/es2019/rules/atlaskit-theme/index.js +117 -50
  18. package/dist/es2019/rules/index.codegen.js +2 -2
  19. package/dist/es2019/rules/no-unsafe-selectors/index.js +69 -2
  20. package/dist/es2019/rules/no-unsafe-values/utils.js +6 -2
  21. package/dist/esm/index.codegen.js +2 -2
  22. package/dist/esm/presets/all-flat.codegen.js +2 -2
  23. package/dist/esm/presets/all.codegen.js +2 -2
  24. package/dist/esm/presets/recommended-flat.codegen.js +2 -2
  25. package/dist/esm/presets/recommended.codegen.js +2 -2
  26. package/dist/esm/rules/atlaskit-theme/index.js +159 -53
  27. package/dist/esm/rules/index.codegen.js +2 -2
  28. package/dist/esm/rules/no-unsafe-selectors/index.js +99 -14
  29. package/dist/esm/rules/no-unsafe-values/utils.js +6 -2
  30. package/dist/types/index.codegen.d.ts +2 -2
  31. package/dist/types/presets/all-flat.codegen.d.ts +2 -2
  32. package/dist/types/presets/all.codegen.d.ts +2 -2
  33. package/dist/types/presets/recommended-flat.codegen.d.ts +2 -2
  34. package/dist/types/presets/recommended.codegen.d.ts +2 -2
  35. package/dist/types/rules/index.codegen.d.ts +2 -2
  36. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 2.1.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [`62aaaa3da8184`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/62aaaa3da8184) -
8
+ Speed up the atlaskit-theme lint rule by skipping files that do not import the banned theme
9
+ mixins, and by checking each Compiled call once instead of every nested identifier.
10
+
11
+ ## 2.1.9
12
+
13
+ ### Patch Changes
14
+
15
+ - [`a4c26c5edfc0b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a4c26c5edfc0b) -
16
+ Allow local literal style values constrained with TypeScript `satisfies` expressions.
17
+ - [`1715d48a722a2`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1715d48a722a2) -
18
+ Migrate responsive styling to typed canonical CSS media-query keys. Allow those keys in the UI
19
+ Styling Standard and report non-canonical queries used with `satisfies`.
20
+
3
21
  ## 2.1.8
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -38,7 +38,7 @@ module.exports = {
38
38
  ## Rules
39
39
 
40
40
  <!-- START_RULE_TABLE_CODEGEN -->
41
- <!-- @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen -->
41
+ <!-- @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen -->
42
42
 
43
43
  | Rule | Description | Recommended | Fixable | Suggestions |
44
44
  | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ------- | ----------- |
@@ -20,8 +20,8 @@ var _index = require("./rules/index.codegen");
20
20
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
21
21
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
22
22
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
23
- * @codegen <<SignedSource::93c84481278f52fc66ecbba80094e6e5>>
24
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
23
+ * @codegen <<SignedSource::ef33ad38180e99be70285ddb225c56b9>>
24
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
25
25
  */
26
26
  // this uses require because not all node versions this package supports use the same import assertions/attributes
27
27
  // eslint-disable-next-line import/no-extraneous-dependencies
@@ -9,8 +9,8 @@ var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/esli
9
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); }
10
10
  /**
11
11
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
12
- * @codegen <<SignedSource::8a252381063c65bbbd7bd21e6a7f99a7>>
13
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
12
+ * @codegen <<SignedSource::ff4acc6ff3441b1ae527ac8371a3717b>>
13
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
14
14
  */
15
15
 
16
16
  var config = {
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::7d9130538f9fe4e88eebb9a6eb22e553>>
10
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
9
+ * @codegen <<SignedSource::64e947d21ff9764f69587dd1641711b6>>
10
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
 
13
13
  var config = {
@@ -9,8 +9,8 @@ var atlaskitDesignSystemPlugin = _interopRequireWildcard(require("@atlaskit/esli
9
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); }
10
10
  /**
11
11
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
12
- * @codegen <<SignedSource::8a252381063c65bbbd7bd21e6a7f99a7>>
13
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
12
+ * @codegen <<SignedSource::ff4acc6ff3441b1ae527ac8371a3717b>>
13
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
14
14
  */
15
15
 
16
16
  var config = {
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::7d9130538f9fe4e88eebb9a6eb22e553>>
10
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
9
+ * @codegen <<SignedSource::64e947d21ff9764f69587dd1641711b6>>
10
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
11
11
  */
12
12
 
13
13
  var config = {
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
7
9
  var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
8
10
  var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
9
11
  var _createRule = require("../utils/create-rule");
10
- var isIdentifierReferenced = function isIdentifierReferenced(hasImportSpecifier, node, references) {
11
- return references.some(function (reference) {
12
- var _reference$resolved;
13
- return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(hasImportSpecifier));
14
- });
15
- };
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
+ 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; }
16
15
  var isTypographyImportSpecifier = function isTypographyImportSpecifier(def) {
17
16
  var _def$parent, _def$parent2, _def$parent3;
18
17
  return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && (def.node.imported.name === 'typography' && ((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value) === '@atlaskit/theme' || ((_def$parent3 = def.parent) === null || _def$parent3 === void 0 ? void 0 : _def$parent3.source.value) === '@atlaskit/theme/typography');
@@ -25,26 +24,107 @@ var isSkeletonShimmerImportSpecifier = function isSkeletonShimmerImportSpecifier
25
24
  var _def$parent7, _def$parent8, _def$parent9;
26
25
  return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent7 = def.parent) === null || _def$parent7 === void 0 ? void 0 : _def$parent7.type) === 'ImportDeclaration' && def.node.imported.name === 'skeletonShimmer' && typeof ((_def$parent8 = def.parent) === null || _def$parent8 === void 0 ? void 0 : _def$parent8.source.value) === 'string' && ((_def$parent9 = def.parent) === null || _def$parent9 === void 0 || (_def$parent9 = _def$parent9.source.value) === null || _def$parent9 === void 0 ? void 0 : _def$parent9.startsWith('@atlaskit/theme'));
27
26
  };
28
- var checkIdentifier = function checkIdentifier(node, context, references) {
29
- if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
30
- context.report({
31
- messageId: 'usingTypography',
32
- node: node
33
- });
27
+ var bannedImportChecks = [{
28
+ messageId: 'usingTypography',
29
+ isBanned: isTypographyImportSpecifier
30
+ }, {
31
+ messageId: 'usingElevation',
32
+ isBanned: isElevationImportSpecifier
33
+ }, {
34
+ messageId: 'usingSkeletonShimmer',
35
+ isBanned: isSkeletonShimmerImportSpecifier
36
+ }];
37
+ function isAstNode(value) {
38
+ return (0, _typeof2.default)(value) === 'object' && value !== null && 'type' in value && typeof value.type === 'string';
39
+ }
40
+ function hasBannedThemeImport(sourceCode) {
41
+ var _iterator = _createForOfIteratorHelper(sourceCode.ast.body),
42
+ _step;
43
+ try {
44
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
45
+ var statement = _step.value;
46
+ if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
47
+ continue;
48
+ }
49
+ var source = statement.source.value;
50
+ if (!source.startsWith('@atlaskit/theme')) {
51
+ continue;
52
+ }
53
+ var _iterator2 = _createForOfIteratorHelper(statement.specifiers),
54
+ _step2;
55
+ try {
56
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
57
+ var specifier = _step2.value;
58
+ if (specifier.type !== 'ImportSpecifier' || specifier.imported.type !== 'Identifier') {
59
+ continue;
60
+ }
61
+ var name = specifier.imported.name;
62
+ if (source === '@atlaskit/theme/typography' || source === '@atlaskit/theme/elevation') {
63
+ return true;
64
+ }
65
+ if (source === '@atlaskit/theme' && (name === 'typography' || name === 'elevation')) {
66
+ return true;
67
+ }
68
+ if (name === 'skeletonShimmer') {
69
+ return true;
70
+ }
71
+ }
72
+ } catch (err) {
73
+ _iterator2.e(err);
74
+ } finally {
75
+ _iterator2.f();
76
+ }
77
+ }
78
+ } catch (err) {
79
+ _iterator.e(err);
80
+ } finally {
81
+ _iterator.f();
34
82
  }
35
- if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
36
- context.report({
37
- messageId: 'usingElevation',
38
- node: node
39
- });
83
+ return false;
84
+ }
85
+ function visitIdentifiers(node, visit) {
86
+ if (node.type === 'Identifier' && 'name' in node && typeof node.name === 'string') {
87
+ visit(node);
40
88
  }
41
- if (isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)) {
42
- context.report({
43
- messageId: 'usingSkeletonShimmer',
44
- node: node
45
- });
89
+ for (var _i = 0, _Object$keys = Object.keys(node); _i < _Object$keys.length; _i++) {
90
+ var key = _Object$keys[_i];
91
+ if (key === 'parent') {
92
+ continue;
93
+ }
94
+ var value = node[key];
95
+ if (Array.isArray(value)) {
96
+ var _iterator3 = _createForOfIteratorHelper(value),
97
+ _step3;
98
+ try {
99
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
100
+ var child = _step3.value;
101
+ if (isAstNode(child)) {
102
+ visitIdentifiers(child, visit);
103
+ }
104
+ }
105
+ } catch (err) {
106
+ _iterator3.e(err);
107
+ } finally {
108
+ _iterator3.f();
109
+ }
110
+ } else if (isAstNode(value)) {
111
+ visitIdentifiers(value, visit);
112
+ }
46
113
  }
47
- };
114
+ }
115
+ function findReferencedVariable(scope, identifier) {
116
+ var current = scope;
117
+ while (current) {
118
+ var variable = current.set.get(identifier.name);
119
+ if (variable !== null && variable !== void 0 && variable.references.some(function (reference) {
120
+ return reference.identifier === identifier;
121
+ })) {
122
+ return variable;
123
+ }
124
+ current = current.upper;
125
+ }
126
+ return undefined;
127
+ }
48
128
  var rule = (0, _createRule.createLintRule)({
49
129
  meta: {
50
130
  name: 'atlaskit-theme',
@@ -62,41 +142,68 @@ var rule = (0, _createRule.createLintRule)({
62
142
  type: 'problem'
63
143
  },
64
144
  create: function create(context) {
145
+ var sourceCode = (0, _contextCompat.getSourceCode)(context);
146
+ if (!hasBannedThemeImport(sourceCode)) {
147
+ return {};
148
+ }
65
149
  var importSources = (0, _isSupportedImport.getImportSources)(context);
66
- return {
67
- 'CallExpression Identifier': function CallExpression_Identifier(node) {
68
- var _getScope = (0, _contextCompat.getScope)(context, node),
69
- references = _getScope.references;
70
- var ancestors = (0, _contextCompat.getAncestors)(context, node);
71
-
72
- // Check if ancestor node is a call expression to Compiled
73
- if (ancestors.some(function (ancestor) {
74
- return ancestor.type === 'CallExpression' && ancestor.callee && (0, _isSupportedImport.isCompiled)(ancestor.callee, references, importSources);
75
- })) {
76
- // Ignore the fontFallback object as it contains strings to be used as token fallbacks
77
- if ('name' in node && node.name !== 'fontFallback') {
78
- // Check identifier for violations
79
- checkIdentifier(node, context, references);
80
- }
150
+ var reported = new WeakSet();
151
+ var reportBannedIdentifier = function reportBannedIdentifier(identifier, scope) {
152
+ if (identifier.name === 'fontFallback' || reported.has(identifier)) {
153
+ return;
154
+ }
155
+ var variable = findReferencedVariable(scope, identifier);
156
+ if (!variable) {
157
+ return;
158
+ }
159
+ var didReport = false;
160
+ for (var _i2 = 0, _bannedImportChecks = bannedImportChecks; _i2 < _bannedImportChecks.length; _i2++) {
161
+ var _bannedImportChecks$_ = _bannedImportChecks[_i2],
162
+ messageId = _bannedImportChecks$_.messageId,
163
+ isBanned = _bannedImportChecks$_.isBanned;
164
+ if (variable.defs.some(isBanned)) {
165
+ context.report({
166
+ messageId: messageId,
167
+ node: identifier
168
+ });
169
+ didReport = true;
81
170
  }
82
- },
83
- 'TaggedTemplateExpression Identifier': function TaggedTemplateExpression_Identifier(node) {
84
- var _getScope2 = (0, _contextCompat.getScope)(context, node),
85
- references = _getScope2.references;
86
- var ancestors = (0, _contextCompat.getAncestors)(context, node);
87
-
88
- // Check if ancestor node is a tagged template expression to Compiled
89
- if (ancestors.some(function (ancestor) {
90
- return ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && (0, _isSupportedImport.isCompiled)(ancestor.tag, references, importSources);
91
- })) {
92
- // Ignore the fontFallback object as it contains strings to be used as token fallbacks
93
- if ('name' in node && node.name !== 'fontFallback') {
94
- // Check identifier for violations
95
- checkIdentifier(node, context, references);
171
+ }
172
+ if (didReport) {
173
+ reported.add(identifier);
174
+ }
175
+ };
176
+ var lintCompiledInvocation = function lintCompiledInvocation(node) {
177
+ if (node.type !== 'CallExpression' && node.type !== 'TaggedTemplateExpression') {
178
+ return;
179
+ }
180
+ var calleeOrTag = node.type === 'CallExpression' ? node.callee : node.tag;
181
+ var scope = (0, _contextCompat.getScope)(context, node);
182
+ if (!(0, _isSupportedImport.isCompiled)(calleeOrTag, scope.references, importSources)) {
183
+ return;
184
+ }
185
+ var roots = node.type === 'CallExpression' ? node.arguments : node.quasi.expressions;
186
+ var _iterator4 = _createForOfIteratorHelper(roots),
187
+ _step4;
188
+ try {
189
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
190
+ var root = _step4.value;
191
+ if (isAstNode(root)) {
192
+ visitIdentifiers(root, function (identifier) {
193
+ return reportBannedIdentifier(identifier, scope);
194
+ });
96
195
  }
97
196
  }
197
+ } catch (err) {
198
+ _iterator4.e(err);
199
+ } finally {
200
+ _iterator4.f();
98
201
  }
99
202
  };
203
+ return {
204
+ CallExpression: lintCompiledInvocation,
205
+ TaggedTemplateExpression: lintCompiledInvocation
206
+ };
100
207
  }
101
208
  });
102
209
  var _default = exports.default = rule;
@@ -25,8 +25,8 @@ var _noUnusedCssmapProperties = _interopRequireDefault(require("./no-unused-cssm
25
25
  var _useCompiled = _interopRequireDefault(require("./use-compiled"));
26
26
  /**
27
27
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
28
- * @codegen <<SignedSource::2eab912b0c44d0fcbdc2f0b79cb42fa9>>
29
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
28
+ * @codegen <<SignedSource::fe6f7ad579eba2900d5adf5ee934c020>>
29
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
30
30
  */
31
31
 
32
32
  var rules = exports.rules = {
@@ -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 _iterator = _createForOfIteratorHelper((0, _styleCalls.getStyleCalls)(context)),
71
- _step;
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 = _step.value;
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
- if (value.type !== 'ObjectExpression' || key.type !== 'Literal' || typeof key.value !== 'string') {
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 _iterator2 = _createForOfIteratorHelper(selectorList.nodes),
119
- _step2;
203
+ var _iterator4 = _createForOfIteratorHelper(selectorList.nodes),
204
+ _step4;
120
205
  try {
121
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
122
- var selector = _step2.value;
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
- _iterator2.e(err);
217
+ _iterator4.e(err);
133
218
  } finally {
134
- _iterator2.f();
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 (_iterator.s(); !(_step = _iterator.n()).done;) {
232
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
148
233
  if (_loop()) continue;
149
234
  }
150
235
  } catch (err) {
151
- _iterator.e(err);
236
+ _iterator3.e(err);
152
237
  } finally {
153
- _iterator.f();
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,7 +1,7 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::93c84481278f52fc66ecbba80094e6e5>>
4
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
3
+ * @codegen <<SignedSource::ef33ad38180e99be70285ddb225c56b9>>
4
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  import allFlat from './presets/all-flat.codegen';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::8a252381063c65bbbd7bd21e6a7f99a7>>
4
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
3
+ * @codegen <<SignedSource::ff4acc6ff3441b1ae527ac8371a3717b>>
4
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  import * as atlaskitDesignSystemPlugin from '@atlaskit/eslint-plugin-design-system';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d9130538f9fe4e88eebb9a6eb22e553>>
4
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
3
+ * @codegen <<SignedSource::64e947d21ff9764f69587dd1641711b6>>
4
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  const config = {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::8a252381063c65bbbd7bd21e6a7f99a7>>
4
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
3
+ * @codegen <<SignedSource::ff4acc6ff3441b1ae527ac8371a3717b>>
4
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  import * as atlaskitDesignSystemPlugin from '@atlaskit/eslint-plugin-design-system';
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d9130538f9fe4e88eebb9a6eb22e553>>
4
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
3
+ * @codegen <<SignedSource::64e947d21ff9764f69587dd1641711b6>>
4
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
 
7
7
  const config = {