@atlaskit/eslint-plugin-design-system 13.17.3 → 13.18.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +1 -0
  3. package/dist/cjs/presets/all-flat.codegen.js +2 -1
  4. package/dist/cjs/presets/all.codegen.js +2 -1
  5. package/dist/cjs/presets/recommended-flat.codegen.js +2 -1
  6. package/dist/cjs/presets/recommended.codegen.js +2 -1
  7. package/dist/cjs/rules/index.codegen.js +3 -1
  8. package/dist/cjs/rules/no-utility-icons/checks.js +0 -1
  9. package/dist/cjs/rules/use-correct-field/index.js +186 -0
  10. package/dist/es2019/presets/all-flat.codegen.js +2 -1
  11. package/dist/es2019/presets/all.codegen.js +2 -1
  12. package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
  13. package/dist/es2019/presets/recommended.codegen.js +2 -1
  14. package/dist/es2019/rules/index.codegen.js +3 -1
  15. package/dist/es2019/rules/no-utility-icons/checks.js +0 -1
  16. package/dist/es2019/rules/use-correct-field/index.js +160 -0
  17. package/dist/esm/presets/all-flat.codegen.js +2 -1
  18. package/dist/esm/presets/all.codegen.js +2 -1
  19. package/dist/esm/presets/recommended-flat.codegen.js +2 -1
  20. package/dist/esm/presets/recommended.codegen.js +2 -1
  21. package/dist/esm/rules/index.codegen.js +3 -1
  22. package/dist/esm/rules/no-utility-icons/checks.js +0 -1
  23. package/dist/esm/rules/use-correct-field/index.js +180 -0
  24. package/dist/types/index.codegen.d.ts +9 -0
  25. package/dist/types/presets/all-flat.codegen.d.ts +1 -0
  26. package/dist/types/presets/all.codegen.d.ts +1 -0
  27. package/dist/types/presets/recommended-flat.codegen.d.ts +1 -0
  28. package/dist/types/presets/recommended.codegen.d.ts +1 -0
  29. package/dist/types/rules/index.codegen.d.ts +1 -0
  30. package/dist/types/rules/use-correct-field/index.d.ts +5 -0
  31. package/dist/types-ts4.5/index.codegen.d.ts +9 -0
  32. package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +1 -0
  33. package/dist/types-ts4.5/presets/all.codegen.d.ts +1 -0
  34. package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +1 -0
  35. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +1 -0
  36. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  37. package/dist/types-ts4.5/rules/use-correct-field/index.d.ts +5 -0
  38. package/package.json +6 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @atlaskit/eslint-plugin-design-system
2
2
 
3
+ ## 13.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#188850](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/188850)
8
+ [`8b19a85abe51e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8b19a85abe51e) -
9
+ Add nmore cases to the new use correct field rule.
10
+ - Updated dependencies
11
+
12
+ ## 13.18.0
13
+
14
+ ### Minor Changes
15
+
16
+ - [#187514](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/187514)
17
+ [`c159d1d45ed81`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c159d1d45ed81) -
18
+ Add new rule to check that inputs use the correct field component from form.
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies
23
+
3
24
  ## 13.17.3
4
25
 
5
26
  ### Patch Changes
package/README.md CHANGED
@@ -94,6 +94,7 @@ module.exports = {
94
94
  | <a href="./packages/design-system/eslint-plugin/src/rules/no-utility-icons/README.md">no-utility-icons</a> | Disallow use of deprecated utility icons, in favor of core icons with `size="small"`. | Yes | Yes | Yes |
95
95
  | <a href="./packages/design-system/eslint-plugin/src/rules/prefer-primitives/README.md">prefer-primitives</a> | Increase awareness of primitive components via code hints. Strictly used for education purposes and discoverability. To enforce usage please refer to the `use-primitives` rule. | | | |
96
96
  | <a href="./packages/design-system/eslint-plugin/src/rules/use-button-group-label/README.md">use-button-group-label</a> | Ensures button groups are described to assistive technology by a direct label or by another element. | Yes | | Yes |
97
+ | <a href="./packages/design-system/eslint-plugin/src/rules/use-correct-field/README.md">use-correct-field</a> | Ensure makers use appropriate field component for their respective form elements. | Yes | Yes | Yes |
97
98
  | <a href="./packages/design-system/eslint-plugin/src/rules/use-cx-function-in-xcss/README.md">use-cx-function-in-xcss</a> | Enforces cx function use to combine styles in xcss. | Yes | Yes | Yes |
98
99
  | <a href="./packages/design-system/eslint-plugin/src/rules/use-datetime-picker-calendar-button/README.md">use-datetime-picker-calendar-button</a> | Encourages makers to use calendar button in Atlassian Design System's date picker and datetime picker components. | Yes | Yes | Yes |
99
100
  | <a href="./packages/design-system/eslint-plugin/src/rules/use-drawer-label/README.md">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | Yes |
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::a8f7f6388f0499adc9db0228b7426aee>>
9
+ * @codegen <<SignedSource::8fb6e53ac7d9be7b9252dd64ec022d26>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -57,6 +57,7 @@ var _default = exports.default = {
57
57
  '@atlaskit/design-system/no-utility-icons': 'warn',
58
58
  '@atlaskit/design-system/prefer-primitives': 'warn',
59
59
  '@atlaskit/design-system/use-button-group-label': 'warn',
60
+ '@atlaskit/design-system/use-correct-field': 'warn',
60
61
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
61
62
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
62
63
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::aaf4f1ee2f2db236ebed7b77de426181>>
9
+ * @codegen <<SignedSource::b727e6e2b1813b88da0df6ff6083be3c>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -56,6 +56,7 @@ var _default = exports.default = {
56
56
  '@atlaskit/design-system/no-utility-icons': 'warn',
57
57
  '@atlaskit/design-system/prefer-primitives': 'warn',
58
58
  '@atlaskit/design-system/use-button-group-label': 'warn',
59
+ '@atlaskit/design-system/use-correct-field': 'warn',
59
60
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
60
61
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
61
62
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::10f372e16c048db9bfb1bc36cf48421c>>
9
+ * @codegen <<SignedSource::af48ffd75d906d008c5701554187b606>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -43,6 +43,7 @@ var _default = exports.default = {
43
43
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
44
44
  '@atlaskit/design-system/no-utility-icons': 'warn',
45
45
  '@atlaskit/design-system/use-button-group-label': 'warn',
46
+ '@atlaskit/design-system/use-correct-field': 'warn',
46
47
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
47
48
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
48
49
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::608f46f9cc8653226152a8edc34849d6>>
9
+ * @codegen <<SignedSource::96e803ae8ae873736bab690b2af62bed>>
10
10
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
11
11
  */
12
12
  var _default = exports.default = {
@@ -42,6 +42,7 @@ var _default = exports.default = {
42
42
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
43
43
  '@atlaskit/design-system/no-utility-icons': 'warn',
44
44
  '@atlaskit/design-system/use-button-group-label': 'warn',
45
+ '@atlaskit/design-system/use-correct-field': 'warn',
45
46
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
46
47
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
47
48
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -50,6 +50,7 @@ var _noUnsupportedDragAndDropLibraries = _interopRequireDefault(require("./no-un
50
50
  var _noUtilityIcons = _interopRequireDefault(require("./no-utility-icons"));
51
51
  var _preferPrimitives = _interopRequireDefault(require("./prefer-primitives"));
52
52
  var _useButtonGroupLabel = _interopRequireDefault(require("./use-button-group-label"));
53
+ var _useCorrectField = _interopRequireDefault(require("./use-correct-field"));
53
54
  var _useCxFunctionInXcss = _interopRequireDefault(require("./use-cx-function-in-xcss"));
54
55
  var _useDatetimePickerCalendarButton = _interopRequireDefault(require("./use-datetime-picker-calendar-button"));
55
56
  var _useDrawerLabel = _interopRequireDefault(require("./use-drawer-label"));
@@ -71,7 +72,7 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
71
72
  var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
72
73
  /**
73
74
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
74
- * @codegen <<SignedSource::c3ee5646fc648d2510a70195a04d7fe9>>
75
+ * @codegen <<SignedSource::3c4282c17de41bbfb755836f00326036>>
75
76
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
76
77
  */
77
78
 
@@ -121,6 +122,7 @@ var rules = exports.rules = {
121
122
  'no-utility-icons': _noUtilityIcons.default,
122
123
  'prefer-primitives': _preferPrimitives.default,
123
124
  'use-button-group-label': _useButtonGroupLabel.default,
125
+ 'use-correct-field': _useCorrectField.default,
124
126
  'use-cx-function-in-xcss': _useCxFunctionInXcss.default,
125
127
  'use-datetime-picker-calendar-button': _useDatetimePickerCalendarButton.default,
126
128
  'use-drawer-label': _useDrawerLabel.default,
@@ -11,7 +11,6 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
11
11
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
12
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
13
  var specialCases = {
14
- '@atlaskit/icon/utility/cross': '@atlaskit/icon/core/close',
15
14
  '@atlaskit/icon/utility/migration/cross--editor-close': '@atlaskit/icon/core/migration/close--editor-close'
16
15
  };
17
16
  var iconPropsinNewButton = ['icon', 'iconBefore', 'iconAfter'];
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useRangeFieldMessage = exports.useCheckboxFieldMessage = exports.default = void 0;
7
+ var _eslintCodemodUtils = require("eslint-codemod-utils");
8
+ var _createRule = require("../utils/create-rule");
9
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
11
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
12
+ var specialFieldsByImport = {
13
+ '@atlaskit/checkbox': {
14
+ component: 'Checkbox',
15
+ field: 'CheckboxField',
16
+ local: undefined
17
+ },
18
+ '@atlaskit/range': {
19
+ component: 'Range',
20
+ field: 'RangeField',
21
+ local: undefined
22
+ },
23
+ '@atlaskit/toggle': {
24
+ component: 'Toggle',
25
+ field: 'CheckboxField',
26
+ local: undefined
27
+ }
28
+ };
29
+ var useCheckboxFieldMessage = exports.useCheckboxFieldMessage = 'Convert Field to CheckboxField';
30
+ var useRangeFieldMessage = exports.useRangeFieldMessage = 'Convert Field to RangeField';
31
+ var rule = (0, _createRule.createLintRule)({
32
+ meta: {
33
+ name: 'use-correct-field',
34
+ type: 'suggestion',
35
+ fixable: 'code',
36
+ hasSuggestions: true,
37
+ docs: {
38
+ description: 'Ensure makers use appropriate field component for their respective form elements.',
39
+ recommended: true,
40
+ severity: 'warn'
41
+ },
42
+ messages: {
43
+ useCheckboxField: 'Checkbox components should use the `CheckboxField` component',
44
+ useRangeField: 'Range components should use the `RangeField` component',
45
+ useCheckboxFieldForToggle: 'Toggle components should use the `CheckboxField` component'
46
+ }
47
+ },
48
+ create: function create(context) {
49
+ var fieldImport;
50
+ var allPackages = [];
51
+ return {
52
+ ImportDeclaration: function ImportDeclaration(node) {
53
+ var source = node.source.value;
54
+ if (typeof source !== 'string') {
55
+ return;
56
+ }
57
+ if (!node.specifiers.length) {
58
+ return;
59
+ }
60
+ var defaultImport = node.specifiers.filter(function (spec) {
61
+ return (0, _eslintCodemodUtils.isNodeOfType)(spec, 'ImportDefaultSpecifier');
62
+ });
63
+ if (source in specialFieldsByImport) {
64
+ allPackages.push(node);
65
+ // set local to local value
66
+ if (defaultImport.length && (0, _eslintCodemodUtils.isNodeOfType)(defaultImport[0], 'ImportDefaultSpecifier') && (0, _eslintCodemodUtils.isNodeOfType)(defaultImport[0].local, 'Identifier')) {
67
+ specialFieldsByImport[source].local = defaultImport[0].local.name;
68
+ }
69
+ }
70
+ if ('@atlaskit/form' !== source) {
71
+ return;
72
+ }
73
+ var namedImport = node.specifiers.filter(function (spec) {
74
+ return (0, _eslintCodemodUtils.isNodeOfType)(spec, 'ImportSpecifier');
75
+ });
76
+ if (namedImport.length && namedImport[0].type === 'ImportSpecifier' && namedImport[0].imported.name === 'Field') {
77
+ fieldImport = namedImport[0].local;
78
+ }
79
+ },
80
+ JSXElement: function JSXElement(node) {
81
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
82
+ return;
83
+ }
84
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
85
+ return;
86
+ }
87
+ var name = node.openingElement.name.name;
88
+
89
+ // if it's not a field import, skip
90
+ if (!fieldImport || name !== fieldImport.name) {
91
+ return;
92
+ }
93
+
94
+ // If no imports are for the inputs that have special fields, exit early
95
+ if (allPackages.every(function (n) {
96
+ return typeof n.source.value !== 'string' || !Object.keys(specialFieldsByImport).includes(n.source.value);
97
+ })) {
98
+ return;
99
+ }
100
+ var fieldRenderProp = node.children.find(function (c) {
101
+ return (0, _eslintCodemodUtils.isNodeOfType)(c, 'JSXExpressionContainer');
102
+ });
103
+ if (!fieldRenderProp) {
104
+ return;
105
+ }
106
+ // I'm not early exiting because it doesn't work with ts for some reason
107
+ if ((0, _eslintCodemodUtils.isNodeOfType)(fieldRenderProp, 'JSXExpressionContainer')) {
108
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(fieldRenderProp.expression, 'ArrowFunctionExpression')) {
109
+ return;
110
+ }
111
+ var q = [fieldRenderProp.expression.body];
112
+ var found;
113
+ while (q.length > 0 && !found) {
114
+ var child = q.pop();
115
+ if ('children' in child) {
116
+ var _iterator = _createForOfIteratorHelper(child.children),
117
+ _step;
118
+ try {
119
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
120
+ var innerChild = _step.value;
121
+ q.push(innerChild);
122
+ }
123
+ } catch (err) {
124
+ _iterator.e(err);
125
+ } finally {
126
+ _iterator.f();
127
+ }
128
+ } else if ((0, _eslintCodemodUtils.isNodeOfType)(child, 'BlockStatement') && (0, _eslintCodemodUtils.isNodeOfType)(child.body[0], 'ExpressionStatement')) {
129
+ q.push(child.body[0].expression);
130
+ }
131
+ if (!(0, _eslintCodemodUtils.isNodeOfType)(child, 'JSXElement') || !(0, _eslintCodemodUtils.isNodeOfType)(child.openingElement.name, 'JSXIdentifier')) {
132
+ continue;
133
+ }
134
+ var elementName = child.openingElement.name.name;
135
+ for (var importName in specialFieldsByImport) {
136
+ // if this child is one of the found component names
137
+ // then break out of the while loop and use the found object
138
+ var localName = specialFieldsByImport[importName].local;
139
+ if (localName === elementName) {
140
+ found = specialFieldsByImport[importName].component;
141
+ break;
142
+ }
143
+ }
144
+ }
145
+ if (!found) {
146
+ return;
147
+ }
148
+
149
+ // if checkbox is inside of the field's render prop
150
+ if (found === 'Checkbox' || found === 'Toggle') {
151
+ context.report({
152
+ node: node,
153
+ messageId: found === 'Checkbox' ? 'useCheckboxField' : 'useCheckboxFieldForToggle',
154
+ suggest: [{
155
+ desc: useCheckboxFieldMessage,
156
+ fix: function fix(fixer) {
157
+ var fixes = [];
158
+ fixes.push(fixer.insertTextBefore(fieldImport, 'CheckboxField, '));
159
+ fixes.push(fixer.replaceText(node.openingElement.name, 'CheckboxField'));
160
+ node.closingElement && fixes.push(fixer.replaceText(node.closingElement.name, 'CheckboxField'));
161
+ return fixes;
162
+ }
163
+ }]
164
+ });
165
+ } else if (found === 'Range') {
166
+ context.report({
167
+ node: node,
168
+ messageId: 'useRangeField',
169
+ suggest: [{
170
+ desc: useRangeFieldMessage,
171
+ fix: function fix(fixer) {
172
+ var fixes = [];
173
+ fixes.push(fixer.insertTextBefore(fieldImport, 'RangeField, '));
174
+ fixes.push(fixer.replaceText(node.openingElement.name, 'RangeField'));
175
+ node.closingElement && fixes.push(fixer.replaceText(node.closingElement.name, 'RangeField'));
176
+ return fixes;
177
+ }
178
+ }]
179
+ });
180
+ }
181
+ }
182
+ }
183
+ };
184
+ }
185
+ });
186
+ var _default = exports.default = rule;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::a8f7f6388f0499adc9db0228b7426aee>>
3
+ * @codegen <<SignedSource::8fb6e53ac7d9be7b9252dd64ec022d26>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -52,6 +52,7 @@ export default {
52
52
  '@atlaskit/design-system/no-utility-icons': 'warn',
53
53
  '@atlaskit/design-system/prefer-primitives': 'warn',
54
54
  '@atlaskit/design-system/use-button-group-label': 'warn',
55
+ '@atlaskit/design-system/use-correct-field': 'warn',
55
56
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
56
57
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
57
58
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::aaf4f1ee2f2db236ebed7b77de426181>>
3
+ * @codegen <<SignedSource::b727e6e2b1813b88da0df6ff6083be3c>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -51,6 +51,7 @@ export default {
51
51
  '@atlaskit/design-system/no-utility-icons': 'warn',
52
52
  '@atlaskit/design-system/prefer-primitives': 'warn',
53
53
  '@atlaskit/design-system/use-button-group-label': 'warn',
54
+ '@atlaskit/design-system/use-correct-field': 'warn',
54
55
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
55
56
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
56
57
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::10f372e16c048db9bfb1bc36cf48421c>>
3
+ * @codegen <<SignedSource::af48ffd75d906d008c5701554187b606>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -38,6 +38,7 @@ export default {
38
38
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
39
39
  '@atlaskit/design-system/no-utility-icons': 'warn',
40
40
  '@atlaskit/design-system/use-button-group-label': 'warn',
41
+ '@atlaskit/design-system/use-correct-field': 'warn',
41
42
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
42
43
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
43
44
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::608f46f9cc8653226152a8edc34849d6>>
3
+ * @codegen <<SignedSource::96e803ae8ae873736bab690b2af62bed>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -37,6 +37,7 @@ export default {
37
37
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
38
38
  '@atlaskit/design-system/no-utility-icons': 'warn',
39
39
  '@atlaskit/design-system/use-button-group-label': 'warn',
40
+ '@atlaskit/design-system/use-correct-field': 'warn',
40
41
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
41
42
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
42
43
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::c3ee5646fc648d2510a70195a04d7fe9>>
3
+ * @codegen <<SignedSource::3c4282c17de41bbfb755836f00326036>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -48,6 +48,7 @@ import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-li
48
48
  import noUtilityIcons from './no-utility-icons';
49
49
  import preferPrimitives from './prefer-primitives';
50
50
  import useButtonGroupLabel from './use-button-group-label';
51
+ import useCorrectField from './use-correct-field';
51
52
  import useCxFunctionInXcss from './use-cx-function-in-xcss';
52
53
  import useDatetimePickerCalendarButton from './use-datetime-picker-calendar-button';
53
54
  import useDrawerLabel from './use-drawer-label';
@@ -113,6 +114,7 @@ export const rules = {
113
114
  'no-utility-icons': noUtilityIcons,
114
115
  'prefer-primitives': preferPrimitives,
115
116
  'use-button-group-label': useButtonGroupLabel,
117
+ 'use-correct-field': useCorrectField,
116
118
  'use-cx-function-in-xcss': useCxFunctionInXcss,
117
119
  'use-datetime-picker-calendar-button': useDatetimePickerCalendarButton,
118
120
  'use-drawer-label': useDrawerLabel,
@@ -1,6 +1,5 @@
1
1
  import { isNodeOfType } from 'eslint-codemod-utils';
2
2
  const specialCases = {
3
- '@atlaskit/icon/utility/cross': '@atlaskit/icon/core/close',
4
3
  '@atlaskit/icon/utility/migration/cross--editor-close': '@atlaskit/icon/core/migration/close--editor-close'
5
4
  };
6
5
  const iconPropsinNewButton = ['icon', 'iconBefore', 'iconAfter'];
@@ -0,0 +1,160 @@
1
+ import { isNodeOfType } from 'eslint-codemod-utils';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ const specialFieldsByImport = {
4
+ '@atlaskit/checkbox': {
5
+ component: 'Checkbox',
6
+ field: 'CheckboxField',
7
+ local: undefined
8
+ },
9
+ '@atlaskit/range': {
10
+ component: 'Range',
11
+ field: 'RangeField',
12
+ local: undefined
13
+ },
14
+ '@atlaskit/toggle': {
15
+ component: 'Toggle',
16
+ field: 'CheckboxField',
17
+ local: undefined
18
+ }
19
+ };
20
+ export const useCheckboxFieldMessage = 'Convert Field to CheckboxField';
21
+ export const useRangeFieldMessage = 'Convert Field to RangeField';
22
+ const rule = createLintRule({
23
+ meta: {
24
+ name: 'use-correct-field',
25
+ type: 'suggestion',
26
+ fixable: 'code',
27
+ hasSuggestions: true,
28
+ docs: {
29
+ description: 'Ensure makers use appropriate field component for their respective form elements.',
30
+ recommended: true,
31
+ severity: 'warn'
32
+ },
33
+ messages: {
34
+ useCheckboxField: 'Checkbox components should use the `CheckboxField` component',
35
+ useRangeField: 'Range components should use the `RangeField` component',
36
+ useCheckboxFieldForToggle: 'Toggle components should use the `CheckboxField` component'
37
+ }
38
+ },
39
+ create(context) {
40
+ let fieldImport;
41
+ const allPackages = [];
42
+ return {
43
+ ImportDeclaration(node) {
44
+ const source = node.source.value;
45
+ if (typeof source !== 'string') {
46
+ return;
47
+ }
48
+ if (!node.specifiers.length) {
49
+ return;
50
+ }
51
+ const defaultImport = node.specifiers.filter(spec => isNodeOfType(spec, 'ImportDefaultSpecifier'));
52
+ if (source in specialFieldsByImport) {
53
+ allPackages.push(node);
54
+ // set local to local value
55
+ if (defaultImport.length && isNodeOfType(defaultImport[0], 'ImportDefaultSpecifier') && isNodeOfType(defaultImport[0].local, 'Identifier')) {
56
+ specialFieldsByImport[source].local = defaultImport[0].local.name;
57
+ }
58
+ }
59
+ if ('@atlaskit/form' !== source) {
60
+ return;
61
+ }
62
+ const namedImport = node.specifiers.filter(spec => isNodeOfType(spec, 'ImportSpecifier'));
63
+ if (namedImport.length && namedImport[0].type === 'ImportSpecifier' && namedImport[0].imported.name === 'Field') {
64
+ fieldImport = namedImport[0].local;
65
+ }
66
+ },
67
+ JSXElement(node) {
68
+ if (!isNodeOfType(node, 'JSXElement')) {
69
+ return;
70
+ }
71
+ if (!isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
72
+ return;
73
+ }
74
+ const name = node.openingElement.name.name;
75
+
76
+ // if it's not a field import, skip
77
+ if (!fieldImport || name !== fieldImport.name) {
78
+ return;
79
+ }
80
+
81
+ // If no imports are for the inputs that have special fields, exit early
82
+ if (allPackages.every(n => typeof n.source.value !== 'string' || !Object.keys(specialFieldsByImport).includes(n.source.value))) {
83
+ return;
84
+ }
85
+ const fieldRenderProp = node.children.find(c => isNodeOfType(c, 'JSXExpressionContainer'));
86
+ if (!fieldRenderProp) {
87
+ return;
88
+ }
89
+ // I'm not early exiting because it doesn't work with ts for some reason
90
+ if (isNodeOfType(fieldRenderProp, 'JSXExpressionContainer')) {
91
+ if (!isNodeOfType(fieldRenderProp.expression, 'ArrowFunctionExpression')) {
92
+ return;
93
+ }
94
+ const q = [fieldRenderProp.expression.body];
95
+ let found;
96
+ while (q.length > 0 && !found) {
97
+ const child = q.pop();
98
+ if ('children' in child) {
99
+ for (const innerChild of child.children) {
100
+ q.push(innerChild);
101
+ }
102
+ } else if (isNodeOfType(child, 'BlockStatement') && isNodeOfType(child.body[0], 'ExpressionStatement')) {
103
+ q.push(child.body[0].expression);
104
+ }
105
+ if (!isNodeOfType(child, 'JSXElement') || !isNodeOfType(child.openingElement.name, 'JSXIdentifier')) {
106
+ continue;
107
+ }
108
+ const elementName = child.openingElement.name.name;
109
+ for (const importName in specialFieldsByImport) {
110
+ // if this child is one of the found component names
111
+ // then break out of the while loop and use the found object
112
+ const localName = specialFieldsByImport[importName].local;
113
+ if (localName === elementName) {
114
+ found = specialFieldsByImport[importName].component;
115
+ break;
116
+ }
117
+ }
118
+ }
119
+ if (!found) {
120
+ return;
121
+ }
122
+
123
+ // if checkbox is inside of the field's render prop
124
+ if (found === 'Checkbox' || found === 'Toggle') {
125
+ context.report({
126
+ node: node,
127
+ messageId: found === 'Checkbox' ? 'useCheckboxField' : 'useCheckboxFieldForToggle',
128
+ suggest: [{
129
+ desc: useCheckboxFieldMessage,
130
+ fix(fixer) {
131
+ const fixes = [];
132
+ fixes.push(fixer.insertTextBefore(fieldImport, 'CheckboxField, '));
133
+ fixes.push(fixer.replaceText(node.openingElement.name, 'CheckboxField'));
134
+ node.closingElement && fixes.push(fixer.replaceText(node.closingElement.name, 'CheckboxField'));
135
+ return fixes;
136
+ }
137
+ }]
138
+ });
139
+ } else if (found === 'Range') {
140
+ context.report({
141
+ node: node,
142
+ messageId: 'useRangeField',
143
+ suggest: [{
144
+ desc: useRangeFieldMessage,
145
+ fix(fixer) {
146
+ const fixes = [];
147
+ fixes.push(fixer.insertTextBefore(fieldImport, 'RangeField, '));
148
+ fixes.push(fixer.replaceText(node.openingElement.name, 'RangeField'));
149
+ node.closingElement && fixes.push(fixer.replaceText(node.closingElement.name, 'RangeField'));
150
+ return fixes;
151
+ }
152
+ }]
153
+ });
154
+ }
155
+ }
156
+ }
157
+ };
158
+ }
159
+ });
160
+ export default rule;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::a8f7f6388f0499adc9db0228b7426aee>>
3
+ * @codegen <<SignedSource::8fb6e53ac7d9be7b9252dd64ec022d26>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -52,6 +52,7 @@ export default {
52
52
  '@atlaskit/design-system/no-utility-icons': 'warn',
53
53
  '@atlaskit/design-system/prefer-primitives': 'warn',
54
54
  '@atlaskit/design-system/use-button-group-label': 'warn',
55
+ '@atlaskit/design-system/use-correct-field': 'warn',
55
56
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
56
57
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
57
58
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::aaf4f1ee2f2db236ebed7b77de426181>>
3
+ * @codegen <<SignedSource::b727e6e2b1813b88da0df6ff6083be3c>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -51,6 +51,7 @@ export default {
51
51
  '@atlaskit/design-system/no-utility-icons': 'warn',
52
52
  '@atlaskit/design-system/prefer-primitives': 'warn',
53
53
  '@atlaskit/design-system/use-button-group-label': 'warn',
54
+ '@atlaskit/design-system/use-correct-field': 'warn',
54
55
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
55
56
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
56
57
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::10f372e16c048db9bfb1bc36cf48421c>>
3
+ * @codegen <<SignedSource::af48ffd75d906d008c5701554187b606>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -38,6 +38,7 @@ export default {
38
38
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
39
39
  '@atlaskit/design-system/no-utility-icons': 'warn',
40
40
  '@atlaskit/design-system/use-button-group-label': 'warn',
41
+ '@atlaskit/design-system/use-correct-field': 'warn',
41
42
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
42
43
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
43
44
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::608f46f9cc8653226152a8edc34849d6>>
3
+ * @codegen <<SignedSource::96e803ae8ae873736bab690b2af62bed>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
 
@@ -37,6 +37,7 @@ export default {
37
37
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
38
38
  '@atlaskit/design-system/no-utility-icons': 'warn',
39
39
  '@atlaskit/design-system/use-button-group-label': 'warn',
40
+ '@atlaskit/design-system/use-correct-field': 'warn',
40
41
  '@atlaskit/design-system/use-cx-function-in-xcss': 'error',
41
42
  '@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
42
43
  '@atlaskit/design-system/use-drawer-label': 'warn',
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::c3ee5646fc648d2510a70195a04d7fe9>>
3
+ * @codegen <<SignedSource::3c4282c17de41bbfb755836f00326036>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
5
5
  */
6
6
  import consistentCssPropUsage from './consistent-css-prop-usage';
@@ -48,6 +48,7 @@ import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-li
48
48
  import noUtilityIcons from './no-utility-icons';
49
49
  import preferPrimitives from './prefer-primitives';
50
50
  import useButtonGroupLabel from './use-button-group-label';
51
+ import useCorrectField from './use-correct-field';
51
52
  import useCxFunctionInXcss from './use-cx-function-in-xcss';
52
53
  import useDatetimePickerCalendarButton from './use-datetime-picker-calendar-button';
53
54
  import useDrawerLabel from './use-drawer-label';
@@ -113,6 +114,7 @@ export var rules = {
113
114
  'no-utility-icons': noUtilityIcons,
114
115
  'prefer-primitives': preferPrimitives,
115
116
  'use-button-group-label': useButtonGroupLabel,
117
+ 'use-correct-field': useCorrectField,
116
118
  'use-cx-function-in-xcss': useCxFunctionInXcss,
117
119
  'use-datetime-picker-calendar-button': useDatetimePickerCalendarButton,
118
120
  'use-drawer-label': useDrawerLabel,
@@ -4,7 +4,6 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
4
4
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
5
  import { isNodeOfType } from 'eslint-codemod-utils';
6
6
  var specialCases = {
7
- '@atlaskit/icon/utility/cross': '@atlaskit/icon/core/close',
8
7
  '@atlaskit/icon/utility/migration/cross--editor-close': '@atlaskit/icon/core/migration/close--editor-close'
9
8
  };
10
9
  var iconPropsinNewButton = ['icon', 'iconBefore', 'iconAfter'];
@@ -0,0 +1,180 @@
1
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
2
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
4
+ import { isNodeOfType } from 'eslint-codemod-utils';
5
+ import { createLintRule } from '../utils/create-rule';
6
+ var specialFieldsByImport = {
7
+ '@atlaskit/checkbox': {
8
+ component: 'Checkbox',
9
+ field: 'CheckboxField',
10
+ local: undefined
11
+ },
12
+ '@atlaskit/range': {
13
+ component: 'Range',
14
+ field: 'RangeField',
15
+ local: undefined
16
+ },
17
+ '@atlaskit/toggle': {
18
+ component: 'Toggle',
19
+ field: 'CheckboxField',
20
+ local: undefined
21
+ }
22
+ };
23
+ export var useCheckboxFieldMessage = 'Convert Field to CheckboxField';
24
+ export var useRangeFieldMessage = 'Convert Field to RangeField';
25
+ var rule = createLintRule({
26
+ meta: {
27
+ name: 'use-correct-field',
28
+ type: 'suggestion',
29
+ fixable: 'code',
30
+ hasSuggestions: true,
31
+ docs: {
32
+ description: 'Ensure makers use appropriate field component for their respective form elements.',
33
+ recommended: true,
34
+ severity: 'warn'
35
+ },
36
+ messages: {
37
+ useCheckboxField: 'Checkbox components should use the `CheckboxField` component',
38
+ useRangeField: 'Range components should use the `RangeField` component',
39
+ useCheckboxFieldForToggle: 'Toggle components should use the `CheckboxField` component'
40
+ }
41
+ },
42
+ create: function create(context) {
43
+ var fieldImport;
44
+ var allPackages = [];
45
+ return {
46
+ ImportDeclaration: function ImportDeclaration(node) {
47
+ var source = node.source.value;
48
+ if (typeof source !== 'string') {
49
+ return;
50
+ }
51
+ if (!node.specifiers.length) {
52
+ return;
53
+ }
54
+ var defaultImport = node.specifiers.filter(function (spec) {
55
+ return isNodeOfType(spec, 'ImportDefaultSpecifier');
56
+ });
57
+ if (source in specialFieldsByImport) {
58
+ allPackages.push(node);
59
+ // set local to local value
60
+ if (defaultImport.length && isNodeOfType(defaultImport[0], 'ImportDefaultSpecifier') && isNodeOfType(defaultImport[0].local, 'Identifier')) {
61
+ specialFieldsByImport[source].local = defaultImport[0].local.name;
62
+ }
63
+ }
64
+ if ('@atlaskit/form' !== source) {
65
+ return;
66
+ }
67
+ var namedImport = node.specifiers.filter(function (spec) {
68
+ return isNodeOfType(spec, 'ImportSpecifier');
69
+ });
70
+ if (namedImport.length && namedImport[0].type === 'ImportSpecifier' && namedImport[0].imported.name === 'Field') {
71
+ fieldImport = namedImport[0].local;
72
+ }
73
+ },
74
+ JSXElement: function JSXElement(node) {
75
+ if (!isNodeOfType(node, 'JSXElement')) {
76
+ return;
77
+ }
78
+ if (!isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
79
+ return;
80
+ }
81
+ var name = node.openingElement.name.name;
82
+
83
+ // if it's not a field import, skip
84
+ if (!fieldImport || name !== fieldImport.name) {
85
+ return;
86
+ }
87
+
88
+ // If no imports are for the inputs that have special fields, exit early
89
+ if (allPackages.every(function (n) {
90
+ return typeof n.source.value !== 'string' || !Object.keys(specialFieldsByImport).includes(n.source.value);
91
+ })) {
92
+ return;
93
+ }
94
+ var fieldRenderProp = node.children.find(function (c) {
95
+ return isNodeOfType(c, 'JSXExpressionContainer');
96
+ });
97
+ if (!fieldRenderProp) {
98
+ return;
99
+ }
100
+ // I'm not early exiting because it doesn't work with ts for some reason
101
+ if (isNodeOfType(fieldRenderProp, 'JSXExpressionContainer')) {
102
+ if (!isNodeOfType(fieldRenderProp.expression, 'ArrowFunctionExpression')) {
103
+ return;
104
+ }
105
+ var q = [fieldRenderProp.expression.body];
106
+ var found;
107
+ while (q.length > 0 && !found) {
108
+ var child = q.pop();
109
+ if ('children' in child) {
110
+ var _iterator = _createForOfIteratorHelper(child.children),
111
+ _step;
112
+ try {
113
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
114
+ var innerChild = _step.value;
115
+ q.push(innerChild);
116
+ }
117
+ } catch (err) {
118
+ _iterator.e(err);
119
+ } finally {
120
+ _iterator.f();
121
+ }
122
+ } else if (isNodeOfType(child, 'BlockStatement') && isNodeOfType(child.body[0], 'ExpressionStatement')) {
123
+ q.push(child.body[0].expression);
124
+ }
125
+ if (!isNodeOfType(child, 'JSXElement') || !isNodeOfType(child.openingElement.name, 'JSXIdentifier')) {
126
+ continue;
127
+ }
128
+ var elementName = child.openingElement.name.name;
129
+ for (var importName in specialFieldsByImport) {
130
+ // if this child is one of the found component names
131
+ // then break out of the while loop and use the found object
132
+ var localName = specialFieldsByImport[importName].local;
133
+ if (localName === elementName) {
134
+ found = specialFieldsByImport[importName].component;
135
+ break;
136
+ }
137
+ }
138
+ }
139
+ if (!found) {
140
+ return;
141
+ }
142
+
143
+ // if checkbox is inside of the field's render prop
144
+ if (found === 'Checkbox' || found === 'Toggle') {
145
+ context.report({
146
+ node: node,
147
+ messageId: found === 'Checkbox' ? 'useCheckboxField' : 'useCheckboxFieldForToggle',
148
+ suggest: [{
149
+ desc: useCheckboxFieldMessage,
150
+ fix: function fix(fixer) {
151
+ var fixes = [];
152
+ fixes.push(fixer.insertTextBefore(fieldImport, 'CheckboxField, '));
153
+ fixes.push(fixer.replaceText(node.openingElement.name, 'CheckboxField'));
154
+ node.closingElement && fixes.push(fixer.replaceText(node.closingElement.name, 'CheckboxField'));
155
+ return fixes;
156
+ }
157
+ }]
158
+ });
159
+ } else if (found === 'Range') {
160
+ context.report({
161
+ node: node,
162
+ messageId: 'useRangeField',
163
+ suggest: [{
164
+ desc: useRangeFieldMessage,
165
+ fix: function fix(fixer) {
166
+ var fixes = [];
167
+ fixes.push(fixer.insertTextBefore(fieldImport, 'RangeField, '));
168
+ fixes.push(fixer.replaceText(node.openingElement.name, 'RangeField'));
169
+ node.closingElement && fixes.push(fixer.replaceText(node.closingElement.name, 'RangeField'));
170
+ return fixes;
171
+ }
172
+ }]
173
+ });
174
+ }
175
+ }
176
+ }
177
+ };
178
+ }
179
+ });
180
+ export default rule;
@@ -60,6 +60,7 @@ export declare const plugin: {
60
60
  'no-utility-icons': import("eslint").Rule.RuleModule;
61
61
  'prefer-primitives': import("eslint").Rule.RuleModule;
62
62
  'use-button-group-label': import("eslint").Rule.RuleModule;
63
+ 'use-correct-field': import("eslint").Rule.RuleModule;
63
64
  'use-cx-function-in-xcss': import("eslint").Rule.RuleModule;
64
65
  'use-datetime-picker-calendar-button': import("eslint").Rule.RuleModule;
65
66
  'use-drawer-label': import("eslint").Rule.RuleModule;
@@ -128,6 +129,7 @@ export declare const plugin: {
128
129
  '@atlaskit/design-system/no-utility-icons': "warn";
129
130
  '@atlaskit/design-system/prefer-primitives': "warn";
130
131
  '@atlaskit/design-system/use-button-group-label': "warn";
132
+ '@atlaskit/design-system/use-correct-field': "warn";
131
133
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
132
134
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
133
135
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -198,6 +200,7 @@ export declare const plugin: {
198
200
  '@atlaskit/design-system/no-utility-icons': "warn";
199
201
  '@atlaskit/design-system/prefer-primitives': "warn";
200
202
  '@atlaskit/design-system/use-button-group-label': "warn";
203
+ '@atlaskit/design-system/use-correct-field': "warn";
201
204
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
202
205
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
203
206
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -252,6 +255,7 @@ export declare const plugin: {
252
255
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
253
256
  '@atlaskit/design-system/no-utility-icons': "warn";
254
257
  '@atlaskit/design-system/use-button-group-label': "warn";
258
+ '@atlaskit/design-system/use-correct-field': "warn";
255
259
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
256
260
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
257
261
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -303,6 +307,7 @@ export declare const plugin: {
303
307
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
304
308
  '@atlaskit/design-system/no-utility-icons': "warn";
305
309
  '@atlaskit/design-system/use-button-group-label': "warn";
310
+ '@atlaskit/design-system/use-correct-field': "warn";
306
311
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
307
312
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
308
313
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -369,6 +374,7 @@ declare const configs: {
369
374
  '@atlaskit/design-system/no-utility-icons': "warn";
370
375
  '@atlaskit/design-system/prefer-primitives': "warn";
371
376
  '@atlaskit/design-system/use-button-group-label': "warn";
377
+ '@atlaskit/design-system/use-correct-field': "warn";
372
378
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
373
379
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
374
380
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -439,6 +445,7 @@ declare const configs: {
439
445
  '@atlaskit/design-system/no-utility-icons': "warn";
440
446
  '@atlaskit/design-system/prefer-primitives': "warn";
441
447
  '@atlaskit/design-system/use-button-group-label': "warn";
448
+ '@atlaskit/design-system/use-correct-field': "warn";
442
449
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
443
450
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
444
451
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -493,6 +500,7 @@ declare const configs: {
493
500
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
494
501
  '@atlaskit/design-system/no-utility-icons': "warn";
495
502
  '@atlaskit/design-system/use-button-group-label': "warn";
503
+ '@atlaskit/design-system/use-correct-field': "warn";
496
504
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
497
505
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
498
506
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -544,6 +552,7 @@ declare const configs: {
544
552
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
545
553
  '@atlaskit/design-system/no-utility-icons': "warn";
546
554
  '@atlaskit/design-system/use-button-group-label': "warn";
555
+ '@atlaskit/design-system/use-correct-field': "warn";
547
556
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
548
557
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
549
558
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -45,6 +45,7 @@ declare const _default: {
45
45
  '@atlaskit/design-system/no-utility-icons': "warn";
46
46
  '@atlaskit/design-system/prefer-primitives': "warn";
47
47
  '@atlaskit/design-system/use-button-group-label': "warn";
48
+ '@atlaskit/design-system/use-correct-field': "warn";
48
49
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
49
50
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
50
51
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -45,6 +45,7 @@ declare const _default: {
45
45
  '@atlaskit/design-system/no-utility-icons': "warn";
46
46
  '@atlaskit/design-system/prefer-primitives': "warn";
47
47
  '@atlaskit/design-system/use-button-group-label': "warn";
48
+ '@atlaskit/design-system/use-correct-field': "warn";
48
49
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
49
50
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
50
51
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -31,6 +31,7 @@ declare const _default: {
31
31
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
32
32
  '@atlaskit/design-system/no-utility-icons': "warn";
33
33
  '@atlaskit/design-system/use-button-group-label': "warn";
34
+ '@atlaskit/design-system/use-correct-field': "warn";
34
35
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
35
36
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
36
37
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -31,6 +31,7 @@ declare const _default: {
31
31
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
32
32
  '@atlaskit/design-system/no-utility-icons': "warn";
33
33
  '@atlaskit/design-system/use-button-group-label': "warn";
34
+ '@atlaskit/design-system/use-correct-field': "warn";
34
35
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
35
36
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
36
37
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -44,6 +44,7 @@ export declare const rules: {
44
44
  'no-utility-icons': import("eslint").Rule.RuleModule;
45
45
  'prefer-primitives': import("eslint").Rule.RuleModule;
46
46
  'use-button-group-label': import("eslint").Rule.RuleModule;
47
+ 'use-correct-field': import("eslint").Rule.RuleModule;
47
48
  'use-cx-function-in-xcss': import("eslint").Rule.RuleModule;
48
49
  'use-datetime-picker-calendar-button': import("eslint").Rule.RuleModule;
49
50
  'use-drawer-label': import("eslint").Rule.RuleModule;
@@ -0,0 +1,5 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const useCheckboxFieldMessage = "Convert Field to CheckboxField";
3
+ export declare const useRangeFieldMessage = "Convert Field to RangeField";
4
+ declare const rule: Rule.RuleModule;
5
+ export default rule;
@@ -60,6 +60,7 @@ export declare const plugin: {
60
60
  'no-utility-icons': import("eslint").Rule.RuleModule;
61
61
  'prefer-primitives': import("eslint").Rule.RuleModule;
62
62
  'use-button-group-label': import("eslint").Rule.RuleModule;
63
+ 'use-correct-field': import("eslint").Rule.RuleModule;
63
64
  'use-cx-function-in-xcss': import("eslint").Rule.RuleModule;
64
65
  'use-datetime-picker-calendar-button': import("eslint").Rule.RuleModule;
65
66
  'use-drawer-label': import("eslint").Rule.RuleModule;
@@ -131,6 +132,7 @@ export declare const plugin: {
131
132
  '@atlaskit/design-system/no-utility-icons': "warn";
132
133
  '@atlaskit/design-system/prefer-primitives': "warn";
133
134
  '@atlaskit/design-system/use-button-group-label': "warn";
135
+ '@atlaskit/design-system/use-correct-field': "warn";
134
136
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
135
137
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
136
138
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -204,6 +206,7 @@ export declare const plugin: {
204
206
  '@atlaskit/design-system/no-utility-icons': "warn";
205
207
  '@atlaskit/design-system/prefer-primitives': "warn";
206
208
  '@atlaskit/design-system/use-button-group-label': "warn";
209
+ '@atlaskit/design-system/use-correct-field': "warn";
207
210
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
208
211
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
209
212
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -261,6 +264,7 @@ export declare const plugin: {
261
264
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
262
265
  '@atlaskit/design-system/no-utility-icons': "warn";
263
266
  '@atlaskit/design-system/use-button-group-label': "warn";
267
+ '@atlaskit/design-system/use-correct-field': "warn";
264
268
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
265
269
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
266
270
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -315,6 +319,7 @@ export declare const plugin: {
315
319
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
316
320
  '@atlaskit/design-system/no-utility-icons': "warn";
317
321
  '@atlaskit/design-system/use-button-group-label': "warn";
322
+ '@atlaskit/design-system/use-correct-field': "warn";
318
323
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
319
324
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
320
325
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -384,6 +389,7 @@ declare const configs: {
384
389
  '@atlaskit/design-system/no-utility-icons': "warn";
385
390
  '@atlaskit/design-system/prefer-primitives': "warn";
386
391
  '@atlaskit/design-system/use-button-group-label': "warn";
392
+ '@atlaskit/design-system/use-correct-field': "warn";
387
393
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
388
394
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
389
395
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -457,6 +463,7 @@ declare const configs: {
457
463
  '@atlaskit/design-system/no-utility-icons': "warn";
458
464
  '@atlaskit/design-system/prefer-primitives': "warn";
459
465
  '@atlaskit/design-system/use-button-group-label': "warn";
466
+ '@atlaskit/design-system/use-correct-field': "warn";
460
467
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
461
468
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
462
469
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -514,6 +521,7 @@ declare const configs: {
514
521
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
515
522
  '@atlaskit/design-system/no-utility-icons': "warn";
516
523
  '@atlaskit/design-system/use-button-group-label': "warn";
524
+ '@atlaskit/design-system/use-correct-field': "warn";
517
525
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
518
526
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
519
527
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -568,6 +576,7 @@ declare const configs: {
568
576
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
569
577
  '@atlaskit/design-system/no-utility-icons': "warn";
570
578
  '@atlaskit/design-system/use-button-group-label': "warn";
579
+ '@atlaskit/design-system/use-correct-field': "warn";
571
580
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
572
581
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
573
582
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -48,6 +48,7 @@ declare const _default: {
48
48
  '@atlaskit/design-system/no-utility-icons': "warn";
49
49
  '@atlaskit/design-system/prefer-primitives': "warn";
50
50
  '@atlaskit/design-system/use-button-group-label': "warn";
51
+ '@atlaskit/design-system/use-correct-field': "warn";
51
52
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
52
53
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
53
54
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -48,6 +48,7 @@ declare const _default: {
48
48
  '@atlaskit/design-system/no-utility-icons': "warn";
49
49
  '@atlaskit/design-system/prefer-primitives': "warn";
50
50
  '@atlaskit/design-system/use-button-group-label': "warn";
51
+ '@atlaskit/design-system/use-correct-field': "warn";
51
52
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
52
53
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
53
54
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -34,6 +34,7 @@ declare const _default: {
34
34
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
35
35
  '@atlaskit/design-system/no-utility-icons': "warn";
36
36
  '@atlaskit/design-system/use-button-group-label': "warn";
37
+ '@atlaskit/design-system/use-correct-field': "warn";
37
38
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
38
39
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
39
40
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -34,6 +34,7 @@ declare const _default: {
34
34
  '@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': "error";
35
35
  '@atlaskit/design-system/no-utility-icons': "warn";
36
36
  '@atlaskit/design-system/use-button-group-label': "warn";
37
+ '@atlaskit/design-system/use-correct-field': "warn";
37
38
  '@atlaskit/design-system/use-cx-function-in-xcss': "error";
38
39
  '@atlaskit/design-system/use-datetime-picker-calendar-button': "warn";
39
40
  '@atlaskit/design-system/use-drawer-label': "warn";
@@ -44,6 +44,7 @@ export declare const rules: {
44
44
  'no-utility-icons': import("eslint").Rule.RuleModule;
45
45
  'prefer-primitives': import("eslint").Rule.RuleModule;
46
46
  'use-button-group-label': import("eslint").Rule.RuleModule;
47
+ 'use-correct-field': import("eslint").Rule.RuleModule;
47
48
  'use-cx-function-in-xcss': import("eslint").Rule.RuleModule;
48
49
  'use-datetime-picker-calendar-button': import("eslint").Rule.RuleModule;
49
50
  'use-drawer-label': import("eslint").Rule.RuleModule;
@@ -0,0 +1,5 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const useCheckboxFieldMessage = "Convert Field to CheckboxField";
3
+ export declare const useRangeFieldMessage = "Convert Field to RangeField";
4
+ declare const rule: Rule.RuleModule;
5
+ export default rule;
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": "13.17.3",
4
+ "version": "13.18.1",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": {
@@ -13,7 +13,6 @@
13
13
  "name": "ESLint plugin",
14
14
  "category": "Tooling"
15
15
  },
16
- "runReact18": true,
17
16
  "toolingLabels": [
18
17
  "linting"
19
18
  ]
@@ -44,9 +43,9 @@
44
43
  },
45
44
  "dependencies": {
46
45
  "@atlaskit/eslint-utils": "^2.0.0",
47
- "@atlaskit/icon": "^27.0.0",
48
- "@atlaskit/icon-lab": "^5.0.0",
49
- "@atlaskit/tokens": "^5.2.0",
46
+ "@atlaskit/icon": "^27.5.0",
47
+ "@atlaskit/icon-lab": "^5.2.0",
48
+ "@atlaskit/tokens": "^5.6.0",
50
49
  "@babel/runtime": "^7.0.0",
51
50
  "@typescript-eslint/utils": "^7.1.0",
52
51
  "ajv": "^6.12.6",
@@ -59,8 +58,8 @@
59
58
  },
60
59
  "devDependencies": {
61
60
  "@af/formatting": "workspace:^",
62
- "@atlaskit/ds-lib": "^4.0.0",
63
- "@atlaskit/theme": "^18.0.0",
61
+ "@atlaskit/ds-lib": "^4.1.0",
62
+ "@atlaskit/theme": "^19.0.0",
64
63
  "@atlassian/codegen": "^0.1.0",
65
64
  "@atlassian/eslint-utils": "^0.5.0",
66
65
  "@atlassian/ts-loader": "^0.1.0",