@atlaskit/eslint-plugin-design-system 10.24.1 → 10.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 +10 -0
- package/README.md +1 -0
- package/dist/cjs/ast-nodes/jsx-attribute.js +8 -0
- package/dist/cjs/presets/all-flat.codegen.js +2 -1
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended-flat.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/use-datetime-picker-calendar-button/index.js +187 -0
- package/dist/es2019/ast-nodes/jsx-attribute.js +8 -0
- package/dist/es2019/presets/all-flat.codegen.js +2 -1
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended-flat.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/use-datetime-picker-calendar-button/index.js +173 -0
- package/dist/esm/ast-nodes/jsx-attribute.js +8 -0
- package/dist/esm/presets/all-flat.codegen.js +2 -1
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended-flat.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/use-datetime-picker-calendar-button/index.js +181 -0
- package/dist/types/ast-nodes/jsx-attribute.d.ts +3 -0
- package/dist/types/index.codegen.d.ts +11 -0
- package/dist/types/presets/all-flat.codegen.d.ts +2 -1
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended-flat.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/use-datetime-picker-calendar-button/index.d.ts +7 -0
- package/dist/types-ts4.5/ast-nodes/jsx-attribute.d.ts +3 -0
- package/dist/types-ts4.5/index.codegen.d.ts +11 -0
- package/dist/types-ts4.5/presets/all-flat.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended-flat.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/use-datetime-picker-calendar-button/index.d.ts +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-design-system
|
|
2
2
|
|
|
3
|
+
## 10.25.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#165487](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/165487)
|
|
8
|
+
[`0e99fc2e1f211`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0e99fc2e1f211) -
|
|
9
|
+
Add new rule for `@atlaskit/datetime-picker`. Ensures that the calendar button is used when
|
|
10
|
+
possible to ensure the picker is accessible. Part of AUTOMAT campaign to migrate all AFM instances
|
|
11
|
+
of date picker and date time picker to use new `shouldShowCalendarButton` prop.
|
|
12
|
+
|
|
3
13
|
## 10.24.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -80,6 +80,7 @@ module.exports = {
|
|
|
80
80
|
| <a href="./src/rules/no-unsupported-drag-and-drop-libraries/README.md">no-unsupported-drag-and-drop-libraries</a> | Disallow importing unsupported drag and drop modules. | Yes | | |
|
|
81
81
|
| <a href="./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. | | | |
|
|
82
82
|
| <a href="./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 |
|
|
83
|
+
| <a href="./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 |
|
|
83
84
|
| <a href="./src/rules/use-drawer-label/README.md">use-drawer-label</a> | Encourages to provide accessible name for Atlassian Design System Drawer component. | Yes | | Yes |
|
|
84
85
|
| <a href="./src/rules/use-heading/README.md">use-heading</a> | Encourage the usage of heading components. | | Yes | Yes |
|
|
85
86
|
| <a href="./src/rules/use-heading-level-in-spotlight-card/README.md">use-heading-level-in-spotlight-card</a> | Inform developers of eventual requirement of `headingLevel` prop in `SpotlightCard` component. The heading level should be the appropriate level according to the surrounding context. | Yes | Yes | |
|
|
@@ -52,6 +52,14 @@ var HelperJSXAttribute = exports.JSXAttribute = {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// handle `css={true}`
|
|
56
|
+
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'JSXExpressionContainer') && (0, _eslintCodemodUtils.isNodeOfType)(node.value.expression, 'Literal')) {
|
|
57
|
+
return {
|
|
58
|
+
type: 'ExpressionStatement Literal',
|
|
59
|
+
value: node.value.expression.value
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
// handle `css='myStyles'`
|
|
56
64
|
if ((0, _eslintCodemodUtils.isNodeOfType)(node.value, 'Literal') && node.value.value) {
|
|
57
65
|
var _node$value$value;
|
|
@@ -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::
|
|
9
|
+
* @codegen <<SignedSource::72c978e91d268fe1463898bd263385bc>>
|
|
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/prefer-primitives': 'warn',
|
|
45
45
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
46
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
46
47
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
47
48
|
'@atlaskit/design-system/use-heading': 'warn',
|
|
48
49
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': '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::
|
|
9
|
+
* @codegen <<SignedSource::5bfdac53d9eb0cc8f885ce996861719e>>
|
|
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/prefer-primitives': 'warn',
|
|
44
44
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
45
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
45
46
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
46
47
|
'@atlaskit/design-system/use-heading': 'warn',
|
|
47
48
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': '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::
|
|
9
|
+
* @codegen <<SignedSource::2c1f5cd2494143a83d590243d7ebf539>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -32,6 +32,7 @@ var _default = exports.default = {
|
|
|
32
32
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
33
33
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
34
34
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
35
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
35
36
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
36
37
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
37
38
|
'@atlaskit/design-system/use-href-in-link-item': '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::
|
|
9
|
+
* @codegen <<SignedSource::9aeb2fd0b5bde21f6ef61b407d0d32ab>>
|
|
10
10
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
11
11
|
*/
|
|
12
12
|
var _default = exports.default = {
|
|
@@ -31,6 +31,7 @@ var _default = exports.default = {
|
|
|
31
31
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
32
32
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
33
33
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
34
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
34
35
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
35
36
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
36
37
|
'@atlaskit/design-system/use-href-in-link-item': 'warn',
|
|
@@ -36,6 +36,7 @@ var _noUnsafeStyleOverrides = _interopRequireDefault(require("./no-unsafe-style-
|
|
|
36
36
|
var _noUnsupportedDragAndDropLibraries = _interopRequireDefault(require("./no-unsupported-drag-and-drop-libraries"));
|
|
37
37
|
var _preferPrimitives = _interopRequireDefault(require("./prefer-primitives"));
|
|
38
38
|
var _useButtonGroupLabel = _interopRequireDefault(require("./use-button-group-label"));
|
|
39
|
+
var _useDatetimePickerCalendarButton = _interopRequireDefault(require("./use-datetime-picker-calendar-button"));
|
|
39
40
|
var _useDrawerLabel = _interopRequireDefault(require("./use-drawer-label"));
|
|
40
41
|
var _useHeading = _interopRequireDefault(require("./use-heading"));
|
|
41
42
|
var _useHeadingLevelInSpotlightCard = _interopRequireDefault(require("./use-heading-level-in-spotlight-card"));
|
|
@@ -53,7 +54,7 @@ var _useTokensTypography = _interopRequireDefault(require("./use-tokens-typograp
|
|
|
53
54
|
var _useVisuallyHidden = _interopRequireDefault(require("./use-visually-hidden"));
|
|
54
55
|
/**
|
|
55
56
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
56
|
-
* @codegen <<SignedSource::
|
|
57
|
+
* @codegen <<SignedSource::50c700a7a1e85949b0e5136a8c576c72>>
|
|
57
58
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
58
59
|
*/
|
|
59
60
|
|
|
@@ -89,6 +90,7 @@ var rules = exports.rules = {
|
|
|
89
90
|
'no-unsupported-drag-and-drop-libraries': _noUnsupportedDragAndDropLibraries.default,
|
|
90
91
|
'prefer-primitives': _preferPrimitives.default,
|
|
91
92
|
'use-button-group-label': _useButtonGroupLabel.default,
|
|
93
|
+
'use-datetime-picker-calendar-button': _useDatetimePickerCalendarButton.default,
|
|
92
94
|
'use-drawer-label': _useDrawerLabel.default,
|
|
93
95
|
'use-heading': _useHeading.default,
|
|
94
96
|
'use-heading-level-in-spotlight-card': _useHeadingLevelInSpotlightCard.default,
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setCalendarButtonPropertyToTrue = exports.setCalendarButtonPropToTrue = exports.default = exports.addCalendarButtonProperty = exports.addCalendarButtonProp = void 0;
|
|
7
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
|
+
var _jsxAttribute = require("../../ast-nodes/jsx-attribute");
|
|
9
|
+
var _jsxElement = require("../../ast-nodes/jsx-element");
|
|
10
|
+
var _createRule = require("../utils/create-rule");
|
|
11
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
12
|
+
|
|
13
|
+
var DATE_PICKER = 'DatePicker';
|
|
14
|
+
var DATETIME_PICKER = 'DateTimePicker';
|
|
15
|
+
var PROP_NAME = 'shouldShowCalendarButton';
|
|
16
|
+
|
|
17
|
+
// Lint rule message
|
|
18
|
+
var message = '`shouldShowCalendarButton` should be set to `true` to make date picker accessible.';
|
|
19
|
+
|
|
20
|
+
// Fix messages
|
|
21
|
+
var addCalendarButtonProp = exports.addCalendarButtonProp = 'Add `shouldShowCalendarButton` prop.';
|
|
22
|
+
var setCalendarButtonPropToTrue = exports.setCalendarButtonPropToTrue = 'Set `shouldShowCalendarButton` prop to `true`.';
|
|
23
|
+
var addCalendarButtonProperty = exports.addCalendarButtonProperty = 'Add `shouldShowCalendarButton: true` to `datePickerProps`.';
|
|
24
|
+
var setCalendarButtonPropertyToTrue = exports.setCalendarButtonPropertyToTrue = 'Set `shouldShowCalendarButton` property in `datePickerProps` to `true`.';
|
|
25
|
+
var datePickerJSXElement = function datePickerJSXElement(node, context) {
|
|
26
|
+
var prop = _jsxElement.JSXElementHelper.getAttributeByName(node, PROP_NAME);
|
|
27
|
+
|
|
28
|
+
// If the prop exists
|
|
29
|
+
if (prop) {
|
|
30
|
+
var attrValue = _jsxAttribute.JSXAttribute.getValue(prop);
|
|
31
|
+
// If the value is a boolean with value `false`
|
|
32
|
+
if ((attrValue === null || attrValue === void 0 ? void 0 : attrValue.type) === 'ExpressionStatement Literal' && (attrValue === null || attrValue === void 0 ? void 0 : attrValue.value) === false) {
|
|
33
|
+
return context.report({
|
|
34
|
+
node: prop,
|
|
35
|
+
messageId: 'datePickerCalendarButtonShouldBeShown',
|
|
36
|
+
suggest: [{
|
|
37
|
+
desc: setCalendarButtonPropToTrue,
|
|
38
|
+
fix: function fix(fixer) {
|
|
39
|
+
return [fixer.replaceText(prop, PROP_NAME)];
|
|
40
|
+
}
|
|
41
|
+
}]
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// If the prop does not exist
|
|
45
|
+
} else {
|
|
46
|
+
return context.report({
|
|
47
|
+
node: node.openingElement,
|
|
48
|
+
messageId: 'datePickerMissingCalendarButtonProp',
|
|
49
|
+
suggest: [{
|
|
50
|
+
desc: addCalendarButtonProp,
|
|
51
|
+
fix: function fix(fixer) {
|
|
52
|
+
return [fixer.insertTextAfter(node.openingElement.name, " ".concat(PROP_NAME))];
|
|
53
|
+
}
|
|
54
|
+
}]
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var dateTimePickerJSXElement = function dateTimePickerJSXElement(node, context) {
|
|
59
|
+
var _datePickerProp$value, _expression$propertie;
|
|
60
|
+
var datePickerProp = _jsxElement.JSXElementHelper.getAttributeByName(node, 'datePickerProps');
|
|
61
|
+
|
|
62
|
+
// If the `datePickerProps` prop does not exist or is not an expression
|
|
63
|
+
// container (the latter being essentially unprecedented, against type
|
|
64
|
+
// guidelines, and useless)
|
|
65
|
+
if (!datePickerProp || ((_datePickerProp$value = datePickerProp.value) === null || _datePickerProp$value === void 0 ? void 0 : _datePickerProp$value.type) !== 'JSXExpressionContainer') {
|
|
66
|
+
return context.report({
|
|
67
|
+
node: node.openingElement,
|
|
68
|
+
messageId: 'dateTimePickerMissingCalendarButtonProp',
|
|
69
|
+
suggest: [{
|
|
70
|
+
desc: addCalendarButtonProperty,
|
|
71
|
+
fix: function fix(fixer) {
|
|
72
|
+
return [fixer.insertTextAfter(node.openingElement.name, " datePickerProps={{ ".concat(PROP_NAME, ": true }}"))];
|
|
73
|
+
}
|
|
74
|
+
}]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Had to cast all these things because ESLint can't hang here. The
|
|
79
|
+
// types are just abjectly wrong from what I can log.
|
|
80
|
+
var expression = datePickerProp.value.expression;
|
|
81
|
+
// If it is not an analyzable expression, like a variable or something, skip
|
|
82
|
+
// it.
|
|
83
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(datePickerProp.value.expression, 'ObjectExpression')) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
var prop = expression === null || expression === void 0 || (_expression$propertie = expression.properties) === null || _expression$propertie === void 0 ? void 0 : _expression$propertie.find(function (property) {
|
|
87
|
+
return property.type === 'Property' && property.key.name === PROP_NAME;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// If the `shouldShowCalendarButton` prop does not exist in `datePickerProps`
|
|
91
|
+
if (!prop) {
|
|
92
|
+
return context.report({
|
|
93
|
+
node: datePickerProp,
|
|
94
|
+
messageId: 'dateTimePickerMissingCalendarButtonProp',
|
|
95
|
+
suggest: [{
|
|
96
|
+
desc: addCalendarButtonProperty,
|
|
97
|
+
fix: function fix(fixer) {
|
|
98
|
+
// If it has existing properties
|
|
99
|
+
if (expression.properties.length > 0) {
|
|
100
|
+
// Needs following comma to not disrupt existing properties inside `datePickerProps`
|
|
101
|
+
return [fixer.insertTextBefore(expression.properties[0], "".concat(PROP_NAME, ": true,"))];
|
|
102
|
+
// Else it's an empty object
|
|
103
|
+
} else {
|
|
104
|
+
return [fixer.replaceText(expression, "{ ".concat(PROP_NAME, ": true }"))];
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}]
|
|
108
|
+
});
|
|
109
|
+
// If the `shouldShowCalendarButton` property exists and it's value is `false`
|
|
110
|
+
} else if ((0, _eslintCodemodUtils.isNodeOfType)(prop.value, 'Literal') && prop.value.value !== true) {
|
|
111
|
+
return context.report({
|
|
112
|
+
node: datePickerProp,
|
|
113
|
+
messageId: 'dateTimePickerCalendarButtonShouldBeShown',
|
|
114
|
+
suggest: [{
|
|
115
|
+
desc: setCalendarButtonPropertyToTrue,
|
|
116
|
+
// Needs following comma to not disrupt existing properties inside `datePickerProps`
|
|
117
|
+
fix: function fix(fixer) {
|
|
118
|
+
return [fixer.replaceText(prop, "".concat(PROP_NAME, ": true,"))];
|
|
119
|
+
}
|
|
120
|
+
}]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
var rule = (0, _createRule.createLintRule)({
|
|
125
|
+
meta: {
|
|
126
|
+
name: 'use-datetime-picker-calendar-button',
|
|
127
|
+
type: 'suggestion',
|
|
128
|
+
fixable: 'code',
|
|
129
|
+
hasSuggestions: true,
|
|
130
|
+
docs: {
|
|
131
|
+
description: "Encourages makers to use calendar button in Atlassian Design System's date picker and datetime picker components.",
|
|
132
|
+
recommended: true,
|
|
133
|
+
severity: 'warn'
|
|
134
|
+
},
|
|
135
|
+
messages: {
|
|
136
|
+
dateTimePickerMissingCalendarButtonProp: "In `datePickerProps`, ".concat(message),
|
|
137
|
+
datePickerMissingCalendarButtonProp: message,
|
|
138
|
+
dateTimePickerCalendarButtonShouldBeShown: "In `datePickerProps`, ".concat(message),
|
|
139
|
+
datePickerCalendarButtonShouldBeShown: message
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
create: function create(context) {
|
|
143
|
+
// List of component's locally imported names that match
|
|
144
|
+
var contextLocalIdentifier = [];
|
|
145
|
+
var contextImportedIdentifier = [];
|
|
146
|
+
return {
|
|
147
|
+
// Only run rule in files where the package is imported
|
|
148
|
+
ImportDeclaration: function ImportDeclaration(node) {
|
|
149
|
+
var _node$specifiers;
|
|
150
|
+
var datetimePickerIdentifier = (_node$specifiers = node.specifiers) === null || _node$specifiers === void 0 ? void 0 : _node$specifiers.filter(function (spec) {
|
|
151
|
+
if (node.source.value === '@atlaskit/datetime-picker') {
|
|
152
|
+
var _spec$imported;
|
|
153
|
+
return (0, _eslintCodemodUtils.isNodeOfType)(spec, 'ImportSpecifier') && [DATE_PICKER, DATETIME_PICKER].includes((_spec$imported = spec.imported) === null || _spec$imported === void 0 ? void 0 : _spec$imported.name);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
datetimePickerIdentifier.forEach(function (identifier) {
|
|
157
|
+
var imported = identifier.imported,
|
|
158
|
+
local = identifier.local;
|
|
159
|
+
contextLocalIdentifier.push(local.name);
|
|
160
|
+
contextImportedIdentifier.push(imported.name);
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
JSXElement: function JSXElement(node) {
|
|
164
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node, 'JSXElement')) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (!(0, _eslintCodemodUtils.isNodeOfType)(node.openingElement.name, 'JSXIdentifier')) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
var name = node.openingElement.name.name;
|
|
171
|
+
var localIndex = contextLocalIdentifier.indexOf(name);
|
|
172
|
+
|
|
173
|
+
// If this component does not match what we're looking for, quit early
|
|
174
|
+
if (localIndex === -1) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
var importedName = contextImportedIdentifier[localIndex];
|
|
178
|
+
if (importedName === DATE_PICKER) {
|
|
179
|
+
return datePickerJSXElement(node, context);
|
|
180
|
+
} else if (importedName === DATETIME_PICKER) {
|
|
181
|
+
return dateTimePickerJSXElement(node, context);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
var _default = exports.default = rule;
|
|
@@ -46,6 +46,14 @@ const HelperJSXAttribute = {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// handle `css={true}`
|
|
50
|
+
if (isNodeOfType(node.value, 'JSXExpressionContainer') && isNodeOfType(node.value.expression, 'Literal')) {
|
|
51
|
+
return {
|
|
52
|
+
type: 'ExpressionStatement Literal',
|
|
53
|
+
value: node.value.expression.value
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
// handle `css='myStyles'`
|
|
50
58
|
if (isNodeOfType(node.value, 'Literal') && node.value.value) {
|
|
51
59
|
var _node$value$value;
|
|
@@ -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::
|
|
3
|
+
* @codegen <<SignedSource::72c978e91d268fe1463898bd263385bc>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -37,6 +37,7 @@ export default {
|
|
|
37
37
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
38
38
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
39
39
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
40
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
40
41
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
41
42
|
'@atlaskit/design-system/use-heading': 'warn',
|
|
42
43
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': '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::
|
|
3
|
+
* @codegen <<SignedSource::5bfdac53d9eb0cc8f885ce996861719e>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -36,6 +36,7 @@ export default {
|
|
|
36
36
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
37
37
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
38
38
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
39
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
39
40
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
40
41
|
'@atlaskit/design-system/use-heading': 'warn',
|
|
41
42
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': '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::
|
|
3
|
+
* @codegen <<SignedSource::2c1f5cd2494143a83d590243d7ebf539>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -26,6 +26,7 @@ export default {
|
|
|
26
26
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
27
27
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
28
28
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
29
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
29
30
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
30
31
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
31
32
|
'@atlaskit/design-system/use-href-in-link-item': '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::
|
|
3
|
+
* @codegen <<SignedSource::9aeb2fd0b5bde21f6ef61b407d0d32ab>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -25,6 +25,7 @@ export default {
|
|
|
25
25
|
'@atlaskit/design-system/no-unsafe-style-overrides': 'warn',
|
|
26
26
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
27
27
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
28
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
28
29
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
29
30
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|
|
30
31
|
'@atlaskit/design-system/use-href-in-link-item': '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::
|
|
3
|
+
* @codegen <<SignedSource::50c700a7a1e85949b0e5136a8c576c72>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
import consistentCssPropUsage from './consistent-css-prop-usage';
|
|
@@ -34,6 +34,7 @@ import noUnsafeStyleOverrides from './no-unsafe-style-overrides';
|
|
|
34
34
|
import noUnsupportedDragAndDropLibraries from './no-unsupported-drag-and-drop-libraries';
|
|
35
35
|
import preferPrimitives from './prefer-primitives';
|
|
36
36
|
import useButtonGroupLabel from './use-button-group-label';
|
|
37
|
+
import useDatetimePickerCalendarButton from './use-datetime-picker-calendar-button';
|
|
37
38
|
import useDrawerLabel from './use-drawer-label';
|
|
38
39
|
import useHeading from './use-heading';
|
|
39
40
|
import useHeadingLevelInSpotlightCard from './use-heading-level-in-spotlight-card';
|
|
@@ -81,6 +82,7 @@ export const rules = {
|
|
|
81
82
|
'no-unsupported-drag-and-drop-libraries': noUnsupportedDragAndDropLibraries,
|
|
82
83
|
'prefer-primitives': preferPrimitives,
|
|
83
84
|
'use-button-group-label': useButtonGroupLabel,
|
|
85
|
+
'use-datetime-picker-calendar-button': useDatetimePickerCalendarButton,
|
|
84
86
|
'use-drawer-label': useDrawerLabel,
|
|
85
87
|
'use-heading': useHeading,
|
|
86
88
|
'use-heading-level-in-spotlight-card': useHeadingLevelInSpotlightCard,
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
|
|
3
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
4
|
+
import { JSXAttribute } from '../../ast-nodes/jsx-attribute';
|
|
5
|
+
import { JSXElementHelper } from '../../ast-nodes/jsx-element';
|
|
6
|
+
import { createLintRule } from '../utils/create-rule';
|
|
7
|
+
const DATE_PICKER = 'DatePicker';
|
|
8
|
+
const DATETIME_PICKER = 'DateTimePicker';
|
|
9
|
+
const PROP_NAME = 'shouldShowCalendarButton';
|
|
10
|
+
|
|
11
|
+
// Lint rule message
|
|
12
|
+
const message = '`shouldShowCalendarButton` should be set to `true` to make date picker accessible.';
|
|
13
|
+
|
|
14
|
+
// Fix messages
|
|
15
|
+
export const addCalendarButtonProp = 'Add `shouldShowCalendarButton` prop.';
|
|
16
|
+
export const setCalendarButtonPropToTrue = 'Set `shouldShowCalendarButton` prop to `true`.';
|
|
17
|
+
export const addCalendarButtonProperty = 'Add `shouldShowCalendarButton: true` to `datePickerProps`.';
|
|
18
|
+
export const setCalendarButtonPropertyToTrue = 'Set `shouldShowCalendarButton` property in `datePickerProps` to `true`.';
|
|
19
|
+
const datePickerJSXElement = (node, context) => {
|
|
20
|
+
const prop = JSXElementHelper.getAttributeByName(node, PROP_NAME);
|
|
21
|
+
|
|
22
|
+
// If the prop exists
|
|
23
|
+
if (prop) {
|
|
24
|
+
const attrValue = JSXAttribute.getValue(prop);
|
|
25
|
+
// If the value is a boolean with value `false`
|
|
26
|
+
if ((attrValue === null || attrValue === void 0 ? void 0 : attrValue.type) === 'ExpressionStatement Literal' && (attrValue === null || attrValue === void 0 ? void 0 : attrValue.value) === false) {
|
|
27
|
+
return context.report({
|
|
28
|
+
node: prop,
|
|
29
|
+
messageId: 'datePickerCalendarButtonShouldBeShown',
|
|
30
|
+
suggest: [{
|
|
31
|
+
desc: setCalendarButtonPropToTrue,
|
|
32
|
+
fix: fixer => [fixer.replaceText(prop, PROP_NAME)]
|
|
33
|
+
}]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// If the prop does not exist
|
|
37
|
+
} else {
|
|
38
|
+
return context.report({
|
|
39
|
+
node: node.openingElement,
|
|
40
|
+
messageId: 'datePickerMissingCalendarButtonProp',
|
|
41
|
+
suggest: [{
|
|
42
|
+
desc: addCalendarButtonProp,
|
|
43
|
+
fix: fixer => [fixer.insertTextAfter(node.openingElement.name, ` ${PROP_NAME}`)]
|
|
44
|
+
}]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const dateTimePickerJSXElement = (node, context) => {
|
|
49
|
+
var _datePickerProp$value, _expression$propertie;
|
|
50
|
+
const datePickerProp = JSXElementHelper.getAttributeByName(node, 'datePickerProps');
|
|
51
|
+
|
|
52
|
+
// If the `datePickerProps` prop does not exist or is not an expression
|
|
53
|
+
// container (the latter being essentially unprecedented, against type
|
|
54
|
+
// guidelines, and useless)
|
|
55
|
+
if (!datePickerProp || ((_datePickerProp$value = datePickerProp.value) === null || _datePickerProp$value === void 0 ? void 0 : _datePickerProp$value.type) !== 'JSXExpressionContainer') {
|
|
56
|
+
return context.report({
|
|
57
|
+
node: node.openingElement,
|
|
58
|
+
messageId: 'dateTimePickerMissingCalendarButtonProp',
|
|
59
|
+
suggest: [{
|
|
60
|
+
desc: addCalendarButtonProperty,
|
|
61
|
+
fix: fixer => [fixer.insertTextAfter(node.openingElement.name, ` datePickerProps={{ ${PROP_NAME}: true }}`)]
|
|
62
|
+
}]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Had to cast all these things because ESLint can't hang here. The
|
|
67
|
+
// types are just abjectly wrong from what I can log.
|
|
68
|
+
const expression = datePickerProp.value.expression;
|
|
69
|
+
// If it is not an analyzable expression, like a variable or something, skip
|
|
70
|
+
// it.
|
|
71
|
+
if (!isNodeOfType(datePickerProp.value.expression, 'ObjectExpression')) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const prop = expression === null || expression === void 0 ? void 0 : (_expression$propertie = expression.properties) === null || _expression$propertie === void 0 ? void 0 : _expression$propertie.find(property => property.type === 'Property' && property.key.name === PROP_NAME);
|
|
75
|
+
|
|
76
|
+
// If the `shouldShowCalendarButton` prop does not exist in `datePickerProps`
|
|
77
|
+
if (!prop) {
|
|
78
|
+
return context.report({
|
|
79
|
+
node: datePickerProp,
|
|
80
|
+
messageId: 'dateTimePickerMissingCalendarButtonProp',
|
|
81
|
+
suggest: [{
|
|
82
|
+
desc: addCalendarButtonProperty,
|
|
83
|
+
fix: fixer => {
|
|
84
|
+
// If it has existing properties
|
|
85
|
+
if (expression.properties.length > 0) {
|
|
86
|
+
// Needs following comma to not disrupt existing properties inside `datePickerProps`
|
|
87
|
+
return [fixer.insertTextBefore(expression.properties[0], `${PROP_NAME}: true,`)];
|
|
88
|
+
// Else it's an empty object
|
|
89
|
+
} else {
|
|
90
|
+
return [fixer.replaceText(expression, `{ ${PROP_NAME}: true }`)];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}]
|
|
94
|
+
});
|
|
95
|
+
// If the `shouldShowCalendarButton` property exists and it's value is `false`
|
|
96
|
+
} else if (isNodeOfType(prop.value, 'Literal') && prop.value.value !== true) {
|
|
97
|
+
return context.report({
|
|
98
|
+
node: datePickerProp,
|
|
99
|
+
messageId: 'dateTimePickerCalendarButtonShouldBeShown',
|
|
100
|
+
suggest: [{
|
|
101
|
+
desc: setCalendarButtonPropertyToTrue,
|
|
102
|
+
// Needs following comma to not disrupt existing properties inside `datePickerProps`
|
|
103
|
+
fix: fixer => [fixer.replaceText(prop, `${PROP_NAME}: true,`)]
|
|
104
|
+
}]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const rule = createLintRule({
|
|
109
|
+
meta: {
|
|
110
|
+
name: 'use-datetime-picker-calendar-button',
|
|
111
|
+
type: 'suggestion',
|
|
112
|
+
fixable: 'code',
|
|
113
|
+
hasSuggestions: true,
|
|
114
|
+
docs: {
|
|
115
|
+
description: "Encourages makers to use calendar button in Atlassian Design System's date picker and datetime picker components.",
|
|
116
|
+
recommended: true,
|
|
117
|
+
severity: 'warn'
|
|
118
|
+
},
|
|
119
|
+
messages: {
|
|
120
|
+
dateTimePickerMissingCalendarButtonProp: `In \`datePickerProps\`, ${message}`,
|
|
121
|
+
datePickerMissingCalendarButtonProp: message,
|
|
122
|
+
dateTimePickerCalendarButtonShouldBeShown: `In \`datePickerProps\`, ${message}`,
|
|
123
|
+
datePickerCalendarButtonShouldBeShown: message
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
create(context) {
|
|
127
|
+
// List of component's locally imported names that match
|
|
128
|
+
const contextLocalIdentifier = [];
|
|
129
|
+
const contextImportedIdentifier = [];
|
|
130
|
+
return {
|
|
131
|
+
// Only run rule in files where the package is imported
|
|
132
|
+
ImportDeclaration(node) {
|
|
133
|
+
var _node$specifiers;
|
|
134
|
+
const datetimePickerIdentifier = (_node$specifiers = node.specifiers) === null || _node$specifiers === void 0 ? void 0 : _node$specifiers.filter(spec => {
|
|
135
|
+
if (node.source.value === '@atlaskit/datetime-picker') {
|
|
136
|
+
var _spec$imported;
|
|
137
|
+
return isNodeOfType(spec, 'ImportSpecifier') && [DATE_PICKER, DATETIME_PICKER].includes((_spec$imported = spec.imported) === null || _spec$imported === void 0 ? void 0 : _spec$imported.name);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
datetimePickerIdentifier.forEach(identifier => {
|
|
141
|
+
const {
|
|
142
|
+
imported,
|
|
143
|
+
local
|
|
144
|
+
} = identifier;
|
|
145
|
+
contextLocalIdentifier.push(local.name);
|
|
146
|
+
contextImportedIdentifier.push(imported.name);
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
JSXElement(node) {
|
|
150
|
+
if (!isNodeOfType(node, 'JSXElement')) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (!isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const name = node.openingElement.name.name;
|
|
157
|
+
const localIndex = contextLocalIdentifier.indexOf(name);
|
|
158
|
+
|
|
159
|
+
// If this component does not match what we're looking for, quit early
|
|
160
|
+
if (localIndex === -1) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const importedName = contextImportedIdentifier[localIndex];
|
|
164
|
+
if (importedName === DATE_PICKER) {
|
|
165
|
+
return datePickerJSXElement(node, context);
|
|
166
|
+
} else if (importedName === DATETIME_PICKER) {
|
|
167
|
+
return dateTimePickerJSXElement(node, context);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
export default rule;
|
|
@@ -46,6 +46,14 @@ var HelperJSXAttribute = {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
// handle `css={true}`
|
|
50
|
+
if (isNodeOfType(node.value, 'JSXExpressionContainer') && isNodeOfType(node.value.expression, 'Literal')) {
|
|
51
|
+
return {
|
|
52
|
+
type: 'ExpressionStatement Literal',
|
|
53
|
+
value: node.value.expression.value
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
// handle `css='myStyles'`
|
|
50
58
|
if (isNodeOfType(node.value, 'Literal') && node.value.value) {
|
|
51
59
|
var _node$value$value;
|
|
@@ -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::
|
|
3
|
+
* @codegen <<SignedSource::72c978e91d268fe1463898bd263385bc>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-design-system codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
@@ -37,6 +37,7 @@ export default {
|
|
|
37
37
|
'@atlaskit/design-system/no-unsupported-drag-and-drop-libraries': 'error',
|
|
38
38
|
'@atlaskit/design-system/prefer-primitives': 'warn',
|
|
39
39
|
'@atlaskit/design-system/use-button-group-label': 'warn',
|
|
40
|
+
'@atlaskit/design-system/use-datetime-picker-calendar-button': 'warn',
|
|
40
41
|
'@atlaskit/design-system/use-drawer-label': 'warn',
|
|
41
42
|
'@atlaskit/design-system/use-heading': 'warn',
|
|
42
43
|
'@atlaskit/design-system/use-heading-level-in-spotlight-card': 'warn',
|