@atlaskit/eslint-plugin-design-system 4.8.2 → 4.9.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.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`9701bf4a8b3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9701bf4a8b3) - Fix false positives for variable names and object property keys
8
+
3
9
  ## 4.8.2
4
10
 
5
11
  ### Patch Changes
@@ -74,17 +74,24 @@ var rule = {
74
74
  }
75
75
  },
76
76
  Identifier: function Identifier(node) {
77
- if ((0, _isNode.isDecendantOfGlobalToken)(node) || (0, _isNode.isDecendantOfType)(node, 'ImportDeclaration')) {
77
+ if ((0, _isNode.isDecendantOfGlobalToken)(node) || (0, _isNode.isDecendantOfType)(node, 'ImportDeclaration') || (0, _isNode.isPropertyKey)(node) || (0, _isNode.isVariableName)(node)) {
78
78
  return;
79
79
  }
80
80
 
81
- if ((0, _isColor.isLegacyColor)(node.name) || (0, _isColor.isHardCodedColor)(node.name)) {
81
+ var isNodeHardCodedColor = (0, _isColor.isHardCodedColor)(node.name);
82
+
83
+ if ((0, _isColor.isLegacyColor)(node.name) || isNodeHardCodedColor) {
82
84
  if (node.parent.type === 'MemberExpression' && node.parent.object.type === 'Identifier') {
83
- context.report({
84
- messageId: 'hardCodedColor',
85
- node: node,
86
- suggest: getTokenSuggestion(node.parent, "".concat(node.parent.object.name, ".").concat(node.name), config)
87
- });
85
+ // Object members as named colors, like obj.ivory, should be valid,
86
+ // and hexes and color functions cannot be property names anyway.
87
+ if (!isNodeHardCodedColor) {
88
+ context.report({
89
+ messageId: 'hardCodedColor',
90
+ node: node,
91
+ suggest: getTokenSuggestion(node.parent, "".concat(node.parent.object.name, ".").concat(node.name), config)
92
+ });
93
+ }
94
+
88
95
  return;
89
96
  }
90
97
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isStyledTemplateNode = exports.isStyledObjectNode = exports.isDecendantOfType = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfGlobalToken = exports.isChildOfType = void 0;
6
+ exports.isVariableName = exports.isStyledTemplateNode = exports.isStyledObjectNode = exports.isPropertyKey = exports.isDecendantOfType = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfGlobalToken = exports.isChildOfType = void 0;
7
7
 
8
8
  var _eslintCodemodUtils = require("eslint-codemod-utils");
9
9
 
@@ -37,6 +37,27 @@ var isDecendantOfType = function isDecendantOfType(node, type) {
37
37
 
38
38
  exports.isDecendantOfType = isDecendantOfType;
39
39
 
40
+ var isPropertyKey = function isPropertyKey(node) {
41
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier') && isDecendantOfType(node, 'Property')) {
42
+ var parent = node.parent;
43
+ return node === parent.key || parent.shorthand;
44
+ }
45
+
46
+ return false;
47
+ };
48
+
49
+ exports.isPropertyKey = isPropertyKey;
50
+
51
+ var isVariableName = function isVariableName(node) {
52
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'Identifier') && isDecendantOfType(node, 'VariableDeclarator')) {
53
+ return node === node.parent.id;
54
+ }
55
+
56
+ return false;
57
+ };
58
+
59
+ exports.isVariableName = isVariableName;
60
+
40
61
  var isDecendantOfStyleJsxAttribute = function isDecendantOfStyleJsxAttribute(node) {
41
62
  // @ts-ignore
42
63
  if (node.type === 'JSXAttribute') {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.8.2",
3
+ "version": "4.9.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,7 +1,7 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
2
  import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
3
3
  import { isLegacyElevation } from '../utils/is-elevation';
4
- import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType } from '../utils/is-node';
4
+ import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType, isPropertyKey, isVariableName } from '../utils/is-node';
5
5
  const defaultConfig = {
6
6
  shouldEnforceFallbacks: false
7
7
  };
@@ -66,17 +66,24 @@ token('color.background.blanket');
66
66
  },
67
67
 
68
68
  Identifier(node) {
69
- if (isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration')) {
69
+ if (isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration') || isPropertyKey(node) || isVariableName(node)) {
70
70
  return;
71
71
  }
72
72
 
73
- if (isLegacyColor(node.name) || isHardCodedColor(node.name)) {
73
+ const isNodeHardCodedColor = isHardCodedColor(node.name);
74
+
75
+ if (isLegacyColor(node.name) || isNodeHardCodedColor) {
74
76
  if (node.parent.type === 'MemberExpression' && node.parent.object.type === 'Identifier') {
75
- context.report({
76
- messageId: 'hardCodedColor',
77
- node,
78
- suggest: getTokenSuggestion(node.parent, `${node.parent.object.name}.${node.name}`, config)
79
- });
77
+ // Object members as named colors, like obj.ivory, should be valid,
78
+ // and hexes and color functions cannot be property names anyway.
79
+ if (!isNodeHardCodedColor) {
80
+ context.report({
81
+ messageId: 'hardCodedColor',
82
+ node,
83
+ suggest: getTokenSuggestion(node.parent, `${node.parent.object.name}.${node.name}`, config)
84
+ });
85
+ }
86
+
80
87
  return;
81
88
  }
82
89
 
@@ -21,6 +21,21 @@ export const isDecendantOfType = (node, type, skipNode = true) => {
21
21
 
22
22
  return false;
23
23
  };
24
+ export const isPropertyKey = node => {
25
+ if (isNodeOfType(node, 'Identifier') && isDecendantOfType(node, 'Property')) {
26
+ const parent = node.parent;
27
+ return node === parent.key || parent.shorthand;
28
+ }
29
+
30
+ return false;
31
+ };
32
+ export const isVariableName = node => {
33
+ if (isNodeOfType(node, 'Identifier') && isDecendantOfType(node, 'VariableDeclarator')) {
34
+ return node === node.parent.id;
35
+ }
36
+
37
+ return false;
38
+ };
24
39
  export const isDecendantOfStyleJsxAttribute = node => {
25
40
  // @ts-ignore
26
41
  if (node.type === 'JSXAttribute') {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.8.2",
3
+ "version": "4.9.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,7 +1,7 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
2
  import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
3
3
  import { isLegacyElevation } from '../utils/is-elevation';
4
- import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType } from '../utils/is-node';
4
+ import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute, isDecendantOfType, isPropertyKey, isVariableName } from '../utils/is-node';
5
5
  var defaultConfig = {
6
6
  shouldEnforceFallbacks: false
7
7
  };
@@ -63,17 +63,24 @@ var rule = {
63
63
  }
64
64
  },
65
65
  Identifier: function Identifier(node) {
66
- if (isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration')) {
66
+ if (isDecendantOfGlobalToken(node) || isDecendantOfType(node, 'ImportDeclaration') || isPropertyKey(node) || isVariableName(node)) {
67
67
  return;
68
68
  }
69
69
 
70
- if (isLegacyColor(node.name) || isHardCodedColor(node.name)) {
70
+ var isNodeHardCodedColor = isHardCodedColor(node.name);
71
+
72
+ if (isLegacyColor(node.name) || isNodeHardCodedColor) {
71
73
  if (node.parent.type === 'MemberExpression' && node.parent.object.type === 'Identifier') {
72
- context.report({
73
- messageId: 'hardCodedColor',
74
- node: node,
75
- suggest: getTokenSuggestion(node.parent, "".concat(node.parent.object.name, ".").concat(node.name), config)
76
- });
74
+ // Object members as named colors, like obj.ivory, should be valid,
75
+ // and hexes and color functions cannot be property names anyway.
76
+ if (!isNodeHardCodedColor) {
77
+ context.report({
78
+ messageId: 'hardCodedColor',
79
+ node: node,
80
+ suggest: getTokenSuggestion(node.parent, "".concat(node.parent.object.name, ".").concat(node.name), config)
81
+ });
82
+ }
83
+
77
84
  return;
78
85
  }
79
86
 
@@ -23,6 +23,21 @@ export var isDecendantOfType = function isDecendantOfType(node, type) {
23
23
 
24
24
  return false;
25
25
  };
26
+ export var isPropertyKey = function isPropertyKey(node) {
27
+ if (isNodeOfType(node, 'Identifier') && isDecendantOfType(node, 'Property')) {
28
+ var parent = node.parent;
29
+ return node === parent.key || parent.shorthand;
30
+ }
31
+
32
+ return false;
33
+ };
34
+ export var isVariableName = function isVariableName(node) {
35
+ if (isNodeOfType(node, 'Identifier') && isDecendantOfType(node, 'VariableDeclarator')) {
36
+ return node === node.parent.id;
37
+ }
38
+
39
+ return false;
40
+ };
26
41
  export var isDecendantOfStyleJsxAttribute = function isDecendantOfStyleJsxAttribute(node) {
27
42
  // @ts-ignore
28
43
  if (node.type === 'JSXAttribute') {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.8.2",
3
+ "version": "4.9.0",
4
4
  "sideEffects": false
5
5
  }
@@ -2,6 +2,8 @@ import type { Rule } from 'eslint';
2
2
  import { CallExpression, Expression, TaggedTemplateExpression } from 'eslint-codemod-utils';
3
3
  export declare const isDecendantOfGlobalToken: (node: Rule.Node) => boolean;
4
4
  export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'], skipNode?: boolean) => boolean;
5
+ export declare const isPropertyKey: (node: Rule.Node) => boolean;
6
+ export declare const isVariableName: (node: Rule.Node) => boolean;
5
7
  export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
6
8
  export declare const isStyledTemplateNode: (node?: Expression | null | undefined) => node is TaggedTemplateExpression;
7
9
  export declare const isStyledObjectNode: (node?: Expression | null | undefined) => node is CallExpression;
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.8.2",
4
+ "version": "4.9.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"
@@ -35,7 +35,7 @@
35
35
  "@atlaskit/theme": "^12.0.2",
36
36
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
37
37
  "@emotion/core": "^10.0.9",
38
- "@emotion/styled": "^10.0.7",
38
+ "@emotion/styled": "^11.0.0",
39
39
  "eslint": "^7.7.0",
40
40
  "react": "^16.8.0",
41
41
  "ts-node": "^10.0.0",