@atlaskit/eslint-plugin-ui-styling-standard 3.0.0 → 3.0.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,14 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 3.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`2a6c8a9e812fc`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2a6c8a9e812fc) -
8
+ `no-important-styles` now reports `!important` values wrapped in TypeScript expressions, e.g.
9
+ `color: 'red !important' as const`, and values inside wrapped style objects such as
10
+ `css({…} as const)` or `'&:hover': {…} as const`. Previously these were skipped.
11
+
3
12
  ## 3.0.0
4
13
 
5
14
  ### Major Changes
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _contextCompat = require("@atlaskit/eslint-utils/context-compat");
8
8
  var _schema = require("@atlaskit/eslint-utils/schema");
9
9
  var _createRuleWithTypedConfig = require("../utils/create-rule-with-typed-config");
10
+ var _isTypeWrapper = require("../utils/is-type-wrapper");
10
11
  var _styleCalls = require("../utils/style-calls");
11
12
  var rule = (0, _createRuleWithTypedConfig.createLintRuleWithTypedConfig)({
12
13
  meta: {
@@ -77,10 +78,34 @@ function isInSupportedStyleCall(context, value, importSources) {
77
78
  return styleCall.node === call && importSources.includes(styleCall.importSource);
78
79
  }));
79
80
  }
81
+
82
+ /**
83
+ * Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
84
+ * outermost wrapper, which is what the next parent refers to, and that parent.
85
+ */
86
+ function climbTypeWrappers(node) {
87
+ var current = node;
88
+ var parent = current.parent;
89
+ while (parent && (0, _isTypeWrapper.isTypeWrapper)(parent)) {
90
+ current = parent;
91
+ parent = current.parent;
92
+ }
93
+ return {
94
+ node: current,
95
+ parent: parent
96
+ };
97
+ }
98
+
99
+ /**
100
+ * Find the style call a value belongs to, looking through TypeScript wrappers at every level:
101
+ * `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
102
+ */
80
103
  function findContainingCall(value) {
81
- var _property, _object;
82
- var property = value.parent;
83
- if (((_property = property) === null || _property === void 0 ? void 0 : _property.type) !== 'Property' || property.value !== value) {
104
+ var _object;
105
+ var _climbTypeWrappers = climbTypeWrappers(value),
106
+ wrappedValue = _climbTypeWrappers.node,
107
+ property = _climbTypeWrappers.parent;
108
+ if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
84
109
  return null;
85
110
  }
86
111
  var object = property.parent;
@@ -89,20 +114,21 @@ function findContainingCall(value) {
89
114
  }
90
115
  while (object) {
91
116
  var _parent$parent;
92
- var parent = object.parent;
93
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === object) {
117
+ var _climbTypeWrappers2 = climbTypeWrappers(object),
118
+ wrappedObject = _climbTypeWrappers2.node,
119
+ parent = _climbTypeWrappers2.parent;
120
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
94
121
  var _object2;
95
- property = parent;
96
- object = property.parent;
122
+ object = parent.parent;
97
123
  if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
98
124
  return null;
99
125
  }
100
126
  continue;
101
127
  }
102
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(object)) {
128
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
103
129
  return parent;
104
130
  }
105
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === object && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
131
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
106
132
  return parent.parent;
107
133
  }
108
134
  return null;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isTypeWrapper = isTypeWrapper;
7
+ /**
8
+ * TypeScript-only wrappers around an expression that ESTree does not model. None of them change
9
+ * the runtime value, so a rule reading a style key, value or argument should look through them:
10
+ *
11
+ * - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
12
+ * - `color: 'red !important' as const`
13
+ * - `css({…} as const)`
14
+ * - `<T>{…}` and `value!`
15
+ */
16
+ var TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
17
+
18
+ /**
19
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
20
+ */
21
+ function isTypeWrapper(node) {
22
+ return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
23
+ }
@@ -1,6 +1,7 @@
1
1
  import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
2
2
  import { importSources } from '@atlaskit/eslint-utils/schema';
3
3
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
4
+ import { isTypeWrapper } from '../utils/is-type-wrapper';
4
5
  import { getStyleCalls } from '../utils/style-calls';
5
6
  const rule = createLintRuleWithTypedConfig({
6
7
  meta: {
@@ -72,10 +73,35 @@ function isInSupportedStyleCall(context, value, importSources) {
72
73
  const call = findContainingCall(value);
73
74
  return Boolean(call && getStyleCalls(context).some(styleCall => styleCall.node === call && importSources.includes(styleCall.importSource)));
74
75
  }
76
+
77
+ /**
78
+ * Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
79
+ * outermost wrapper, which is what the next parent refers to, and that parent.
80
+ */
81
+ function climbTypeWrappers(node) {
82
+ let current = node;
83
+ let parent = current.parent;
84
+ while (parent && isTypeWrapper(parent)) {
85
+ current = parent;
86
+ parent = current.parent;
87
+ }
88
+ return {
89
+ node: current,
90
+ parent
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Find the style call a value belongs to, looking through TypeScript wrappers at every level:
96
+ * `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
97
+ */
75
98
  function findContainingCall(value) {
76
- var _property, _object;
77
- let property = value.parent;
78
- if (((_property = property) === null || _property === void 0 ? void 0 : _property.type) !== 'Property' || property.value !== value) {
99
+ var _object;
100
+ const {
101
+ node: wrappedValue,
102
+ parent: property
103
+ } = climbTypeWrappers(value);
104
+ if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
79
105
  return null;
80
106
  }
81
107
  let object = property.parent;
@@ -84,20 +110,22 @@ function findContainingCall(value) {
84
110
  }
85
111
  while (object) {
86
112
  var _parent$parent;
87
- const parent = object.parent;
88
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === object) {
113
+ const {
114
+ node: wrappedObject,
115
+ parent
116
+ } = climbTypeWrappers(object);
117
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
89
118
  var _object2;
90
- property = parent;
91
- object = property.parent;
119
+ object = parent.parent;
92
120
  if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
93
121
  return null;
94
122
  }
95
123
  continue;
96
124
  }
97
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(object)) {
125
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
98
126
  return parent;
99
127
  }
100
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === object && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
128
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
101
129
  return parent.parent;
102
130
  }
103
131
  return null;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * TypeScript-only wrappers around an expression that ESTree does not model. None of them change
3
+ * the runtime value, so a rule reading a style key, value or argument should look through them:
4
+ *
5
+ * - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
6
+ * - `color: 'red !important' as const`
7
+ * - `css({…} as const)`
8
+ * - `<T>{…}` and `value!`
9
+ */
10
+ const TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
11
+
12
+ /**
13
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
14
+ */
15
+ export function isTypeWrapper(node) {
16
+ return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
17
+ }
@@ -1,6 +1,7 @@
1
1
  import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
2
2
  import { importSources } from '@atlaskit/eslint-utils/schema';
3
3
  import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
4
+ import { isTypeWrapper } from '../utils/is-type-wrapper';
4
5
  import { getStyleCalls } from '../utils/style-calls';
5
6
  var rule = createLintRuleWithTypedConfig({
6
7
  meta: {
@@ -71,10 +72,34 @@ function isInSupportedStyleCall(context, value, importSources) {
71
72
  return styleCall.node === call && importSources.includes(styleCall.importSource);
72
73
  }));
73
74
  }
75
+
76
+ /**
77
+ * Step up from `node` past any TypeScript wrappers (`as`, `satisfies`, `<T>`, `!`). Returns the
78
+ * outermost wrapper, which is what the next parent refers to, and that parent.
79
+ */
80
+ function climbTypeWrappers(node) {
81
+ var current = node;
82
+ var parent = current.parent;
83
+ while (parent && isTypeWrapper(parent)) {
84
+ current = parent;
85
+ parent = current.parent;
86
+ }
87
+ return {
88
+ node: current,
89
+ parent: parent
90
+ };
91
+ }
92
+
93
+ /**
94
+ * Find the style call a value belongs to, looking through TypeScript wrappers at every level:
95
+ * `color: 'red !important' as const`, `'&:hover': {…} as const` and `css({…} as const)`.
96
+ */
74
97
  function findContainingCall(value) {
75
- var _property, _object;
76
- var property = value.parent;
77
- if (((_property = property) === null || _property === void 0 ? void 0 : _property.type) !== 'Property' || property.value !== value) {
98
+ var _object;
99
+ var _climbTypeWrappers = climbTypeWrappers(value),
100
+ wrappedValue = _climbTypeWrappers.node,
101
+ property = _climbTypeWrappers.parent;
102
+ if ((property === null || property === void 0 ? void 0 : property.type) !== 'Property' || property.value !== wrappedValue) {
78
103
  return null;
79
104
  }
80
105
  var object = property.parent;
@@ -83,20 +108,21 @@ function findContainingCall(value) {
83
108
  }
84
109
  while (object) {
85
110
  var _parent$parent;
86
- var parent = object.parent;
87
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === object) {
111
+ var _climbTypeWrappers2 = climbTypeWrappers(object),
112
+ wrappedObject = _climbTypeWrappers2.node,
113
+ parent = _climbTypeWrappers2.parent;
114
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'Property' && parent.value === wrappedObject) {
88
115
  var _object2;
89
- property = parent;
90
- object = property.parent;
116
+ object = parent.parent;
91
117
  if (((_object2 = object) === null || _object2 === void 0 ? void 0 : _object2.type) !== 'ObjectExpression') {
92
118
  return null;
93
119
  }
94
120
  continue;
95
121
  }
96
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(object)) {
122
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'CallExpression' && parent.arguments.includes(wrappedObject)) {
97
123
  return parent;
98
124
  }
99
- if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === object && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
125
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) === 'ArrowFunctionExpression' && parent.body === wrappedObject && ((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === 'CallExpression' && parent.parent.arguments.includes(parent)) {
100
126
  return parent.parent;
101
127
  }
102
128
  return null;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * TypeScript-only wrappers around an expression that ESTree does not model. None of them change
3
+ * the runtime value, so a rule reading a style key, value or argument should look through them:
4
+ *
5
+ * - `['.foo' satisfies `.${typeof FOO_CLASS}`]: {…}`
6
+ * - `color: 'red !important' as const`
7
+ * - `css({…} as const)`
8
+ * - `<T>{…}` and `value!`
9
+ */
10
+ var TYPE_WRAPPER_TYPES = new Set(['TSAsExpression', 'TSNonNullExpression', 'TSSatisfiesExpression', 'TSTypeAssertion']);
11
+
12
+ /**
13
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
14
+ */
15
+ export function isTypeWrapper(node) {
16
+ return Boolean(node && TYPE_WRAPPER_TYPES.has(node.type));
17
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Whether `node` is a TypeScript wrapper (`as`, `satisfies`, `<T>`, `!`) around an expression.
3
+ */
4
+ export declare function isTypeWrapper(node: {
5
+ type: string;
6
+ } | null | undefined): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "3.0.0",
3
+ "version": "3.0.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",