@atlaskit/eslint-plugin-design-system 4.0.1 → 4.1.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,15 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`52fbe80eeb5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/52fbe80eeb5) - Moved logic for detecting deprecated tokens out of no-unsafe-design-token-usage and moves it into a new rule: no-deprecated-token-usage. This rule is solely reponsible for catching usage of deprecated tokens. In most cases this allows consumers to set this rule to "warn", allowing iterative migration to new token names rather than in a big bang.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
3
13
  ## 4.0.1
4
14
 
5
15
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -9,6 +9,8 @@ exports.rules = exports.configs = void 0;
9
9
 
10
10
  var _ensureDesignTokenUsage = _interopRequireDefault(require("./rules/ensure-design-token-usage"));
11
11
 
12
+ var _noDeprecatedDesignTokenUsage = _interopRequireDefault(require("./rules/no-deprecated-design-token-usage"));
13
+
12
14
  var _noDeprecatedImports = _interopRequireDefault(require("./rules/no-deprecated-imports"));
13
15
 
14
16
  var _noUnsafeDesignTokenUsage = _interopRequireDefault(require("./rules/no-unsafe-design-token-usage"));
@@ -16,6 +18,7 @@ var _noUnsafeDesignTokenUsage = _interopRequireDefault(require("./rules/no-unsaf
16
18
  var rules = {
17
19
  'ensure-design-token-usage': _ensureDesignTokenUsage.default,
18
20
  'no-unsafe-design-token-usage': _noUnsafeDesignTokenUsage.default,
21
+ 'no-deprecated-design-token-usage': _noDeprecatedDesignTokenUsage.default,
19
22
  'no-deprecated-imports': _noDeprecatedImports.default
20
23
  };
21
24
  exports.rules = rules;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _renameMapping = _interopRequireDefault(require("@atlaskit/tokens/rename-mapping"));
11
+
12
+ var getCleanPathId = function getCleanPathId(path) {
13
+ return path.split('.').filter(function (el) {
14
+ return el !== '[default]';
15
+ }).join('.');
16
+ };
17
+
18
+ var rule = {
19
+ meta: {
20
+ docs: {
21
+ recommended: true
22
+ },
23
+ fixable: 'code',
24
+ type: 'problem',
25
+ messages: {
26
+ tokenRenamed: 'The token "{{name}}" is deprecated in favour of "{{replacement}}".'
27
+ }
28
+ },
29
+ create: function create(context) {
30
+ return {
31
+ 'CallExpression[callee.name="token"]': function CallExpressionCalleeNameToken(node) {
32
+ if (node.type !== 'CallExpression') {
33
+ return;
34
+ }
35
+
36
+ if (node.arguments[0].type !== 'Literal') {
37
+ return;
38
+ }
39
+
40
+ var tokenKey = node.arguments[0].value;
41
+
42
+ if (!tokenKey) {
43
+ return;
44
+ }
45
+
46
+ if (typeof tokenKey !== 'string') {
47
+ return;
48
+ }
49
+
50
+ var migrationMeta = _renameMapping.default.filter(function (t) {
51
+ return t.state === 'deprecated';
52
+ }).find(function (t) {
53
+ return t.path === tokenKey;
54
+ });
55
+
56
+ if (migrationMeta) {
57
+ var cleanTokenKey = getCleanPathId(migrationMeta.replacement);
58
+ context.report({
59
+ messageId: 'tokenRenamed',
60
+ node: node,
61
+ data: {
62
+ name: tokenKey,
63
+ replacement: cleanTokenKey
64
+ },
65
+ fix: function fix(fixer) {
66
+ return fixer.replaceText(node.arguments[0], "'".concat(cleanTokenKey, "'"));
67
+ }
68
+ });
69
+ return;
70
+ }
71
+ }
72
+ };
73
+ }
74
+ };
75
+ var _default = rule;
76
+ exports.default = _default;
@@ -15,6 +15,12 @@ var _isNode = require("../utils/is-node");
15
15
 
16
16
  var _isToken = require("../utils/is-token");
17
17
 
18
+ var getCleanPathId = function getCleanPathId(path) {
19
+ return path.split('.').filter(function (el) {
20
+ return el !== '[default]';
21
+ }).join('.');
22
+ };
23
+
18
24
  var defaultConfig = {
19
25
  shouldEnforceFallbacks: false
20
26
  };
@@ -29,7 +35,7 @@ var rule = {
29
35
  directTokenUsage: "Access the global theme using the token function.\n\n```\nimport { token } from '@atlaskit/tokens';\n\ntoken('{{tokenKey}}');\n```\n",
30
36
  staticToken: "Token string should be inlined directly into the function call.\n\n```\ntoken('color.background.blanket');\n```\n",
31
37
  invalidToken: 'The token "{{name}}" does not exist.',
32
- tokenRenamed: 'The token "{{name}}" has been renamed.',
38
+ tokenRemoved: 'The token "{{name}}" is removed in favour of "{{replacement}}".',
33
39
  tokenFallbackEnforced: "Token function requires a fallback, preferably something that best matches the light/default theme in case tokens aren't present.\n\n```\ntoken('color.background.blanket', N500A);\n```\n ",
34
40
  tokenFallbackRestricted: "Token function must not use a fallback.\n\n```\ntoken('color.background.blanket');\n```\n "
35
41
  }
@@ -130,15 +136,23 @@ var rule = {
130
136
  return;
131
137
  }
132
138
 
133
- if (typeof tokenKey === 'string' && tokenKey in _renameMapping.default) {
139
+ var migrationMeta = _renameMapping.default.filter(function (t) {
140
+ return t.state === 'deleted';
141
+ }).find(function (t) {
142
+ return t.path === tokenKey;
143
+ });
144
+
145
+ if (typeof tokenKey === 'string' && migrationMeta) {
146
+ var cleanTokenKey = getCleanPathId(migrationMeta.replacement);
134
147
  context.report({
135
- messageId: 'tokenRenamed',
148
+ messageId: 'tokenRemoved',
136
149
  node: node,
137
150
  data: {
138
- name: tokenKey
151
+ name: tokenKey,
152
+ replacement: cleanTokenKey
139
153
  },
140
154
  fix: function fix(fixer) {
141
- return fixer.replaceText(node.arguments[0], "'".concat(_renameMapping.default[tokenKey], "'"));
155
+ return fixer.replaceText(node.arguments[0], "'".concat(cleanTokenKey, "'"));
142
156
  }
143
157
  });
144
158
  return;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,9 +1,11 @@
1
1
  import ensureTokenUsage from './rules/ensure-design-token-usage';
2
+ import noDeprecatedUsage from './rules/no-deprecated-design-token-usage';
2
3
  import noDeprecatedImports from './rules/no-deprecated-imports';
3
4
  import noUnsafeUsage from './rules/no-unsafe-design-token-usage';
4
5
  export const rules = {
5
6
  'ensure-design-token-usage': ensureTokenUsage,
6
7
  'no-unsafe-design-token-usage': noUnsafeUsage,
8
+ 'no-deprecated-design-token-usage': noDeprecatedUsage,
7
9
  'no-deprecated-imports': noDeprecatedImports
8
10
  };
9
11
  export const configs = {
@@ -0,0 +1,58 @@
1
+ import renameMapping from '@atlaskit/tokens/rename-mapping';
2
+
3
+ const getCleanPathId = path => path.split('.').filter(el => el !== '[default]').join('.');
4
+
5
+ const rule = {
6
+ meta: {
7
+ docs: {
8
+ recommended: true
9
+ },
10
+ fixable: 'code',
11
+ type: 'problem',
12
+ messages: {
13
+ tokenRenamed: 'The token "{{name}}" is deprecated in favour of "{{replacement}}".'
14
+ }
15
+ },
16
+
17
+ create(context) {
18
+ return {
19
+ 'CallExpression[callee.name="token"]': node => {
20
+ if (node.type !== 'CallExpression') {
21
+ return;
22
+ }
23
+
24
+ if (node.arguments[0].type !== 'Literal') {
25
+ return;
26
+ }
27
+
28
+ const tokenKey = node.arguments[0].value;
29
+
30
+ if (!tokenKey) {
31
+ return;
32
+ }
33
+
34
+ if (typeof tokenKey !== 'string') {
35
+ return;
36
+ }
37
+
38
+ const migrationMeta = renameMapping.filter(t => t.state === 'deprecated').find(t => t.path === tokenKey);
39
+
40
+ if (migrationMeta) {
41
+ const cleanTokenKey = getCleanPathId(migrationMeta.replacement);
42
+ context.report({
43
+ messageId: 'tokenRenamed',
44
+ node,
45
+ data: {
46
+ name: tokenKey,
47
+ replacement: cleanTokenKey
48
+ },
49
+ fix: fixer => fixer.replaceText(node.arguments[0], `'${cleanTokenKey}'`)
50
+ });
51
+ return;
52
+ }
53
+ }
54
+ };
55
+ }
56
+
57
+ };
58
+ export default rule;
@@ -2,6 +2,9 @@ import renameMapping from '@atlaskit/tokens/rename-mapping';
2
2
  import tokens from '@atlaskit/tokens/token-names';
3
3
  import { isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute } from '../utils/is-node';
4
4
  import { isToken } from '../utils/is-token';
5
+
6
+ const getCleanPathId = path => path.split('.').filter(el => el !== '[default]').join('.');
7
+
5
8
  const defaultConfig = {
6
9
  shouldEnforceFallbacks: false
7
10
  };
@@ -28,7 +31,7 @@ token('color.background.blanket');
28
31
  \`\`\`
29
32
  `,
30
33
  invalidToken: 'The token "{{name}}" does not exist.',
31
- tokenRenamed: 'The token "{{name}}" has been renamed.',
34
+ tokenRemoved: 'The token "{{name}}" is removed in favour of "{{replacement}}".',
32
35
  tokenFallbackEnforced: `Token function requires a fallback, preferably something that best matches the light/default theme in case tokens aren't present.
33
36
 
34
37
  \`\`\`
@@ -136,14 +139,18 @@ token('color.background.blanket');
136
139
  return;
137
140
  }
138
141
 
139
- if (typeof tokenKey === 'string' && tokenKey in renameMapping) {
142
+ const migrationMeta = renameMapping.filter(t => t.state === 'deleted').find(t => t.path === tokenKey);
143
+
144
+ if (typeof tokenKey === 'string' && migrationMeta) {
145
+ const cleanTokenKey = getCleanPathId(migrationMeta.replacement);
140
146
  context.report({
141
- messageId: 'tokenRenamed',
147
+ messageId: 'tokenRemoved',
142
148
  node,
143
149
  data: {
144
- name: tokenKey
150
+ name: tokenKey,
151
+ replacement: cleanTokenKey
145
152
  },
146
- fix: fixer => fixer.replaceText(node.arguments[0], `'${renameMapping[tokenKey]}'`)
153
+ fix: fixer => fixer.replaceText(node.arguments[0], `'${cleanTokenKey}'`)
147
154
  });
148
155
  return;
149
156
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "sideEffects": false
5
5
  }
package/dist/esm/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import ensureTokenUsage from './rules/ensure-design-token-usage';
2
+ import noDeprecatedUsage from './rules/no-deprecated-design-token-usage';
2
3
  import noDeprecatedImports from './rules/no-deprecated-imports';
3
4
  import noUnsafeUsage from './rules/no-unsafe-design-token-usage';
4
5
  export var rules = {
5
6
  'ensure-design-token-usage': ensureTokenUsage,
6
7
  'no-unsafe-design-token-usage': noUnsafeUsage,
8
+ 'no-deprecated-design-token-usage': noDeprecatedUsage,
7
9
  'no-deprecated-imports': noDeprecatedImports
8
10
  };
9
11
  export var configs = {
@@ -0,0 +1,66 @@
1
+ import renameMapping from '@atlaskit/tokens/rename-mapping';
2
+
3
+ var getCleanPathId = function getCleanPathId(path) {
4
+ return path.split('.').filter(function (el) {
5
+ return el !== '[default]';
6
+ }).join('.');
7
+ };
8
+
9
+ var rule = {
10
+ meta: {
11
+ docs: {
12
+ recommended: true
13
+ },
14
+ fixable: 'code',
15
+ type: 'problem',
16
+ messages: {
17
+ tokenRenamed: 'The token "{{name}}" is deprecated in favour of "{{replacement}}".'
18
+ }
19
+ },
20
+ create: function create(context) {
21
+ return {
22
+ 'CallExpression[callee.name="token"]': function CallExpressionCalleeNameToken(node) {
23
+ if (node.type !== 'CallExpression') {
24
+ return;
25
+ }
26
+
27
+ if (node.arguments[0].type !== 'Literal') {
28
+ return;
29
+ }
30
+
31
+ var tokenKey = node.arguments[0].value;
32
+
33
+ if (!tokenKey) {
34
+ return;
35
+ }
36
+
37
+ if (typeof tokenKey !== 'string') {
38
+ return;
39
+ }
40
+
41
+ var migrationMeta = renameMapping.filter(function (t) {
42
+ return t.state === 'deprecated';
43
+ }).find(function (t) {
44
+ return t.path === tokenKey;
45
+ });
46
+
47
+ if (migrationMeta) {
48
+ var cleanTokenKey = getCleanPathId(migrationMeta.replacement);
49
+ context.report({
50
+ messageId: 'tokenRenamed',
51
+ node: node,
52
+ data: {
53
+ name: tokenKey,
54
+ replacement: cleanTokenKey
55
+ },
56
+ fix: function fix(fixer) {
57
+ return fixer.replaceText(node.arguments[0], "'".concat(cleanTokenKey, "'"));
58
+ }
59
+ });
60
+ return;
61
+ }
62
+ }
63
+ };
64
+ }
65
+ };
66
+ export default rule;
@@ -2,6 +2,13 @@ import renameMapping from '@atlaskit/tokens/rename-mapping';
2
2
  import tokens from '@atlaskit/tokens/token-names';
3
3
  import { isDecendantOfStyleBlock, isDecendantOfStyleJsxAttribute } from '../utils/is-node';
4
4
  import { isToken } from '../utils/is-token';
5
+
6
+ var getCleanPathId = function getCleanPathId(path) {
7
+ return path.split('.').filter(function (el) {
8
+ return el !== '[default]';
9
+ }).join('.');
10
+ };
11
+
5
12
  var defaultConfig = {
6
13
  shouldEnforceFallbacks: false
7
14
  };
@@ -16,7 +23,7 @@ var rule = {
16
23
  directTokenUsage: "Access the global theme using the token function.\n\n```\nimport { token } from '@atlaskit/tokens';\n\ntoken('{{tokenKey}}');\n```\n",
17
24
  staticToken: "Token string should be inlined directly into the function call.\n\n```\ntoken('color.background.blanket');\n```\n",
18
25
  invalidToken: 'The token "{{name}}" does not exist.',
19
- tokenRenamed: 'The token "{{name}}" has been renamed.',
26
+ tokenRemoved: 'The token "{{name}}" is removed in favour of "{{replacement}}".',
20
27
  tokenFallbackEnforced: "Token function requires a fallback, preferably something that best matches the light/default theme in case tokens aren't present.\n\n```\ntoken('color.background.blanket', N500A);\n```\n ",
21
28
  tokenFallbackRestricted: "Token function must not use a fallback.\n\n```\ntoken('color.background.blanket');\n```\n "
22
29
  }
@@ -117,15 +124,23 @@ var rule = {
117
124
  return;
118
125
  }
119
126
 
120
- if (typeof tokenKey === 'string' && tokenKey in renameMapping) {
127
+ var migrationMeta = renameMapping.filter(function (t) {
128
+ return t.state === 'deleted';
129
+ }).find(function (t) {
130
+ return t.path === tokenKey;
131
+ });
132
+
133
+ if (typeof tokenKey === 'string' && migrationMeta) {
134
+ var cleanTokenKey = getCleanPathId(migrationMeta.replacement);
121
135
  context.report({
122
- messageId: 'tokenRenamed',
136
+ messageId: 'tokenRemoved',
123
137
  node: node,
124
138
  data: {
125
- name: tokenKey
139
+ name: tokenKey,
140
+ replacement: cleanTokenKey
126
141
  },
127
142
  fix: function fix(fixer) {
128
- return fixer.replaceText(node.arguments[0], "'".concat(renameMapping[tokenKey], "'"));
143
+ return fixer.replaceText(node.arguments[0], "'".concat(cleanTokenKey, "'"));
129
144
  }
130
145
  });
131
146
  return;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,6 +1,7 @@
1
1
  export declare const rules: {
2
2
  'ensure-design-token-usage': import("eslint").Rule.RuleModule;
3
3
  'no-unsafe-design-token-usage': import("eslint").Rule.RuleModule;
4
+ 'no-deprecated-design-token-usage': import("eslint").Rule.RuleModule;
4
5
  'no-deprecated-imports': import("eslint").Rule.RuleModule;
5
6
  };
6
7
  export declare const configs: {
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ declare const rule: Rule.RuleModule;
3
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-design-system",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -20,7 +20,7 @@
20
20
  ".": "./src/index.tsx"
21
21
  },
22
22
  "dependencies": {
23
- "@atlaskit/tokens": "^0.4.0",
23
+ "@atlaskit/tokens": "^0.5.0",
24
24
  "@babel/runtime": "^7.0.0"
25
25
  },
26
26
  "devDependencies": {