@atlaskit/eslint-plugin-ui-styling-standard 2.1.5 → 2.1.6

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,14 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 2.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`eac2b82a415cd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/eac2b82a415cd) -
8
+ Allow statically written style keys annotated with TypeScript `satisfies` expressions.
9
+ `no-unsafe-values` no longer reports a computed key that unwraps to a string literal, and
10
+ `no-imported-style-values` no longer reports imported identifiers used in type positions.
11
+
3
12
  ## 2.1.5
4
13
 
5
14
  ### Patch Changes
@@ -80,6 +80,13 @@ var checkIdentifier = function checkIdentifier(identifier, context, functionAllo
80
80
  var _ref = identifier,
81
81
  parent = _ref.parent;
82
82
 
83
+ // Type references and `typeof` queries are erased at runtime and are not
84
+ // imported style values. Runtime expressions wrapped by `as` or `satisfies`
85
+ // must still be checked.
86
+ if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
87
+ return;
88
+ }
89
+
83
90
  // Even though `member` in `object.member` is syntactically an identifier,
84
91
  // it should be ignored as `.member` is syntax sugar for `['member']` here.
85
92
  // We should still lint `object[member]` (when `parent.computed` === true)
@@ -13,6 +13,13 @@ var _findVariable = require("@atlaskit/eslint-utils/find-variable");
13
13
  function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
14
14
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
15
15
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
16
+ var unwrapSatisfiesExpression = function unwrapSatisfiesExpression(node) {
17
+ var currentNode = node;
18
+ while (currentNode.type === 'TSSatisfiesExpression') {
19
+ currentNode = currentNode.expression;
20
+ }
21
+ return currentNode;
22
+ };
16
23
  function isReferenceToCssVar(variable) {
17
24
  var definitions = variable.defs;
18
25
  return definitions.every(function (definition) {
@@ -189,6 +196,16 @@ var Linter = exports.Linter = /*#__PURE__*/function () {
189
196
  }, {
190
197
  key: "lintKey",
191
198
  value: function lintKey(property) {
199
+ var key = property.key;
200
+
201
+ // A type-only `satisfies` annotation preserves a static key at runtime.
202
+ // It is safe for the same reason as a directly written string literal.
203
+ var unwrappedKey = unwrapSatisfiesExpression(key);
204
+ var isSatisfiesExpression = unwrappedKey !== key;
205
+ if (property.computed && isSatisfiesExpression && unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
206
+ return;
207
+ }
208
+
192
209
  /**
193
210
  * If it's not computed then it must be a plain string.
194
211
  *
@@ -69,6 +69,13 @@ const checkIdentifier = (identifier, context, functionAllowList, keysAllowList)
69
69
  parent
70
70
  } = identifier;
71
71
 
72
+ // Type references and `typeof` queries are erased at runtime and are not
73
+ // imported style values. Runtime expressions wrapped by `as` or `satisfies`
74
+ // must still be checked.
75
+ if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
76
+ return;
77
+ }
78
+
72
79
  // Even though `member` in `object.member` is syntactically an identifier,
73
80
  // it should be ignored as `.member` is syntax sugar for `['member']` here.
74
81
  // We should still lint `object[member]` (when `parent.computed` === true)
@@ -1,6 +1,13 @@
1
1
  import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
2
2
  import { findIdentifierNode } from '@atlaskit/eslint-utils/find-identifier-node';
3
3
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
4
+ const unwrapSatisfiesExpression = node => {
5
+ let currentNode = node;
6
+ while (currentNode.type === 'TSSatisfiesExpression') {
7
+ currentNode = currentNode.expression;
8
+ }
9
+ return currentNode;
10
+ };
4
11
  function isReferenceToCssVar(variable) {
5
12
  const definitions = variable.defs;
6
13
  return definitions.every(definition => {
@@ -156,6 +163,16 @@ export class Linter {
156
163
  });
157
164
  }
158
165
  lintKey(property) {
166
+ const key = property.key;
167
+
168
+ // A type-only `satisfies` annotation preserves a static key at runtime.
169
+ // It is safe for the same reason as a directly written string literal.
170
+ const unwrappedKey = unwrapSatisfiesExpression(key);
171
+ const isSatisfiesExpression = unwrappedKey !== key;
172
+ if (property.computed && isSatisfiesExpression && unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
173
+ return;
174
+ }
175
+
159
176
  /**
160
177
  * If it's not computed then it must be a plain string.
161
178
  *
@@ -73,6 +73,13 @@ var checkIdentifier = function checkIdentifier(identifier, context, functionAllo
73
73
  var _ref = identifier,
74
74
  parent = _ref.parent;
75
75
 
76
+ // Type references and `typeof` queries are erased at runtime and are not
77
+ // imported style values. Runtime expressions wrapped by `as` or `satisfies`
78
+ // must still be checked.
79
+ if (parent && (parent.type === 'TSTypeReference' || parent.type === 'TSTypeQuery')) {
80
+ return;
81
+ }
82
+
76
83
  // Even though `member` in `object.member` is syntactically an identifier,
77
84
  // it should be ignored as `.member` is syntax sugar for `['member']` here.
78
85
  // We should still lint `object[member]` (when `parent.computed` === true)
@@ -6,6 +6,13 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
6
6
  import { getAllowedDynamicKeys, getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
7
7
  import { findIdentifierNode } from '@atlaskit/eslint-utils/find-identifier-node';
8
8
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
9
+ var unwrapSatisfiesExpression = function unwrapSatisfiesExpression(node) {
10
+ var currentNode = node;
11
+ while (currentNode.type === 'TSSatisfiesExpression') {
12
+ currentNode = currentNode.expression;
13
+ }
14
+ return currentNode;
15
+ };
9
16
  function isReferenceToCssVar(variable) {
10
17
  var definitions = variable.defs;
11
18
  return definitions.every(function (definition) {
@@ -182,6 +189,16 @@ export var Linter = /*#__PURE__*/function () {
182
189
  }, {
183
190
  key: "lintKey",
184
191
  value: function lintKey(property) {
192
+ var key = property.key;
193
+
194
+ // A type-only `satisfies` annotation preserves a static key at runtime.
195
+ // It is safe for the same reason as a directly written string literal.
196
+ var unwrappedKey = unwrapSatisfiesExpression(key);
197
+ var isSatisfiesExpression = unwrappedKey !== key;
198
+ if (property.computed && isSatisfiesExpression && unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
199
+ return;
200
+ }
201
+
185
202
  /**
186
203
  * If it's not computed then it must be a plain string.
187
204
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "2.1.5",
3
+ "version": "2.1.6",
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,10 +28,10 @@
28
28
  ],
29
29
  "atlaskit:src": "src/index.tsx",
30
30
  "dependencies": {
31
- "@atlaskit/eslint-plugin-design-system": "^16.11.0",
31
+ "@atlaskit/eslint-plugin-design-system": "^16.12.0",
32
32
  "@atlaskit/eslint-utils": "^3.1.0",
33
33
  "@babel/runtime": "^7.0.0",
34
- "@typescript-eslint/utils": "^7.1.0",
34
+ "@typescript-eslint/utils": "^8.64.0",
35
35
  "ajv": "^6.12.6",
36
36
  "eslint-codemod-utils": "^1.8.6",
37
37
  "eslint-scope": "^8.0.0",
@@ -44,7 +44,7 @@
44
44
  "devDependencies": {
45
45
  "@af/formatting": "workspace:^",
46
46
  "@atlaskit/ds-lib": "^8.0.0",
47
- "@atlassian/codegen": "^0.2.0",
47
+ "@atlassian/codegen": "^0.3.0",
48
48
  "@atlassian/ts-loader": "^0.1.0",
49
49
  "@eslint/eslintrc": "^3.0.2",
50
50
  "@types/eslint": "^8.56.6",