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

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,21 @@
1
1
  # @atlaskit/eslint-plugin-ui-styling-standard
2
2
 
3
+ ## 2.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - [`f0c3543359684`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f0c3543359684) -
8
+ Allow safe local named dimension-based container queries
9
+
10
+ ## 2.1.6
11
+
12
+ ### Patch Changes
13
+
14
+ - [`eac2b82a415cd`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/eac2b82a415cd) -
15
+ Allow statically written style keys annotated with TypeScript `satisfies` expressions.
16
+ `no-unsafe-values` no longer reports a computed key that unwraps to a string literal, and
17
+ `no-imported-style-values` no longer reports imported identifiers used in type positions.
18
+
3
19
  ## 2.1.5
4
20
 
5
21
  ### Patch Changes
@@ -36,6 +36,38 @@ var isStaticContainerKey = function isStaticContainerKey(node) {
36
36
  }
37
37
  return expression.type === 'TemplateLiteral' && ((_expression$expressio = expression.expressions) === null || _expression$expressio === void 0 ? void 0 : _expression$expressio.length) === 0;
38
38
  };
39
+ var getStaticString = function getStaticString(node) {
40
+ var _expression$expressio2;
41
+ if (!node) {
42
+ return undefined;
43
+ }
44
+ var expression = unwrapTypeScriptExpression(node);
45
+ if (expression.type === 'Literal') {
46
+ var value = expression.value;
47
+ return typeof value === 'string' ? value : undefined;
48
+ }
49
+ if (expression.type === 'TemplateLiteral' && ((_expression$expressio2 = expression.expressions) === null || _expression$expressio2 === void 0 ? void 0 : _expression$expressio2.length) === 0) {
50
+ var _expression$quasis;
51
+ return (_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 || (_expression$quasis = _expression$quasis[0]) === null || _expression$quasis === void 0 || (_expression$quasis = _expression$quasis.value) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.raw;
52
+ }
53
+ return undefined;
54
+ };
55
+ var getPropertyName = function getPropertyName(node) {
56
+ var expression = unwrapTypeScriptExpression(node);
57
+ return expression.type === 'Identifier' ? expression.name : getStaticString(expression);
58
+ };
59
+ var isDimensionQuery = function isDimensionQuery(query) {
60
+ // Policy source: https://hello.atlassian.net/wiki/spaces/~7012119e15ecf78c74278a34bd6681745f7bb/pages/2595609668/What+would+it+take+to+get+container+queries+working
61
+ var condition = query.replace(/^@container\s+[-_a-zA-Z][-_a-zA-Z0-9]*\s*/, '');
62
+ return !condition.includes('style(') && /\b(?:width|height|min-width|max-width|min-height|max-height)\b/i.test(condition);
63
+ };
64
+ var getContainerName = function getContainerName(query) {
65
+ var match = query.match(/^@container\s+([-_a-zA-Z][-_a-zA-Z0-9]*)\b/);
66
+ return match === null || match === void 0 ? void 0 : match[1];
67
+ };
68
+ var isContainerDeclaration = function isContainerDeclaration(node) {
69
+ return getPropertyName(node) === 'containerName';
70
+ };
39
71
  var isImportedContainerType = function isImportedContainerType(node, context) {
40
72
  var expression = node;
41
73
  var _loop = function _loop() {
@@ -65,12 +97,12 @@ var isImportedContainerType = function isImportedContainerType(node, context) {
65
97
  return false;
66
98
  };
67
99
  var isContainerQuery = function isContainerQuery(node) {
68
- var _expression$quasis;
100
+ var _expression$quasis2;
69
101
  var expression = unwrapTypeScriptExpression(node);
70
102
  if (expression.type === 'Literal' && typeof expression.value === 'string') {
71
103
  return expression.value.includes('@container');
72
104
  }
73
- return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.some(function (quasi) {
105
+ return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis2 = expression.quasis) === null || _expression$quasis2 === void 0 ? void 0 : _expression$quasis2.some(function (quasi) {
74
106
  var _quasi$value;
75
107
  return (_quasi$value = quasi.value) === null || _quasi$value === void 0 || (_quasi$value = _quasi$value.raw) === null || _quasi$value === void 0 ? void 0 : _quasi$value.includes('@container');
76
108
  }));
@@ -84,14 +116,36 @@ var rule = (0, _createRule.createLintRule)({
84
116
  severity: 'error'
85
117
  },
86
118
  messages: {
87
- 'no-container-queries': 'We block @container queries as they break scope and are not type-safe. We suggest alternatives such as JS-based APIs or @media queries.'
119
+ 'no-container-queries': '@container queries must use a named container declared in the same file and a width/height-based condition.',
120
+ 'no-container-style-queries': 'Style queries are not allowed. Use a width/height-based @container query instead.',
121
+ 'no-unbound-container-queries': 'Container queries must include a container name, for example @container card (min-width: 30rem).',
122
+ 'no-mismatched-container-name': 'The @container name must match a containerName declared in the same file.',
123
+ 'no-non-dimension-container-queries': 'Container queries must be dimension-based (width or height); style and other feature queries are not allowed.'
88
124
  },
89
125
  type: 'problem',
90
126
  schema: schema
91
127
  },
92
128
  create: function create(context) {
93
129
  var importSources = (0, _isSupportedImport.getImportSources)(context);
130
+ var containerNames = new Set();
94
131
  return {
132
+ Program: function Program(node) {
133
+ _estraverse.default.traverse(node, {
134
+ enter: function enter(child) {
135
+ if (child.type !== 'Property') {
136
+ return;
137
+ }
138
+ var property = child;
139
+ if (isContainerDeclaration(property.key)) {
140
+ var id = getStaticString(property.value);
141
+ if (id) {
142
+ containerNames.add(id);
143
+ }
144
+ }
145
+ },
146
+ fallback: 'iteration'
147
+ });
148
+ },
95
149
  CallExpression: function CallExpression(node) {
96
150
  var _getScope = (0, _contextCompat.getScope)(context, node),
97
151
  references = _getScope.references;
@@ -105,12 +159,15 @@ var rule = (0, _createRule.createLintRule)({
105
159
  if (!isContainerQuery(key)) {
106
160
  return;
107
161
  }
108
- if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression)) {
162
+ var query = getStaticString(key);
163
+ var queryName = query ? getContainerName(query) : undefined;
164
+ var reportMessageId = !query ? 'no-container-queries' : query.includes('style(') ? 'no-container-style-queries' : !queryName ? 'no-unbound-container-queries' : !containerNames.has(queryName) ? 'no-mismatched-container-name' : !isDimensionQuery(query) ? 'no-non-dimension-container-queries' : 'no-container-queries';
165
+ if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression) && query && queryName && containerNames.has(queryName) && isDimensionQuery(query)) {
109
166
  return;
110
167
  }
111
168
  context.report({
112
169
  node: node.key,
113
- messageId: 'no-container-queries'
170
+ messageId: reportMessageId
114
171
  });
115
172
  },
116
173
  /**
@@ -29,6 +29,38 @@ const isStaticContainerKey = node => {
29
29
  }
30
30
  return expression.type === 'TemplateLiteral' && ((_expression$expressio = expression.expressions) === null || _expression$expressio === void 0 ? void 0 : _expression$expressio.length) === 0;
31
31
  };
32
+ const getStaticString = node => {
33
+ var _expression$expressio2;
34
+ if (!node) {
35
+ return undefined;
36
+ }
37
+ const expression = unwrapTypeScriptExpression(node);
38
+ if (expression.type === 'Literal') {
39
+ const value = expression.value;
40
+ return typeof value === 'string' ? value : undefined;
41
+ }
42
+ if (expression.type === 'TemplateLiteral' && ((_expression$expressio2 = expression.expressions) === null || _expression$expressio2 === void 0 ? void 0 : _expression$expressio2.length) === 0) {
43
+ var _expression$quasis, _expression$quasis$, _expression$quasis$$v;
44
+ return (_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 ? void 0 : (_expression$quasis$ = _expression$quasis[0]) === null || _expression$quasis$ === void 0 ? void 0 : (_expression$quasis$$v = _expression$quasis$.value) === null || _expression$quasis$$v === void 0 ? void 0 : _expression$quasis$$v.raw;
45
+ }
46
+ return undefined;
47
+ };
48
+ const getPropertyName = node => {
49
+ const expression = unwrapTypeScriptExpression(node);
50
+ return expression.type === 'Identifier' ? expression.name : getStaticString(expression);
51
+ };
52
+ const isDimensionQuery = query => {
53
+ // Policy source: https://hello.atlassian.net/wiki/spaces/~7012119e15ecf78c74278a34bd6681745f7bb/pages/2595609668/What+would+it+take+to+get+container+queries+working
54
+ const condition = query.replace(/^@container\s+[-_a-zA-Z][-_a-zA-Z0-9]*\s*/, '');
55
+ return !condition.includes('style(') && /\b(?:width|height|min-width|max-width|min-height|max-height)\b/i.test(condition);
56
+ };
57
+ const getContainerName = query => {
58
+ const match = query.match(/^@container\s+([-_a-zA-Z][-_a-zA-Z0-9]*)\b/);
59
+ return match === null || match === void 0 ? void 0 : match[1];
60
+ };
61
+ const isContainerDeclaration = node => {
62
+ return getPropertyName(node) === 'containerName';
63
+ };
32
64
  const isImportedContainerType = (node, context) => {
33
65
  let expression = node;
34
66
  while (expression.type === 'TSSatisfiesExpression') {
@@ -48,12 +80,12 @@ const isImportedContainerType = (node, context) => {
48
80
  return false;
49
81
  };
50
82
  const isContainerQuery = node => {
51
- var _expression$quasis;
83
+ var _expression$quasis2;
52
84
  const expression = unwrapTypeScriptExpression(node);
53
85
  if (expression.type === 'Literal' && typeof expression.value === 'string') {
54
86
  return expression.value.includes('@container');
55
87
  }
56
- return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.some(quasi => {
88
+ return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis2 = expression.quasis) === null || _expression$quasis2 === void 0 ? void 0 : _expression$quasis2.some(quasi => {
57
89
  var _quasi$value, _quasi$value$raw;
58
90
  return (_quasi$value = quasi.value) === null || _quasi$value === void 0 ? void 0 : (_quasi$value$raw = _quasi$value.raw) === null || _quasi$value$raw === void 0 ? void 0 : _quasi$value$raw.includes('@container');
59
91
  }));
@@ -67,14 +99,36 @@ const rule = createLintRule({
67
99
  severity: 'error'
68
100
  },
69
101
  messages: {
70
- 'no-container-queries': 'We block @container queries as they break scope and are not type-safe. We suggest alternatives such as JS-based APIs or @media queries.'
102
+ 'no-container-queries': '@container queries must use a named container declared in the same file and a width/height-based condition.',
103
+ 'no-container-style-queries': 'Style queries are not allowed. Use a width/height-based @container query instead.',
104
+ 'no-unbound-container-queries': 'Container queries must include a container name, for example @container card (min-width: 30rem).',
105
+ 'no-mismatched-container-name': 'The @container name must match a containerName declared in the same file.',
106
+ 'no-non-dimension-container-queries': 'Container queries must be dimension-based (width or height); style and other feature queries are not allowed.'
71
107
  },
72
108
  type: 'problem',
73
109
  schema
74
110
  },
75
111
  create(context) {
76
112
  const importSources = getImportSources(context);
113
+ const containerNames = new Set();
77
114
  return {
115
+ Program(node) {
116
+ estraverse.traverse(node, {
117
+ enter(child) {
118
+ if (child.type !== 'Property') {
119
+ return;
120
+ }
121
+ const property = child;
122
+ if (isContainerDeclaration(property.key)) {
123
+ const id = getStaticString(property.value);
124
+ if (id) {
125
+ containerNames.add(id);
126
+ }
127
+ }
128
+ },
129
+ fallback: 'iteration'
130
+ });
131
+ },
78
132
  CallExpression(node) {
79
133
  const {
80
134
  references
@@ -89,12 +143,15 @@ const rule = createLintRule({
89
143
  if (!isContainerQuery(key)) {
90
144
  return;
91
145
  }
92
- if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression)) {
146
+ const query = getStaticString(key);
147
+ const queryName = query ? getContainerName(query) : undefined;
148
+ const reportMessageId = !query ? 'no-container-queries' : query.includes('style(') ? 'no-container-style-queries' : !queryName ? 'no-unbound-container-queries' : !containerNames.has(queryName) ? 'no-mismatched-container-name' : !isDimensionQuery(query) ? 'no-non-dimension-container-queries' : 'no-container-queries';
149
+ if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression) && query && queryName && containerNames.has(queryName) && isDimensionQuery(query)) {
93
150
  return;
94
151
  }
95
152
  context.report({
96
153
  node: node.key,
97
- messageId: 'no-container-queries'
154
+ messageId: reportMessageId
98
155
  });
99
156
  },
100
157
  /**
@@ -29,6 +29,38 @@ var isStaticContainerKey = function isStaticContainerKey(node) {
29
29
  }
30
30
  return expression.type === 'TemplateLiteral' && ((_expression$expressio = expression.expressions) === null || _expression$expressio === void 0 ? void 0 : _expression$expressio.length) === 0;
31
31
  };
32
+ var getStaticString = function getStaticString(node) {
33
+ var _expression$expressio2;
34
+ if (!node) {
35
+ return undefined;
36
+ }
37
+ var expression = unwrapTypeScriptExpression(node);
38
+ if (expression.type === 'Literal') {
39
+ var value = expression.value;
40
+ return typeof value === 'string' ? value : undefined;
41
+ }
42
+ if (expression.type === 'TemplateLiteral' && ((_expression$expressio2 = expression.expressions) === null || _expression$expressio2 === void 0 ? void 0 : _expression$expressio2.length) === 0) {
43
+ var _expression$quasis;
44
+ return (_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 || (_expression$quasis = _expression$quasis[0]) === null || _expression$quasis === void 0 || (_expression$quasis = _expression$quasis.value) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.raw;
45
+ }
46
+ return undefined;
47
+ };
48
+ var getPropertyName = function getPropertyName(node) {
49
+ var expression = unwrapTypeScriptExpression(node);
50
+ return expression.type === 'Identifier' ? expression.name : getStaticString(expression);
51
+ };
52
+ var isDimensionQuery = function isDimensionQuery(query) {
53
+ // Policy source: https://hello.atlassian.net/wiki/spaces/~7012119e15ecf78c74278a34bd6681745f7bb/pages/2595609668/What+would+it+take+to+get+container+queries+working
54
+ var condition = query.replace(/^@container\s+[-_a-zA-Z][-_a-zA-Z0-9]*\s*/, '');
55
+ return !condition.includes('style(') && /\b(?:width|height|min-width|max-width|min-height|max-height)\b/i.test(condition);
56
+ };
57
+ var getContainerName = function getContainerName(query) {
58
+ var match = query.match(/^@container\s+([-_a-zA-Z][-_a-zA-Z0-9]*)\b/);
59
+ return match === null || match === void 0 ? void 0 : match[1];
60
+ };
61
+ var isContainerDeclaration = function isContainerDeclaration(node) {
62
+ return getPropertyName(node) === 'containerName';
63
+ };
32
64
  var isImportedContainerType = function isImportedContainerType(node, context) {
33
65
  var expression = node;
34
66
  var _loop = function _loop() {
@@ -58,12 +90,12 @@ var isImportedContainerType = function isImportedContainerType(node, context) {
58
90
  return false;
59
91
  };
60
92
  var isContainerQuery = function isContainerQuery(node) {
61
- var _expression$quasis;
93
+ var _expression$quasis2;
62
94
  var expression = unwrapTypeScriptExpression(node);
63
95
  if (expression.type === 'Literal' && typeof expression.value === 'string') {
64
96
  return expression.value.includes('@container');
65
97
  }
66
- return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis = expression.quasis) === null || _expression$quasis === void 0 ? void 0 : _expression$quasis.some(function (quasi) {
98
+ return expression.type === 'TemplateLiteral' && Boolean((_expression$quasis2 = expression.quasis) === null || _expression$quasis2 === void 0 ? void 0 : _expression$quasis2.some(function (quasi) {
67
99
  var _quasi$value;
68
100
  return (_quasi$value = quasi.value) === null || _quasi$value === void 0 || (_quasi$value = _quasi$value.raw) === null || _quasi$value === void 0 ? void 0 : _quasi$value.includes('@container');
69
101
  }));
@@ -77,14 +109,36 @@ var rule = createLintRule({
77
109
  severity: 'error'
78
110
  },
79
111
  messages: {
80
- 'no-container-queries': 'We block @container queries as they break scope and are not type-safe. We suggest alternatives such as JS-based APIs or @media queries.'
112
+ 'no-container-queries': '@container queries must use a named container declared in the same file and a width/height-based condition.',
113
+ 'no-container-style-queries': 'Style queries are not allowed. Use a width/height-based @container query instead.',
114
+ 'no-unbound-container-queries': 'Container queries must include a container name, for example @container card (min-width: 30rem).',
115
+ 'no-mismatched-container-name': 'The @container name must match a containerName declared in the same file.',
116
+ 'no-non-dimension-container-queries': 'Container queries must be dimension-based (width or height); style and other feature queries are not allowed.'
81
117
  },
82
118
  type: 'problem',
83
119
  schema: schema
84
120
  },
85
121
  create: function create(context) {
86
122
  var importSources = getImportSources(context);
123
+ var containerNames = new Set();
87
124
  return {
125
+ Program: function Program(node) {
126
+ estraverse.traverse(node, {
127
+ enter: function enter(child) {
128
+ if (child.type !== 'Property') {
129
+ return;
130
+ }
131
+ var property = child;
132
+ if (isContainerDeclaration(property.key)) {
133
+ var id = getStaticString(property.value);
134
+ if (id) {
135
+ containerNames.add(id);
136
+ }
137
+ }
138
+ },
139
+ fallback: 'iteration'
140
+ });
141
+ },
88
142
  CallExpression: function CallExpression(node) {
89
143
  var _getScope = getScope(context, node),
90
144
  references = _getScope.references;
@@ -98,12 +152,15 @@ var rule = createLintRule({
98
152
  if (!isContainerQuery(key)) {
99
153
  return;
100
154
  }
101
- if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression)) {
155
+ var query = getStaticString(key);
156
+ var queryName = query ? getContainerName(query) : undefined;
157
+ var reportMessageId = !query ? 'no-container-queries' : query.includes('style(') ? 'no-container-style-queries' : !queryName ? 'no-unbound-container-queries' : !containerNames.has(queryName) ? 'no-mismatched-container-name' : !isDimensionQuery(query) ? 'no-non-dimension-container-queries' : 'no-container-queries';
158
+ if (isImportedContainerType(key, context) && isStaticContainerKey(key.expression) && query && queryName && containerNames.has(queryName) && isDimensionQuery(query)) {
102
159
  return;
103
160
  }
104
161
  context.report({
105
162
  node: node.key,
106
- messageId: 'no-container-queries'
163
+ messageId: reportMessageId
107
164
  });
108
165
  },
109
166
  /**
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.7",
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",