@atlaskit/eslint-plugin-design-system 8.36.0 → 8.36.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,11 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 8.36.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#79810](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/79810) [`8c6e96aa3cf0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8c6e96aa3cf0) - Fixed an issue with `ensure-design-token-usage` where color props on primitive components could report an error.
8
+
3
9
  ## 8.36.0
4
10
 
5
11
  ### Minor Changes
@@ -143,6 +143,11 @@ var lintJSXLiteralForColor = exports.lintJSXLiteralForColor = function lintJSXLi
143
143
  if ((0, _isNode.isDecendantOfSvgElement)(node.parent)) {
144
144
  return;
145
145
  }
146
+
147
+ // Box backgroundColor prop accepts token names directly - don't lint against this
148
+ if ((0, _isNode.isDecendantOfPrimitive)(node.parent, context)) {
149
+ return;
150
+ }
146
151
  if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
147
152
  return;
148
153
  }
@@ -3,8 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isPropertyKey = exports.isDecendantOfType = exports.isDecendantOfSvgElement = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfGlobalToken = exports.isCssInJsTemplateNode = exports.isCssInJsObjectNode = exports.isCssInJsCallNode = exports.isChildOfType = void 0;
6
+ exports.isPropertyKey = exports.isDecendantOfType = exports.isDecendantOfSvgElement = exports.isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleBlock = exports.isDecendantOfPrimitive = exports.isDecendantOfGlobalToken = exports.isCssInJsTemplateNode = exports.isCssInJsObjectNode = exports.isCssInJsCallNode = exports.isChildOfType = void 0;
7
7
  var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ var _astNodes = require("../../ast-nodes");
8
9
  // eslint-disable-next-line import/no-extraneous-dependencies
9
10
 
10
11
  var isDecendantOfGlobalToken = exports.isDecendantOfGlobalToken = function isDecendantOfGlobalToken(node) {
@@ -54,6 +55,22 @@ var isDecendantOfSvgElement = exports.isDecendantOfSvgElement = function isDecen
54
55
  }
55
56
  return false;
56
57
  };
58
+ var isDecendantOfPrimitive = exports.isDecendantOfPrimitive = function isDecendantOfPrimitive(node, context) {
59
+ var primitivesToCheck = ['Box', 'Text'];
60
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
61
+ // @ts-ignore
62
+ if (primitivesToCheck.includes(node.openingElement.name.name)) {
63
+ var importDeclaration = _astNodes.Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
64
+ if (importDeclaration.length) {
65
+ return true;
66
+ }
67
+ }
68
+ }
69
+ if (node.parent) {
70
+ return isDecendantOfPrimitive(node.parent, context);
71
+ }
72
+ return false;
73
+ };
57
74
  var cssInJsCallees = ['css', 'styled', 'styled2'];
58
75
  var isCssInJsTemplateNode = exports.isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
59
76
  return (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
@@ -4,7 +4,7 @@ import { node as generate, isNodeOfType } from 'eslint-codemod-utils';
4
4
  import { getIsException } from '../utils/get-is-exception';
5
5
  import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
6
6
  import { isLegacyElevation } from '../utils/is-elevation';
7
- import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
7
+ import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfPrimitive, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
8
8
  // TemplateLiteral > Identifier
9
9
  export const lintTemplateIdentifierForColor = (node, context, config) => {
10
10
  if (node.type !== 'Identifier') {
@@ -138,6 +138,11 @@ export const lintJSXLiteralForColor = (node, context, config) => {
138
138
  if (isDecendantOfSvgElement(node.parent)) {
139
139
  return;
140
140
  }
141
+
142
+ // Box backgroundColor prop accepts token names directly - don't lint against this
143
+ if (isDecendantOfPrimitive(node.parent, context)) {
144
+ return;
145
+ }
141
146
  if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
142
147
  return;
143
148
  }
@@ -1,6 +1,7 @@
1
1
  // eslint-disable-next-line import/no-extraneous-dependencies
2
2
 
3
3
  import { isNodeOfType } from 'eslint-codemod-utils';
4
+ import { Root } from '../../ast-nodes';
4
5
  export const isDecendantOfGlobalToken = node => {
5
6
  if (isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'token' || node.callee.name === 'getTokenValue')) {
6
7
  return true;
@@ -47,6 +48,22 @@ export const isDecendantOfSvgElement = node => {
47
48
  }
48
49
  return false;
49
50
  };
51
+ export const isDecendantOfPrimitive = (node, context) => {
52
+ const primitivesToCheck = ['Box', 'Text'];
53
+ if (isNodeOfType(node, 'JSXElement')) {
54
+ // @ts-ignore
55
+ if (primitivesToCheck.includes(node.openingElement.name.name)) {
56
+ const importDeclaration = Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
57
+ if (importDeclaration.length) {
58
+ return true;
59
+ }
60
+ }
61
+ }
62
+ if (node.parent) {
63
+ return isDecendantOfPrimitive(node.parent, context);
64
+ }
65
+ return false;
66
+ };
50
67
  const cssInJsCallees = ['css', 'styled', 'styled2'];
51
68
  export const isCssInJsTemplateNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
52
69
  export const isCssInJsCallNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && cssInJsCallees.includes(node.callee.name);
@@ -4,7 +4,7 @@ import { node as generate, isNodeOfType } from 'eslint-codemod-utils';
4
4
  import { getIsException } from '../utils/get-is-exception';
5
5
  import { includesHardCodedColor, isHardCodedColor, isLegacyColor, isLegacyNamedColor } from '../utils/is-color';
6
6
  import { isLegacyElevation } from '../utils/is-elevation';
7
- import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
7
+ import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfPrimitive, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
8
8
  // TemplateLiteral > Identifier
9
9
  export var lintTemplateIdentifierForColor = function lintTemplateIdentifierForColor(node, context, config) {
10
10
  if (node.type !== 'Identifier') {
@@ -137,6 +137,11 @@ export var lintJSXLiteralForColor = function lintJSXLiteralForColor(node, contex
137
137
  if (isDecendantOfSvgElement(node.parent)) {
138
138
  return;
139
139
  }
140
+
141
+ // Box backgroundColor prop accepts token names directly - don't lint against this
142
+ if (isDecendantOfPrimitive(node.parent, context)) {
143
+ return;
144
+ }
140
145
  if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
141
146
  return;
142
147
  }
@@ -1,6 +1,7 @@
1
1
  // eslint-disable-next-line import/no-extraneous-dependencies
2
2
 
3
3
  import { isNodeOfType } from 'eslint-codemod-utils';
4
+ import { Root } from '../../ast-nodes';
4
5
  export var isDecendantOfGlobalToken = function isDecendantOfGlobalToken(node) {
5
6
  if (isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'token' || node.callee.name === 'getTokenValue')) {
6
7
  return true;
@@ -48,6 +49,22 @@ export var isDecendantOfSvgElement = function isDecendantOfSvgElement(node) {
48
49
  }
49
50
  return false;
50
51
  };
52
+ export var isDecendantOfPrimitive = function isDecendantOfPrimitive(node, context) {
53
+ var primitivesToCheck = ['Box', 'Text'];
54
+ if (isNodeOfType(node, 'JSXElement')) {
55
+ // @ts-ignore
56
+ if (primitivesToCheck.includes(node.openingElement.name.name)) {
57
+ var importDeclaration = Root.findImportsByModule(context.getSourceCode().ast.body, '@atlaskit/primitives');
58
+ if (importDeclaration.length) {
59
+ return true;
60
+ }
61
+ }
62
+ }
63
+ if (node.parent) {
64
+ return isDecendantOfPrimitive(node.parent, context);
65
+ }
66
+ return false;
67
+ };
51
68
  var cssInJsCallees = ['css', 'styled', 'styled2'];
52
69
  export var isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
53
70
  return (node === null || node === void 0 ? void 0 : node.type) === 'TaggedTemplateExpression' && node.tag.type === 'MemberExpression' && node.tag.object.type === 'Identifier' && node.tag.object.name === 'styled';
@@ -5,6 +5,7 @@ export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'
5
5
  export declare const isPropertyKey: (node: Rule.Node) => boolean;
6
6
  export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
7
7
  export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
8
+ export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.RuleContext) => boolean;
8
9
  export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
9
10
  export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
10
11
  export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
@@ -5,6 +5,7 @@ export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'
5
5
  export declare const isPropertyKey: (node: Rule.Node) => boolean;
6
6
  export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
7
7
  export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
8
+ export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.RuleContext) => boolean;
8
9
  export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
9
10
  export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
10
11
  export declare const isCssInJsObjectNode: (node?: Expression | null) => 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": "8.36.0",
4
+ "version": "8.36.1",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"