@atlaskit/eslint-plugin-design-system 4.10.1 → 4.11.0

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,11 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 4.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`268f92124e2`](https://bitbucket.org/atlassian/atlassian-frontend/commits/268f92124e2) - Bolster isException logic to support descendants of excepted functions and to be case-agnostic
8
+
3
9
  ## 4.10.1
4
10
 
5
11
  ### Patch Changes
@@ -7,6 +7,8 @@ exports.default = void 0;
7
7
 
8
8
  var _eslintCodemodUtils = require("eslint-codemod-utils");
9
9
 
10
+ var _getIsException = require("../utils/get-is-exception");
11
+
10
12
  var _isColor = require("../utils/is-color");
11
13
 
12
14
  var _isElevation = require("../utils/is-elevation");
@@ -58,20 +60,14 @@ var rule = {
58
60
  },
59
61
  create: function create(context) {
60
62
  var config = context.options[0] || defaultConfig;
61
-
62
- var isException = function isException(value) {
63
- var _config$exceptions$in, _config$exceptions;
64
-
65
- return (_config$exceptions$in = (_config$exceptions = config.exceptions) === null || _config$exceptions === void 0 ? void 0 : _config$exceptions.includes(value)) !== null && _config$exceptions$in !== void 0 ? _config$exceptions$in : false;
66
- };
67
-
63
+ var isException = (0, _getIsException.getIsException)(config.exceptions);
68
64
  return {
69
65
  'TemplateLiteral > Identifier': function TemplateLiteralIdentifier(node) {
70
66
  if (!(0, _isNode.isDecendantOfStyleBlock)(node)) {
71
67
  return;
72
68
  }
73
69
 
74
- if (node.type === 'Identifier' && (0, _isColor.isLegacyNamedColor)(node.name) && !isException(node.name)) {
70
+ if (node.type === 'Identifier' && (0, _isColor.isLegacyNamedColor)(node.name) && !isException(node)) {
75
71
  context.report({
76
72
  messageId: 'hardCodedColor',
77
73
  node: node,
@@ -81,7 +77,7 @@ var rule = {
81
77
  }
82
78
  },
83
79
  Identifier: function Identifier(node) {
84
- if (isException(node.name) || (0, _isNode.isDecendantOfGlobalToken)(node) || (0, _isNode.isDecendantOfType)(node, 'ImportDeclaration') || (0, _isNode.isPropertyKey)(node) || (0, _isNode.isVariableName)(node)) {
80
+ if (isException(node) || (0, _isNode.isDecendantOfGlobalToken)(node) || (0, _isNode.isDecendantOfType)(node, 'ImportDeclaration') || (0, _isNode.isPropertyKey)(node) || (0, _isNode.isVariableName)(node)) {
85
81
  return;
86
82
  }
87
83
 
@@ -159,11 +155,7 @@ var rule = {
159
155
  });
160
156
  },
161
157
  'ObjectExpression > Property > Literal': function ObjectExpressionPropertyLiteral(node) {
162
- if (node.type !== 'Literal') {
163
- return;
164
- }
165
-
166
- if (typeof node.value !== 'string') {
158
+ if (node.type !== 'Literal' || typeof node.value !== 'string') {
167
159
  return;
168
160
  }
169
161
 
@@ -171,11 +163,7 @@ var rule = {
171
163
  return;
172
164
  }
173
165
 
174
- if (isException(node.value)) {
175
- return;
176
- }
177
-
178
- if ((0, _isColor.isHardCodedColor)(node.value) || (0, _isColor.includesHardCodedColor)(node.value)) {
166
+ if (((0, _isColor.isHardCodedColor)(node.value) || (0, _isColor.includesHardCodedColor)(node.value)) && !isException(node)) {
179
167
  context.report({
180
168
  messageId: 'hardCodedColor',
181
169
  node: node,
@@ -193,7 +181,7 @@ var rule = {
193
181
  return;
194
182
  }
195
183
 
196
- if (!(0, _isColor.isLegacyNamedColor)(node.callee.name) || (0, _isNode.isDecendantOfGlobalToken)(node) || isException(node.callee.name)) {
184
+ if (!(0, _isColor.isLegacyNamedColor)(node.callee.name) || (0, _isNode.isDecendantOfGlobalToken)(node) || isException(node)) {
197
185
  return;
198
186
  }
199
187
 
@@ -213,12 +201,12 @@ var rule = {
213
201
  }
214
202
 
215
203
  if (node.value.type === 'Literal') {
216
- var literalValue = node.value.value;
217
-
218
- if (isException(literalValue)) {
204
+ if (isException(node)) {
219
205
  return;
220
206
  }
221
207
 
208
+ var literalValue = node.value.value;
209
+
222
210
  if ((0, _isColor.isHardCodedColor)(literalValue) || (0, _isColor.includesHardCodedColor)(literalValue)) {
223
211
  context.report({
224
212
  messageId: 'hardCodedColor',
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getIsException = void 0;
7
+
8
+ var getNodeValue = function getNodeValue(node) {
9
+ var _node$value;
10
+
11
+ switch (node.type) {
12
+ case 'Identifier':
13
+ return node.name;
14
+
15
+ case 'Literal':
16
+ return typeof node.value === 'string' ? node.value : null;
17
+
18
+ case 'CallExpression':
19
+ return node.callee.type === 'Identifier' ? node.callee.name : null;
20
+ // @ts-expect-error
21
+
22
+ case 'JSXAttribute':
23
+ // @ts-expect-error
24
+ return ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'Literal' ? node.value.value : null;
25
+
26
+ default:
27
+ return null;
28
+ }
29
+ };
30
+
31
+ var getIsException = function getIsException(exceptions) {
32
+ if (!(exceptions !== null && exceptions !== void 0 && exceptions.length)) {
33
+ return function () {
34
+ return false;
35
+ };
36
+ }
37
+
38
+ var exceptionsSet = new Set(exceptions.map(function (x) {
39
+ return x.toLowerCase();
40
+ }));
41
+
42
+ var isException = function isException(node) {
43
+ var value = getNodeValue(node);
44
+
45
+ if (value) {
46
+ var splitValues = value.split(/[-_\s]+/);
47
+
48
+ if (splitValues.some(function (v) {
49
+ return exceptionsSet.has(v.toLowerCase());
50
+ })) {
51
+ return true;
52
+ }
53
+ }
54
+
55
+ if (node.parent) {
56
+ return isException(node.parent);
57
+ }
58
+
59
+ return false;
60
+ };
61
+
62
+ return isException;
63
+ };
64
+
65
+ exports.getIsException = getIsException;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.10.1",
3
+ "version": "4.11.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,4 +1,5 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import { getIsException } from '../utils/get-is-exception';
2
3
  import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
3
4
  import { isLegacyElevation } from '../utils/is-elevation';
4
5
  import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType, isPropertyKey, isVariableName } from '../utils/is-node';
@@ -49,20 +50,14 @@ token('color.background.blanket');
49
50
 
50
51
  create(context) {
51
52
  const config = context.options[0] || defaultConfig;
52
-
53
- const isException = value => {
54
- var _config$exceptions$in, _config$exceptions;
55
-
56
- return (_config$exceptions$in = (_config$exceptions = config.exceptions) === null || _config$exceptions === void 0 ? void 0 : _config$exceptions.includes(value)) !== null && _config$exceptions$in !== void 0 ? _config$exceptions$in : false;
57
- };
58
-
53
+ const isException = getIsException(config.exceptions);
59
54
  return {
60
55
  'TemplateLiteral > Identifier': node => {
61
56
  if (!isDecendantOfStyleBlock(node)) {
62
57
  return;
63
58
  }
64
59
 
65
- if (node.type === 'Identifier' && isLegacyNamedColor(node.name) && !isException(node.name)) {
60
+ if (node.type === 'Identifier' && isLegacyNamedColor(node.name) && !isException(node)) {
66
61
  context.report({
67
62
  messageId: 'hardCodedColor',
68
63
  node,
@@ -73,7 +68,7 @@ token('color.background.blanket');
73
68
  },
74
69
 
75
70
  Identifier(node) {
76
- if (isException(node.name) || isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration') || isPropertyKey(node) || isVariableName(node)) {
71
+ if (isException(node) || isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration') || isPropertyKey(node) || isVariableName(node)) {
77
72
  return;
78
73
  }
79
74
 
@@ -156,11 +151,7 @@ ${' '.repeat(getNodeColumn(node) - 2)}box-shadow: \${token('${elevation.shadow}'
156
151
  });
157
152
  },
158
153
  'ObjectExpression > Property > Literal': node => {
159
- if (node.type !== 'Literal') {
160
- return;
161
- }
162
-
163
- if (typeof node.value !== 'string') {
154
+ if (node.type !== 'Literal' || typeof node.value !== 'string') {
164
155
  return;
165
156
  }
166
157
 
@@ -168,11 +159,7 @@ ${' '.repeat(getNodeColumn(node) - 2)}box-shadow: \${token('${elevation.shadow}'
168
159
  return;
169
160
  }
170
161
 
171
- if (isException(node.value)) {
172
- return;
173
- }
174
-
175
- if (isHardCodedColor(node.value) || includesHardCodedColor(node.value)) {
162
+ if ((isHardCodedColor(node.value) || includesHardCodedColor(node.value)) && !isException(node)) {
176
163
  context.report({
177
164
  messageId: 'hardCodedColor',
178
165
  node,
@@ -191,7 +178,7 @@ ${' '.repeat(getNodeColumn(node) - 2)}box-shadow: \${token('${elevation.shadow}'
191
178
  return;
192
179
  }
193
180
 
194
- if (!isLegacyNamedColor(node.callee.name) || isDecendantOfGlobalToken(node) || isException(node.callee.name)) {
181
+ if (!isLegacyNamedColor(node.callee.name) || isDecendantOfGlobalToken(node) || isException(node)) {
195
182
  return;
196
183
  }
197
184
 
@@ -212,12 +199,12 @@ ${' '.repeat(getNodeColumn(node) - 2)}box-shadow: \${token('${elevation.shadow}'
212
199
  }
213
200
 
214
201
  if (node.value.type === 'Literal') {
215
- const literalValue = node.value.value;
216
-
217
- if (isException(literalValue)) {
202
+ if (isException(node)) {
218
203
  return;
219
204
  }
220
205
 
206
+ const literalValue = node.value.value;
207
+
221
208
  if (isHardCodedColor(literalValue) || includesHardCodedColor(literalValue)) {
222
209
  context.report({
223
210
  messageId: 'hardCodedColor',
@@ -0,0 +1,50 @@
1
+ const getNodeValue = node => {
2
+ var _node$value;
3
+
4
+ switch (node.type) {
5
+ case 'Identifier':
6
+ return node.name;
7
+
8
+ case 'Literal':
9
+ return typeof node.value === 'string' ? node.value : null;
10
+
11
+ case 'CallExpression':
12
+ return node.callee.type === 'Identifier' ? node.callee.name : null;
13
+ // @ts-expect-error
14
+
15
+ case 'JSXAttribute':
16
+ // @ts-expect-error
17
+ return ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'Literal' ? node.value.value : null;
18
+
19
+ default:
20
+ return null;
21
+ }
22
+ };
23
+
24
+ export const getIsException = exceptions => {
25
+ if (!(exceptions !== null && exceptions !== void 0 && exceptions.length)) {
26
+ return () => false;
27
+ }
28
+
29
+ const exceptionsSet = new Set(exceptions.map(x => x.toLowerCase()));
30
+
31
+ const isException = node => {
32
+ const value = getNodeValue(node);
33
+
34
+ if (value) {
35
+ const splitValues = value.split(/[-_\s]+/);
36
+
37
+ if (splitValues.some(v => exceptionsSet.has(v.toLowerCase()))) {
38
+ return true;
39
+ }
40
+ }
41
+
42
+ if (node.parent) {
43
+ return isException(node.parent);
44
+ }
45
+
46
+ return false;
47
+ };
48
+
49
+ return isException;
50
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.10.1",
3
+ "version": "4.11.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,4 +1,5 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import { getIsException } from '../utils/get-is-exception';
2
3
  import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
3
4
  import { isLegacyElevation } from '../utils/is-elevation';
4
5
  import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType, isPropertyKey, isVariableName } from '../utils/is-node';
@@ -47,20 +48,14 @@ var rule = {
47
48
  },
48
49
  create: function create(context) {
49
50
  var config = context.options[0] || defaultConfig;
50
-
51
- var isException = function isException(value) {
52
- var _config$exceptions$in, _config$exceptions;
53
-
54
- return (_config$exceptions$in = (_config$exceptions = config.exceptions) === null || _config$exceptions === void 0 ? void 0 : _config$exceptions.includes(value)) !== null && _config$exceptions$in !== void 0 ? _config$exceptions$in : false;
55
- };
56
-
51
+ var isException = getIsException(config.exceptions);
57
52
  return {
58
53
  'TemplateLiteral > Identifier': function TemplateLiteralIdentifier(node) {
59
54
  if (!isDecendantOfStyleBlock(node)) {
60
55
  return;
61
56
  }
62
57
 
63
- if (node.type === 'Identifier' && isLegacyNamedColor(node.name) && !isException(node.name)) {
58
+ if (node.type === 'Identifier' && isLegacyNamedColor(node.name) && !isException(node)) {
64
59
  context.report({
65
60
  messageId: 'hardCodedColor',
66
61
  node: node,
@@ -70,7 +65,7 @@ var rule = {
70
65
  }
71
66
  },
72
67
  Identifier: function Identifier(node) {
73
- if (isException(node.name) || isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration') || isPropertyKey(node) || isVariableName(node)) {
68
+ if (isException(node) || isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration') || isPropertyKey(node) || isVariableName(node)) {
74
69
  return;
75
70
  }
76
71
 
@@ -148,11 +143,7 @@ var rule = {
148
143
  });
149
144
  },
150
145
  'ObjectExpression > Property > Literal': function ObjectExpressionPropertyLiteral(node) {
151
- if (node.type !== 'Literal') {
152
- return;
153
- }
154
-
155
- if (typeof node.value !== 'string') {
146
+ if (node.type !== 'Literal' || typeof node.value !== 'string') {
156
147
  return;
157
148
  }
158
149
 
@@ -160,11 +151,7 @@ var rule = {
160
151
  return;
161
152
  }
162
153
 
163
- if (isException(node.value)) {
164
- return;
165
- }
166
-
167
- if (isHardCodedColor(node.value) || includesHardCodedColor(node.value)) {
154
+ if ((isHardCodedColor(node.value) || includesHardCodedColor(node.value)) && !isException(node)) {
168
155
  context.report({
169
156
  messageId: 'hardCodedColor',
170
157
  node: node,
@@ -182,7 +169,7 @@ var rule = {
182
169
  return;
183
170
  }
184
171
 
185
- if (!isLegacyNamedColor(node.callee.name) || isDecendantOfGlobalToken(node) || isException(node.callee.name)) {
172
+ if (!isLegacyNamedColor(node.callee.name) || isDecendantOfGlobalToken(node) || isException(node)) {
186
173
  return;
187
174
  }
188
175
 
@@ -202,12 +189,12 @@ var rule = {
202
189
  }
203
190
 
204
191
  if (node.value.type === 'Literal') {
205
- var literalValue = node.value.value;
206
-
207
- if (isException(literalValue)) {
192
+ if (isException(node)) {
208
193
  return;
209
194
  }
210
195
 
196
+ var literalValue = node.value.value;
197
+
211
198
  if (isHardCodedColor(literalValue) || includesHardCodedColor(literalValue)) {
212
199
  context.report({
213
200
  messageId: 'hardCodedColor',
@@ -0,0 +1,56 @@
1
+ var getNodeValue = function getNodeValue(node) {
2
+ var _node$value;
3
+
4
+ switch (node.type) {
5
+ case 'Identifier':
6
+ return node.name;
7
+
8
+ case 'Literal':
9
+ return typeof node.value === 'string' ? node.value : null;
10
+
11
+ case 'CallExpression':
12
+ return node.callee.type === 'Identifier' ? node.callee.name : null;
13
+ // @ts-expect-error
14
+
15
+ case 'JSXAttribute':
16
+ // @ts-expect-error
17
+ return ((_node$value = node.value) === null || _node$value === void 0 ? void 0 : _node$value.type) === 'Literal' ? node.value.value : null;
18
+
19
+ default:
20
+ return null;
21
+ }
22
+ };
23
+
24
+ export var getIsException = function getIsException(exceptions) {
25
+ if (!(exceptions !== null && exceptions !== void 0 && exceptions.length)) {
26
+ return function () {
27
+ return false;
28
+ };
29
+ }
30
+
31
+ var exceptionsSet = new Set(exceptions.map(function (x) {
32
+ return x.toLowerCase();
33
+ }));
34
+
35
+ var isException = function isException(node) {
36
+ var value = getNodeValue(node);
37
+
38
+ if (value) {
39
+ var splitValues = value.split(/[-_\s]+/);
40
+
41
+ if (splitValues.some(function (v) {
42
+ return exceptionsSet.has(v.toLowerCase());
43
+ })) {
44
+ return true;
45
+ }
46
+ }
47
+
48
+ if (node.parent) {
49
+ return isException(node.parent);
50
+ }
51
+
52
+ return false;
53
+ };
54
+
55
+ return isException;
56
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.10.1",
3
+ "version": "4.11.0",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,2 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const getIsException: (exceptions?: string[] | undefined) => (node: Rule.Node) => boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
3
  "description": "The essential plugin for use with the Atlassian Design System.",
4
- "version": "4.10.1",
4
+ "version": "4.11.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"