@atlaskit/eslint-plugin-design-system 8.24.0 → 8.25.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
+ ## 8.25.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#70369](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70369) [`611434ce1fe5`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/611434ce1fe5) - ensure-design-token-usage no longer errors on color properties defined in SVG JSX elements.
8
+
3
9
  ## 8.24.0
4
10
 
5
11
  ### Minor Changes
@@ -140,6 +140,9 @@ var lintJSXLiteralForColor = exports.lintJSXLiteralForColor = function lintJSXLi
140
140
  if (!(0, _eslintCodemodUtils.isNodeOfType)(node.parent.name, 'JSXIdentifier')) {
141
141
  return;
142
142
  }
143
+ if ((0, _isNode.isDecendantOfSvgElement)(node.parent)) {
144
+ return;
145
+ }
143
146
  if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
144
147
  return;
145
148
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.isPropertyKey = exports.isDecendantOfType = 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.isDecendantOfGlobalToken = exports.isCssInJsTemplateNode = exports.isCssInJsObjectNode = exports.isCssInJsCallNode = exports.isChildOfType = void 0;
7
7
  var _eslintCodemodUtils = require("eslint-codemod-utils");
8
8
  // eslint-disable-next-line import/no-extraneous-dependencies
9
9
 
@@ -42,6 +42,18 @@ var isDecendantOfStyleJsxAttribute = exports.isDecendantOfStyleJsxAttribute = fu
42
42
  }
43
43
  return false;
44
44
  };
45
+ var isDecendantOfSvgElement = exports.isDecendantOfSvgElement = function isDecendantOfSvgElement(node) {
46
+ if ((0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
47
+ // @ts-ignore
48
+ if (node.openingElement.name.name === 'svg') {
49
+ return true;
50
+ }
51
+ }
52
+ if (node.parent) {
53
+ return isDecendantOfSvgElement(node.parent);
54
+ }
55
+ return false;
56
+ };
45
57
  var cssInJsCallees = ['css', 'styled', 'styled2'];
46
58
  var isCssInJsTemplateNode = exports.isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
47
59
  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 } from '../utils/is-node';
7
+ import { isChildOfType, isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfSvgElement } from '../utils/is-node';
8
8
  // TemplateLiteral > Identifier
9
9
  export const lintTemplateIdentifierForColor = (node, context, config) => {
10
10
  if (node.type !== 'Identifier') {
@@ -135,6 +135,9 @@ export const lintJSXLiteralForColor = (node, context, config) => {
135
135
  if (!isNodeOfType(node.parent.name, 'JSXIdentifier')) {
136
136
  return;
137
137
  }
138
+ if (isDecendantOfSvgElement(node.parent)) {
139
+ return;
140
+ }
138
141
  if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
139
142
  return;
140
143
  }
@@ -35,6 +35,18 @@ export const isDecendantOfStyleJsxAttribute = node => {
35
35
  }
36
36
  return false;
37
37
  };
38
+ export const isDecendantOfSvgElement = node => {
39
+ if (isNodeOfType(node, 'JSXElement')) {
40
+ // @ts-ignore
41
+ if (node.openingElement.name.name === 'svg') {
42
+ return true;
43
+ }
44
+ }
45
+ if (node.parent) {
46
+ return isDecendantOfSvgElement(node.parent);
47
+ }
48
+ return false;
49
+ };
38
50
  const cssInJsCallees = ['css', 'styled', 'styled2'];
39
51
  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';
40
52
  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 } from '../utils/is-node';
7
+ import { isChildOfType, isDecendantOfGlobalToken, 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') {
@@ -134,6 +134,9 @@ export var lintJSXLiteralForColor = function lintJSXLiteralForColor(node, contex
134
134
  if (!isNodeOfType(node.parent.name, 'JSXIdentifier')) {
135
135
  return;
136
136
  }
137
+ if (isDecendantOfSvgElement(node.parent)) {
138
+ return;
139
+ }
137
140
  if (['alt', 'src', 'label', 'key'].includes(node.parent.name.name)) {
138
141
  return;
139
142
  }
@@ -36,6 +36,18 @@ export var isDecendantOfStyleJsxAttribute = function isDecendantOfStyleJsxAttrib
36
36
  }
37
37
  return false;
38
38
  };
39
+ export var isDecendantOfSvgElement = function isDecendantOfSvgElement(node) {
40
+ if (isNodeOfType(node, 'JSXElement')) {
41
+ // @ts-ignore
42
+ if (node.openingElement.name.name === 'svg') {
43
+ return true;
44
+ }
45
+ }
46
+ if (node.parent) {
47
+ return isDecendantOfSvgElement(node.parent);
48
+ }
49
+ return false;
50
+ };
39
51
  var cssInJsCallees = ['css', 'styled', 'styled2'];
40
52
  export var isCssInJsTemplateNode = function isCssInJsTemplateNode(node) {
41
53
  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,6 +4,7 @@ export declare const isDecendantOfGlobalToken: (node: EslintNode) => boolean;
4
4
  export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'], skipNode?: boolean) => boolean;
5
5
  export declare const isPropertyKey: (node: Rule.Node) => boolean;
6
6
  export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
7
+ export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
7
8
  export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
8
9
  export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
9
10
  export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
@@ -4,6 +4,7 @@ export declare const isDecendantOfGlobalToken: (node: EslintNode) => boolean;
4
4
  export declare const isDecendantOfType: (node: Rule.Node, type: Rule.Node['type'], skipNode?: boolean) => boolean;
5
5
  export declare const isPropertyKey: (node: Rule.Node) => boolean;
6
6
  export declare const isDecendantOfStyleJsxAttribute: (node: Rule.Node) => boolean;
7
+ export declare const isDecendantOfSvgElement: (node: Rule.Node) => boolean;
7
8
  export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
8
9
  export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
9
10
  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.24.0",
4
+ "version": "8.25.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "publishConfig": {
7
7
  "registry": "https://registry.npmjs.org/"