@atlaskit/eslint-plugin-design-system 10.0.0 → 10.0.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,14 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 10.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#98294](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98294)
8
+ [`0663be43d057`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0663be43d057) -
9
+ The `ensure-design-token-usage` rule will now ignore `xcss()` calls even if the `xcss` variable
10
+ has been aliased.
11
+
3
12
  ## 10.0.0
4
13
 
5
14
  ### Major Changes
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = exports.createWithConfig = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _eslintCodemodUtils = require("eslint-codemod-utils");
10
+ var _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
10
11
  var _createRule = require("../utils/create-rule");
11
12
  var _isColor = require("../utils/is-color");
12
13
  var _isNode = require("../utils/is-node");
@@ -67,6 +68,14 @@ var createWithConfig = exports.createWithConfig = function createWithConfig(init
67
68
  return ObjectExpression;
68
69
  }(function (parentNode) {
69
70
  return (0, _errorBoundary.errorBoundary)(function () {
71
+ var _context$getScope = context.getScope(),
72
+ references = _context$getScope.references;
73
+ /**
74
+ * NOTE: This rule doesn't have an `importSources` config option,
75
+ * so this will just be equal to DEFAULT_IMPORT_SOURCES (which is fine)
76
+ */
77
+ var importSources = (0, _isSupportedImport.getImportSources)(context);
78
+
70
79
  // To force the correct node type
71
80
  if (!(0, _eslintCodemodUtils.isNodeOfType)(parentNode, 'ObjectExpression')) {
72
81
  return;
@@ -76,7 +85,7 @@ var createWithConfig = exports.createWithConfig = function createWithConfig(init
76
85
  if (parentNode.parent.type === 'Property') {
77
86
  return;
78
87
  }
79
- if ((0, _isNode.isDecendantOfXcssBlock)(parentNode)) {
88
+ if ((0, _isNode.isDecendantOfXcssBlock)(parentNode, references, importSources)) {
80
89
  return;
81
90
  }
82
91
  if (!(0, _isNode.isDecendantOfStyleBlock)(parentNode) && !(0, _isNode.isDecendantOfType)(parentNode, 'JSXExpressionContainer')) {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.isPropertyKey = exports.isDecendantOfXcssBlock = 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 _isSupportedImport = require("@atlaskit/eslint-utils/is-supported-import");
8
9
  var _astNodes = require("../../ast-nodes");
9
10
  // eslint-disable-next-line import/no-extraneous-dependencies
10
11
 
@@ -81,16 +82,13 @@ var isCssInJsCallNode = exports.isCssInJsCallNode = function isCssInJsCallNode(n
81
82
  var isCssInJsObjectNode = exports.isCssInJsObjectNode = function isCssInJsObjectNode(node) {
82
83
  return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && cssInJsCallees.includes(node.callee.object.name);
83
84
  };
84
- var isXcssCallNode = function isXcssCallNode(node) {
85
- return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'xcss';
86
- };
87
- var isDecendantOfXcssBlock = exports.isDecendantOfXcssBlock = function isDecendantOfXcssBlock(node) {
85
+ var isDecendantOfXcssBlock = exports.isDecendantOfXcssBlock = function isDecendantOfXcssBlock(node, referencesInScope, importSources) {
88
86
  // xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
89
- if (isXcssCallNode(node)) {
87
+ if (node.type === 'CallExpression' && (0, _isSupportedImport.isXcss)(node.callee, referencesInScope, importSources)) {
90
88
  return true;
91
89
  }
92
90
  if (node.parent) {
93
- return isDecendantOfXcssBlock(node.parent);
91
+ return isDecendantOfXcssBlock(node.parent, referencesInScope, importSources);
94
92
  }
95
93
  return false;
96
94
  };
@@ -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 { getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
4
5
  import { createLintRule } from '../utils/create-rule';
5
6
  import { includesHardCodedColor } from '../utils/is-color';
6
7
  import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType, isDecendantOfXcssBlock } from '../utils/is-node';
@@ -45,6 +46,15 @@ const createWithConfig = initialConfig => context => {
45
46
  }),
46
47
  // const styles = css({ color: 'red', margin: '4px' }), styled.div({ color: 'red', margin: '4px' })
47
48
  ObjectExpression: parentNode => errorBoundary(() => {
49
+ const {
50
+ references
51
+ } = context.getScope();
52
+ /**
53
+ * NOTE: This rule doesn't have an `importSources` config option,
54
+ * so this will just be equal to DEFAULT_IMPORT_SOURCES (which is fine)
55
+ */
56
+ const importSources = getImportSources(context);
57
+
48
58
  // To force the correct node type
49
59
  if (!isNodeOfType(parentNode, 'ObjectExpression')) {
50
60
  return;
@@ -54,7 +64,7 @@ const createWithConfig = initialConfig => context => {
54
64
  if (parentNode.parent.type === 'Property') {
55
65
  return;
56
66
  }
57
- if (isDecendantOfXcssBlock(parentNode)) {
67
+ if (isDecendantOfXcssBlock(parentNode, references, importSources)) {
58
68
  return;
59
69
  }
60
70
  if (!isDecendantOfStyleBlock(parentNode) && !isDecendantOfType(parentNode, 'JSXExpressionContainer')) {
@@ -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 { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
4
5
  import { Root } from '../../ast-nodes';
5
6
  export const isDecendantOfGlobalToken = node => {
6
7
  if (isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'token' || node.callee.name === 'getTokenValue')) {
@@ -68,14 +69,13 @@ const cssInJsCallees = ['css', 'styled', 'styled2'];
68
69
  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';
69
70
  export const isCssInJsCallNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && cssInJsCallees.includes(node.callee.name);
70
71
  export const isCssInJsObjectNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && cssInJsCallees.includes(node.callee.object.name);
71
- const isXcssCallNode = node => (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'xcss';
72
- export const isDecendantOfXcssBlock = node => {
72
+ export const isDecendantOfXcssBlock = (node, referencesInScope, importSources) => {
73
73
  // xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
74
- if (isXcssCallNode(node)) {
74
+ if (node.type === 'CallExpression' && isXcss(node.callee, referencesInScope, importSources)) {
75
75
  return true;
76
76
  }
77
77
  if (node.parent) {
78
- return isDecendantOfXcssBlock(node.parent);
78
+ return isDecendantOfXcssBlock(node.parent, referencesInScope, importSources);
79
79
  }
80
80
  return false;
81
81
  };
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  // eslint-disable-next-line import/no-extraneous-dependencies
3
3
 
4
4
  import { isNodeOfType } from 'eslint-codemod-utils';
5
+ import { getImportSources } from '@atlaskit/eslint-utils/is-supported-import';
5
6
  import { createLintRule } from '../utils/create-rule';
6
7
  import { includesHardCodedColor } from '../utils/is-color';
7
8
  import { isDecendantOfGlobalToken, isDecendantOfStyleBlock, isDecendantOfType, isDecendantOfXcssBlock } from '../utils/is-node';
@@ -60,6 +61,14 @@ var createWithConfig = function createWithConfig(initialConfig) {
60
61
  return ObjectExpression;
61
62
  }(function (parentNode) {
62
63
  return errorBoundary(function () {
64
+ var _context$getScope = context.getScope(),
65
+ references = _context$getScope.references;
66
+ /**
67
+ * NOTE: This rule doesn't have an `importSources` config option,
68
+ * so this will just be equal to DEFAULT_IMPORT_SOURCES (which is fine)
69
+ */
70
+ var importSources = getImportSources(context);
71
+
63
72
  // To force the correct node type
64
73
  if (!isNodeOfType(parentNode, 'ObjectExpression')) {
65
74
  return;
@@ -69,7 +78,7 @@ var createWithConfig = function createWithConfig(initialConfig) {
69
78
  if (parentNode.parent.type === 'Property') {
70
79
  return;
71
80
  }
72
- if (isDecendantOfXcssBlock(parentNode)) {
81
+ if (isDecendantOfXcssBlock(parentNode, references, importSources)) {
73
82
  return;
74
83
  }
75
84
  if (!isDecendantOfStyleBlock(parentNode) && !isDecendantOfType(parentNode, 'JSXExpressionContainer')) {
@@ -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 { isXcss } from '@atlaskit/eslint-utils/is-supported-import';
4
5
  import { Root } from '../../ast-nodes';
5
6
  export var isDecendantOfGlobalToken = function isDecendantOfGlobalToken(node) {
6
7
  if (isNodeOfType(node, 'CallExpression') && isNodeOfType(node.callee, 'Identifier') && (node.callee.name === 'token' || node.callee.name === 'getTokenValue')) {
@@ -75,16 +76,13 @@ export var isCssInJsCallNode = function isCssInJsCallNode(node) {
75
76
  export var isCssInJsObjectNode = function isCssInJsObjectNode(node) {
76
77
  return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.object.type === 'Identifier' && cssInJsCallees.includes(node.callee.object.name);
77
78
  };
78
- var isXcssCallNode = function isXcssCallNode(node) {
79
- return (node === null || node === void 0 ? void 0 : node.type) === 'CallExpression' && node.callee.type === 'Identifier' && node.callee.name === 'xcss';
80
- };
81
- export var isDecendantOfXcssBlock = function isDecendantOfXcssBlock(node) {
79
+ export var isDecendantOfXcssBlock = function isDecendantOfXcssBlock(node, referencesInScope, importSources) {
82
80
  // xcss contains types for all properties that accept tokens, so ignore xcss for linting as it will report false positives
83
- if (isXcssCallNode(node)) {
81
+ if (node.type === 'CallExpression' && isXcss(node.callee, referencesInScope, importSources)) {
84
82
  return true;
85
83
  }
86
84
  if (node.parent) {
87
- return isDecendantOfXcssBlock(node.parent);
85
+ return isDecendantOfXcssBlock(node.parent, referencesInScope, importSources);
88
86
  }
89
87
  return false;
90
88
  };
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from 'eslint';
2
- import { RuleConfig } from './types';
2
+ import { type RuleConfig } from './types';
3
3
  declare const createWithConfig: (initialConfig: RuleConfig) => Rule.RuleModule['create'];
4
4
  declare const rule: Rule.RuleModule;
5
5
  export default rule;
@@ -1,5 +1,5 @@
1
- import type { Rule } from 'eslint';
2
- import { CallExpression, EslintNode, Expression, TaggedTemplateExpression } from 'eslint-codemod-utils';
1
+ import type { Rule, Scope } from 'eslint';
2
+ import { type CallExpression, type EslintNode, type Expression, type TaggedTemplateExpression } from 'eslint-codemod-utils';
3
3
  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;
@@ -9,6 +9,6 @@ export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.Rul
9
9
  export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
10
10
  export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
11
11
  export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
12
- export declare const isDecendantOfXcssBlock: (node: Rule.Node) => boolean;
12
+ export declare const isDecendantOfXcssBlock: (node: Rule.Node, referencesInScope: Scope.Reference[], importSources: string[]) => boolean;
13
13
  export declare const isDecendantOfStyleBlock: (node: Rule.Node) => boolean;
14
14
  export declare const isChildOfType: (node: Rule.Node, type: Rule.Node['type']) => boolean;
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from 'eslint';
2
- import { RuleConfig } from './types';
2
+ import { type RuleConfig } from './types';
3
3
  declare const createWithConfig: (initialConfig: RuleConfig) => Rule.RuleModule['create'];
4
4
  declare const rule: Rule.RuleModule;
5
5
  export default rule;
@@ -1,5 +1,5 @@
1
- import type { Rule } from 'eslint';
2
- import { CallExpression, EslintNode, Expression, TaggedTemplateExpression } from 'eslint-codemod-utils';
1
+ import type { Rule, Scope } from 'eslint';
2
+ import { type CallExpression, type EslintNode, type Expression, type TaggedTemplateExpression } from 'eslint-codemod-utils';
3
3
  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;
@@ -9,6 +9,6 @@ export declare const isDecendantOfPrimitive: (node: Rule.Node, context: Rule.Rul
9
9
  export declare const isCssInJsTemplateNode: (node?: Expression | null) => node is TaggedTemplateExpression;
10
10
  export declare const isCssInJsCallNode: (node?: Expression | null) => node is CallExpression;
11
11
  export declare const isCssInJsObjectNode: (node?: Expression | null) => node is CallExpression;
12
- export declare const isDecendantOfXcssBlock: (node: Rule.Node) => boolean;
12
+ export declare const isDecendantOfXcssBlock: (node: Rule.Node, referencesInScope: Scope.Reference[], importSources: string[]) => boolean;
13
13
  export declare const isDecendantOfStyleBlock: (node: Rule.Node) => boolean;
14
14
  export declare const isChildOfType: (node: Rule.Node, type: Rule.Node['type']) => 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": "10.0.0",
4
+ "version": "10.0.1",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {