@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
@@ -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 _iterator = _createForOfIteratorHelper(getStyleCalls(context)),
65
- _step;
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 = _step.value;
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
- if (value.type !== 'ObjectExpression' || key.type !== 'Literal' || typeof key.value !== 'string') {
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 _iterator2 = _createForOfIteratorHelper(selectorList.nodes),
113
- _step2;
197
+ var _iterator4 = _createForOfIteratorHelper(selectorList.nodes),
198
+ _step4;
114
199
  try {
115
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
116
- var selector = _step2.value;
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
- _iterator2.e(err);
211
+ _iterator4.e(err);
127
212
  } finally {
128
- _iterator2.f();
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 (_iterator.s(); !(_step = _iterator.n()).done;) {
226
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
142
227
  if (_loop()) continue;
143
228
  }
144
229
  } catch (err) {
145
- _iterator.e(err);
230
+ _iterator3.e(err);
146
231
  } finally {
147
- _iterator.f();
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;
@@ -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
  import type { ESLint } from 'eslint';
7
7
  export declare const plugin: ESLint.Plugin;
@@ -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
  import type { Linter } from 'eslint';
7
7
  declare const config: Linter.FlatConfig;
@@ -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
  import type { ESLint } from 'eslint';
7
7
  declare const config: ESLint.ConfigData;
@@ -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
  import type { Linter } from 'eslint';
7
7
  declare const config: Linter.FlatConfig;
@@ -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
  import type { ESLint } from 'eslint';
7
7
  declare const config: ESLint.ConfigData;
@@ -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::2eab912b0c44d0fcbdc2f0b79cb42fa9>>
4
- * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
3
+ * @codegen <<SignedSource::fe6f7ad579eba2900d5adf5ee934c020>>
4
+ * @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  import type { Rule } from 'eslint';
7
7
  export declare const rules: Record<string, Rule.RuleModule>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "2.1.8",
3
+ "version": "2.1.10",
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.12.0",
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",