@atlaskit/eslint-plugin-ui-styling-standard 2.4.0 → 2.4.1

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 2.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`3e2e34bcc2601`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3e2e34bcc2601) -
8
+ `no-imported-style-values`: no longer reports imported identifiers used in qualified type
9
+ positions, such as `'value' satisfies typeof Tokens.COLOR_TEXT` or
10
+ `'value' satisfies Theme.Color`. These are erased at runtime and are not imported style values.
11
+ - [`a5979af0b9045`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/a5979af0b9045) -
12
+ `no-nested-selectors` now lints computed keys wrapped in TypeScript expressions (`satisfies`,
13
+ `as`, type assertions, non-null), e.g. `['.foo' satisfies \`.${typeof FOO_CLASS}\`]`. Previously
14
+ these keys were silently skipped.
15
+
3
16
  ## 2.4.0
4
17
 
5
18
  ### Minor Changes
@@ -83,7 +83,14 @@ var checkIdentifier = function checkIdentifier(identifier, context, functionAllo
83
83
  // Type references and `typeof` queries are erased at runtime and are not
84
84
  // imported style values. Runtime expressions wrapped by `as` or `satisfies`
85
85
  // must still be checked.
86
- if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
86
+ // Qualified names (e.g. `typeof Tokens.COLOR_TEXT` or `Theme.Colors`) nest the
87
+ // identifier inside one or more `TSQualifiedName` nodes, so walk up through them
88
+ // to find the enclosing type node.
89
+ var typeContext = parent;
90
+ while (typeContext && typeContext.type === 'TSQualifiedName') {
91
+ typeContext = typeContext.parent;
92
+ }
93
+ if (typeContext && (typeContext.type === 'TSTypeReference' || typeContext.type === 'TSTypeQuery')) {
87
94
  return;
88
95
  }
89
96
 
@@ -16,7 +16,19 @@ var _walkStyleCallProperties = require("../utils/walk-style-call-properties");
16
16
  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
17
  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
18
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
- var getCssSelector = function getCssSelector(key) {
19
+ /**
20
+ * Strip TypeScript-only wrappers from a computed key so the selector inside is still linted,
21
+ * for example `['.foo' satisfies `.${typeof FOO_CLASS}`]` is checked as `'.foo'`.
22
+ */
23
+ var unwrapTypeScriptExpression = function unwrapTypeScriptExpression(key) {
24
+ var expression = key;
25
+ while ((expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') && expression.expression) {
26
+ expression = expression.expression;
27
+ }
28
+ return expression;
29
+ };
30
+ var getCssSelector = function getCssSelector(rawKey) {
31
+ var key = unwrapTypeScriptExpression(rawKey);
20
32
  if (key.type === 'Literal' && typeof key.value === 'string') {
21
33
  return key.value;
22
34
  }
@@ -72,7 +72,14 @@ const checkIdentifier = (identifier, context, functionAllowList, keysAllowList)
72
72
  // Type references and `typeof` queries are erased at runtime and are not
73
73
  // imported style values. Runtime expressions wrapped by `as` or `satisfies`
74
74
  // must still be checked.
75
- if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
75
+ // Qualified names (e.g. `typeof Tokens.COLOR_TEXT` or `Theme.Colors`) nest the
76
+ // identifier inside one or more `TSQualifiedName` nodes, so walk up through them
77
+ // to find the enclosing type node.
78
+ let typeContext = parent;
79
+ while (typeContext && typeContext.type === 'TSQualifiedName') {
80
+ typeContext = typeContext.parent;
81
+ }
82
+ if (typeContext && (typeContext.type === 'TSTypeReference' || typeContext.type === 'TSTypeQuery')) {
76
83
  return;
77
84
  }
78
85
 
@@ -5,7 +5,19 @@ import { isSimpleSelector } from '../utils/is-simple-selector';
5
5
  import { parseSelector } from '../utils/parse-selector';
6
6
  import { getStyleCalls } from '../utils/style-calls';
7
7
  import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
8
- const getCssSelector = key => {
8
+ /**
9
+ * Strip TypeScript-only wrappers from a computed key so the selector inside is still linted,
10
+ * for example `['.foo' satisfies `.${typeof FOO_CLASS}`]` is checked as `'.foo'`.
11
+ */
12
+ const unwrapTypeScriptExpression = key => {
13
+ let expression = key;
14
+ while ((expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') && expression.expression) {
15
+ expression = expression.expression;
16
+ }
17
+ return expression;
18
+ };
19
+ const getCssSelector = rawKey => {
20
+ const key = unwrapTypeScriptExpression(rawKey);
9
21
  if (key.type === 'Literal' && typeof key.value === 'string') {
10
22
  return key.value;
11
23
  }
@@ -76,7 +76,14 @@ var checkIdentifier = function checkIdentifier(identifier, context, functionAllo
76
76
  // Type references and `typeof` queries are erased at runtime and are not
77
77
  // imported style values. Runtime expressions wrapped by `as` or `satisfies`
78
78
  // must still be checked.
79
- if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
79
+ // Qualified names (e.g. `typeof Tokens.COLOR_TEXT` or `Theme.Colors`) nest the
80
+ // identifier inside one or more `TSQualifiedName` nodes, so walk up through them
81
+ // to find the enclosing type node.
82
+ var typeContext = parent;
83
+ while (typeContext && typeContext.type === 'TSQualifiedName') {
84
+ typeContext = typeContext.parent;
85
+ }
86
+ if (typeContext && (typeContext.type === 'TSTypeReference' || typeContext.type === 'TSTypeQuery')) {
80
87
  return;
81
88
  }
82
89
 
@@ -9,7 +9,19 @@ import { isSimpleSelector } from '../utils/is-simple-selector';
9
9
  import { parseSelector } from '../utils/parse-selector';
10
10
  import { getStyleCalls } from '../utils/style-calls';
11
11
  import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
12
- var getCssSelector = function getCssSelector(key) {
12
+ /**
13
+ * Strip TypeScript-only wrappers from a computed key so the selector inside is still linted,
14
+ * for example `['.foo' satisfies `.${typeof FOO_CLASS}`]` is checked as `'.foo'`.
15
+ */
16
+ var unwrapTypeScriptExpression = function unwrapTypeScriptExpression(key) {
17
+ var expression = key;
18
+ while ((expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') && expression.expression) {
19
+ expression = expression.expression;
20
+ }
21
+ return expression;
22
+ };
23
+ var getCssSelector = function getCssSelector(rawKey) {
24
+ var key = unwrapTypeScriptExpression(rawKey);
13
25
  if (key.type === 'Literal' && typeof key.value === 'string') {
14
26
  return key.value;
15
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
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",