@atlaskit/eslint-plugin-design-system 10.24.1 → 10.26.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 +23 -0
- package/README.md +2 -1
- 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/no-deprecated-imports/checks.js +201 -0
- package/dist/cjs/rules/no-deprecated-imports/constants.js +8 -0
- package/dist/cjs/rules/no-deprecated-imports/handlers/icon.js +204 -0
- package/dist/cjs/rules/no-deprecated-imports/index.js +25 -118
- package/dist/cjs/rules/use-datetime-picker-calendar-button/index.js +187 -0
- package/dist/cjs/rules/utils/get-deprecated-config.js +9 -1
- 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/no-deprecated-imports/checks.js +175 -0
- package/dist/es2019/rules/no-deprecated-imports/constants.js +2 -0
- package/dist/es2019/rules/no-deprecated-imports/handlers/icon.js +153 -0
- package/dist/es2019/rules/no-deprecated-imports/index.js +23 -103
- package/dist/es2019/rules/use-datetime-picker-calendar-button/index.js +173 -0
- package/dist/es2019/rules/utils/get-deprecated-config.js +12 -1
- 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/no-deprecated-imports/checks.js +195 -0
- package/dist/esm/rules/no-deprecated-imports/constants.js +2 -0
- package/dist/esm/rules/no-deprecated-imports/handlers/icon.js +197 -0
- package/dist/esm/rules/no-deprecated-imports/index.js +23 -117
- package/dist/esm/rules/use-datetime-picker-calendar-button/index.js +181 -0
- package/dist/esm/rules/utils/get-deprecated-config.js +9 -1
- package/dist/types/ast-nodes/jsx-attribute.d.ts +3 -0
- package/dist/types/index.codegen.d.ts +14 -9
- 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 +2 -3
- package/dist/types/rules/no-deprecated-imports/checks.d.ts +11 -0
- package/dist/types/rules/no-deprecated-imports/constants.d.ts +2 -0
- package/dist/types/rules/no-deprecated-imports/handlers/icon.d.ts +38 -0
- package/dist/types/rules/no-deprecated-imports/index.d.ts +1 -7
- package/dist/types/rules/use-datetime-picker-calendar-button/index.d.ts +7 -0
- package/dist/types/rules/utils/types.d.ts +1 -0
- package/dist/types-ts4.5/ast-nodes/jsx-attribute.d.ts +3 -0
- package/dist/types-ts4.5/index.codegen.d.ts +14 -15
- 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 +2 -5
- package/dist/types-ts4.5/rules/no-deprecated-imports/checks.d.ts +11 -0
- package/dist/types-ts4.5/rules/no-deprecated-imports/constants.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-deprecated-imports/handlers/icon.d.ts +38 -0
- package/dist/types-ts4.5/rules/no-deprecated-imports/index.d.ts +1 -9
- package/dist/types-ts4.5/rules/use-datetime-picker-calendar-button/index.d.ts +7 -0
- package/dist/types-ts4.5/rules/utils/types.d.ts +1 -0
- package/package.json +3 -2
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
6
|
+
exports.name = exports.default = void 0;
|
|
9
7
|
var _createRule = require("../utils/create-rule");
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
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; } }
|
|
14
|
-
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; } /**
|
|
8
|
+
var _errorBoundary = require("../utils/error-boundary");
|
|
9
|
+
var _checks = require("./checks");
|
|
10
|
+
/**
|
|
15
11
|
* Forked from original `no-restricted-imports` although the source has been substantially changed.
|
|
16
12
|
*
|
|
17
13
|
* To ensure compliance the license from eslint has been included and the original attribution.
|
|
@@ -37,19 +33,18 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
37
33
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
38
34
|
* THE SOFTWARE.
|
|
39
35
|
*/
|
|
36
|
+
|
|
40
37
|
var name = exports.name = 'no-deprecated-imports';
|
|
41
|
-
var
|
|
42
|
-
var pathWithCustomMessageId = exports.pathWithCustomMessageId = 'pathWithCustomMessage';
|
|
43
|
-
var rule = (0, _createRule.createRule)({
|
|
44
|
-
name: name,
|
|
45
|
-
defaultOptions: [{
|
|
46
|
-
deprecatedConfig: (0, _getDeprecatedConfig.getConfig)('imports')
|
|
47
|
-
}],
|
|
38
|
+
var rule = (0, _createRule.createLintRule)({
|
|
48
39
|
meta: {
|
|
40
|
+
name: name,
|
|
41
|
+
fixable: 'code',
|
|
42
|
+
hasSuggestions: true,
|
|
49
43
|
type: 'suggestion',
|
|
50
44
|
docs: {
|
|
51
45
|
description: 'Disallow importing deprecated modules.',
|
|
52
|
-
recommended:
|
|
46
|
+
recommended: true,
|
|
47
|
+
severity: 'error'
|
|
53
48
|
},
|
|
54
49
|
messages: {
|
|
55
50
|
pathWithCustomMessage: "'{{importSource}}' import is restricted from being used. {{customMessage}}",
|
|
@@ -89,108 +84,20 @@ var rule = (0, _createRule.createRule)({
|
|
|
89
84
|
}
|
|
90
85
|
}]
|
|
91
86
|
},
|
|
92
|
-
create: function create(context
|
|
93
|
-
var
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
* @param {Map<string,TSESTree.Node>} importNames Map of import names that are being imported
|
|
107
|
-
* @returns {void}
|
|
108
|
-
* @private
|
|
109
|
-
*/
|
|
110
|
-
function checkRestrictedPathAndReport(importSource, node, importNames) {
|
|
111
|
-
if (!Object.prototype.hasOwnProperty.call(restrictedPathMessages, importSource)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
var config = restrictedPathMessages[importSource];
|
|
115
|
-
|
|
116
|
-
// The message will only exist if the import is completely banned,
|
|
117
|
-
// eg a deprecated package
|
|
118
|
-
if ('message' in config) {
|
|
119
|
-
context.report({
|
|
120
|
-
node: node,
|
|
121
|
-
messageId: pathWithCustomMessageId,
|
|
122
|
-
data: {
|
|
123
|
-
importSource: importSource,
|
|
124
|
-
customMessage: config.message
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// if there are specific named exports that are banned,
|
|
130
|
-
// iterate through and check if they're being imported
|
|
131
|
-
if ('importSpecifiers' in config) {
|
|
132
|
-
var _config$importSpecifi;
|
|
133
|
-
(_config$importSpecifi = config.importSpecifiers) === null || _config$importSpecifi === void 0 || _config$importSpecifi.forEach(function (restrictedImport) {
|
|
134
|
-
if (importNames.has(restrictedImport.importName)) {
|
|
135
|
-
context.report({
|
|
136
|
-
node: importNames.get(restrictedImport.importName),
|
|
137
|
-
messageId: importNameWithCustomMessageId,
|
|
138
|
-
data: {
|
|
139
|
-
importName: restrictedImport.importName,
|
|
140
|
-
importSource: importSource,
|
|
141
|
-
customMessage: restrictedImport.message
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Checks a node to see if any problems should be reported.
|
|
151
|
-
* @param {ASTNode} node The node to check.
|
|
152
|
-
* @returns {void}
|
|
153
|
-
* @private
|
|
154
|
-
*/
|
|
155
|
-
var checkNode = function checkNode(node) {
|
|
156
|
-
var importSource = node.source.value.trim();
|
|
157
|
-
var importNames = new Map();
|
|
158
|
-
if ('specifiers' in node) {
|
|
159
|
-
var _iterator = _createForOfIteratorHelper(node.specifiers),
|
|
160
|
-
_step;
|
|
161
|
-
try {
|
|
162
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
163
|
-
var specifier = _step.value;
|
|
164
|
-
var _name = void 0;
|
|
165
|
-
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
166
|
-
_name = 'default';
|
|
167
|
-
} else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
168
|
-
_name = '*';
|
|
169
|
-
} else if (specifier.type === 'ImportSpecifier') {
|
|
170
|
-
_name = specifier.imported.name;
|
|
171
|
-
} else if (specifier.local) {
|
|
172
|
-
_name = specifier.local.name;
|
|
173
|
-
}
|
|
174
|
-
if (_name) {
|
|
175
|
-
importNames.set(_name, specifier);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
} catch (err) {
|
|
179
|
-
_iterator.e(err);
|
|
180
|
-
} finally {
|
|
181
|
-
_iterator.f();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
checkRestrictedPathAndReport(importSource, node, importNames);
|
|
185
|
-
};
|
|
186
|
-
return {
|
|
187
|
-
ImportDeclaration: checkNode,
|
|
188
|
-
ExportNamedDeclaration: function ExportNamedDeclaration(node) {
|
|
189
|
-
if (node.source) {
|
|
190
|
-
checkNode(node);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
};
|
|
87
|
+
create: function create(context) {
|
|
88
|
+
var _createChecks = (0, _checks.createChecks)(context),
|
|
89
|
+
checkImportNode = _createChecks.checkImportNode,
|
|
90
|
+
checkExportNode = _createChecks.checkExportNode,
|
|
91
|
+
checkJSXElement = _createChecks.checkJSXElement,
|
|
92
|
+
checkIdentifier = _createChecks.checkIdentifier,
|
|
93
|
+
throwErrors = _createChecks.throwErrors;
|
|
94
|
+
return (0, _errorBoundary.errorBoundary)({
|
|
95
|
+
ImportDeclaration: checkImportNode,
|
|
96
|
+
ExportNamedDeclaration: checkExportNode,
|
|
97
|
+
JSXElement: checkJSXElement,
|
|
98
|
+
Identifier: checkIdentifier,
|
|
99
|
+
'Program:exit': throwErrors
|
|
100
|
+
});
|
|
194
101
|
}
|
|
195
102
|
});
|
|
196
103
|
var _default = exports.default = rule;
|
|
@@ -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;
|
|
@@ -5,11 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.getConfig = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
8
9
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _deprecatedMap = require("@atlaskit/icon-lab/deprecated-map");
|
|
12
|
+
var _deprecatedMap2 = require("@atlaskit/icon/deprecated-map");
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
15
|
var getConfig = exports.getConfig = function getConfig(specifier) {
|
|
11
16
|
var configPath = _path.default.resolve(__dirname, '..', '..', '..', 'configs', 'deprecated.json');
|
|
12
17
|
var source = _fs.default.readFileSync(configPath, 'utf8');
|
|
13
18
|
var parsedConfig = JSON.parse(source);
|
|
14
|
-
|
|
19
|
+
var combinedConfig = _objectSpread(_objectSpread({}, parsedConfig), {}, {
|
|
20
|
+
imports: _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, parsedConfig.imports), _deprecatedMap2.deprecatedCore), _deprecatedMap2.deprecatedUtility), _deprecatedMap.deprecatedCore)
|
|
21
|
+
});
|
|
22
|
+
return combinedConfig[specifier];
|
|
15
23
|
};
|
|
@@ -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,175 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { getConfig } from '../utils/get-deprecated-config';
|
|
3
|
+
import { isDeprecatedImportConfig } from '../utils/types';
|
|
4
|
+
import { importNameWithCustomMessageId, pathWithCustomMessageId } from './constants';
|
|
5
|
+
import { getDeprecationIconHandler } from './handlers/icon';
|
|
6
|
+
export const createChecks = context => {
|
|
7
|
+
const deprecatedIconHandler = getDeprecationIconHandler(context);
|
|
8
|
+
const throwErrors = () => {
|
|
9
|
+
deprecatedIconHandler.throwErrors();
|
|
10
|
+
};
|
|
11
|
+
const getHandler = importSource => {
|
|
12
|
+
if (importSource.startsWith('@atlaskit/icon')) {
|
|
13
|
+
return deprecatedIconHandler;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Report a restricted path.
|
|
19
|
+
* @param {string} importSource path of the import
|
|
20
|
+
* @param {string} type whether the node is an import or export
|
|
21
|
+
* @param {node} node representing the restricted path reference
|
|
22
|
+
* @param {Map<string,TSESTree.Node>} importNames Map of import names that are being imported
|
|
23
|
+
* @returns {void}
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
function checkRestrictedPathAndReport({
|
|
27
|
+
importSource,
|
|
28
|
+
type,
|
|
29
|
+
node,
|
|
30
|
+
importNames
|
|
31
|
+
}) {
|
|
32
|
+
var _context$options$;
|
|
33
|
+
const restrictedPathMessages = ((_context$options$ = context.options[0]) === null || _context$options$ === void 0 ? void 0 : _context$options$.deprecatedConfig) || getConfig('imports');
|
|
34
|
+
if (!isDeprecatedImportConfig(restrictedPathMessages)) {
|
|
35
|
+
throw new Error('Config is invalid for deprecated imports');
|
|
36
|
+
}
|
|
37
|
+
if (!Object.prototype.hasOwnProperty.call(restrictedPathMessages, importSource)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const config = restrictedPathMessages[importSource];
|
|
41
|
+
const handler = getHandler(importSource);
|
|
42
|
+
if (handler) {
|
|
43
|
+
if (type === 'import') {
|
|
44
|
+
handler.createImportError({
|
|
45
|
+
node,
|
|
46
|
+
importSource,
|
|
47
|
+
config
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
handler.createExportError({
|
|
51
|
+
node,
|
|
52
|
+
importSource,
|
|
53
|
+
config
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
// Default behaviour
|
|
58
|
+
// The message will only exist if the import is completely banned,
|
|
59
|
+
// eg a deprecated package
|
|
60
|
+
if ('message' in config) {
|
|
61
|
+
context.report({
|
|
62
|
+
node,
|
|
63
|
+
messageId: pathWithCustomMessageId,
|
|
64
|
+
data: {
|
|
65
|
+
importSource,
|
|
66
|
+
customMessage: config.message
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// if there are specific named exports that are banned,
|
|
72
|
+
// iterate through and check if they're being imported
|
|
73
|
+
if ('importSpecifiers' in config) {
|
|
74
|
+
var _config$importSpecifi;
|
|
75
|
+
(_config$importSpecifi = config.importSpecifiers) === null || _config$importSpecifi === void 0 ? void 0 : _config$importSpecifi.forEach(restrictedImport => {
|
|
76
|
+
if (importNames.has(restrictedImport.importName)) {
|
|
77
|
+
context.report({
|
|
78
|
+
node: importNames.get(restrictedImport.importName),
|
|
79
|
+
messageId: importNameWithCustomMessageId,
|
|
80
|
+
data: {
|
|
81
|
+
importName: restrictedImport.importName,
|
|
82
|
+
importSource: importSource,
|
|
83
|
+
customMessage: restrictedImport.message
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Checks a node to see if any problems should be reported.
|
|
94
|
+
* @param {ASTNode} node The node to check.
|
|
95
|
+
* @returns {void}
|
|
96
|
+
* @private
|
|
97
|
+
*/
|
|
98
|
+
const checkImportNode = node => {
|
|
99
|
+
const importSource = node.source.value.trim();
|
|
100
|
+
const importNames = new Map();
|
|
101
|
+
if ('specifiers' in node) {
|
|
102
|
+
for (const specifier of node.specifiers) {
|
|
103
|
+
let name;
|
|
104
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
105
|
+
name = 'default';
|
|
106
|
+
} else if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
107
|
+
name = '*';
|
|
108
|
+
} else if (specifier.type === 'ImportSpecifier') {
|
|
109
|
+
name = specifier.imported.name;
|
|
110
|
+
}
|
|
111
|
+
if (name) {
|
|
112
|
+
importNames.set(name, specifier);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
checkRestrictedPathAndReport({
|
|
117
|
+
importSource,
|
|
118
|
+
type: 'import',
|
|
119
|
+
node,
|
|
120
|
+
importNames
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Checks a node to see if any problems should be reported.
|
|
126
|
+
* @param {ASTNode} node The node to check.
|
|
127
|
+
* @returns {void}
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
const checkExportNode = node => {
|
|
131
|
+
if (!node.source || !node.source.value) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const importSource = node.source.value.trim();
|
|
135
|
+
const importNames = new Map();
|
|
136
|
+
if ('specifiers' in node) {
|
|
137
|
+
for (const specifier of node.specifiers) {
|
|
138
|
+
let name;
|
|
139
|
+
if (specifier.local) {
|
|
140
|
+
name = specifier.local.name;
|
|
141
|
+
}
|
|
142
|
+
if (name) {
|
|
143
|
+
importNames.set(name, specifier);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
checkRestrictedPathAndReport({
|
|
148
|
+
importSource,
|
|
149
|
+
type: 'export',
|
|
150
|
+
node,
|
|
151
|
+
importNames
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Create a mapping of JSX elements by their name so they can be processed later.
|
|
157
|
+
* @param node The JSX node found by ESLint
|
|
158
|
+
*/
|
|
159
|
+
const checkJSXElement = node => {
|
|
160
|
+
if (!('openingElement' in node) || !isNodeOfType(node.openingElement.name, 'JSXIdentifier')) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
deprecatedIconHandler.checkJSXElement(node);
|
|
164
|
+
};
|
|
165
|
+
const checkIdentifier = node => {
|
|
166
|
+
deprecatedIconHandler.checkIdentifier(node);
|
|
167
|
+
};
|
|
168
|
+
return {
|
|
169
|
+
checkImportNode,
|
|
170
|
+
checkExportNode,
|
|
171
|
+
checkJSXElement,
|
|
172
|
+
checkIdentifier,
|
|
173
|
+
throwErrors
|
|
174
|
+
};
|
|
175
|
+
};
|