@atlaskit/eslint-plugin-platform 2.9.2 → 2.10.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 +15 -0
- package/dist/cjs/index.js +11 -1
- package/dist/cjs/rules/compiled/expand-motion-shorthand/index.js +281 -0
- package/dist/cjs/rules/compiled/use-motion-token-values/index.js +506 -0
- package/dist/cjs/rules/editor-example-type-import-required/index.js +321 -0
- package/dist/cjs/rules/import/one-value-export-per-file/index.js +203 -0
- package/dist/es2019/index.js +11 -1
- package/dist/es2019/rules/compiled/expand-motion-shorthand/index.js +239 -0
- package/dist/es2019/rules/compiled/use-motion-token-values/index.js +444 -0
- package/dist/es2019/rules/editor-example-type-import-required/index.js +286 -0
- package/dist/es2019/rules/import/one-value-export-per-file/index.js +191 -0
- package/dist/esm/index.js +11 -1
- package/dist/esm/rules/compiled/expand-motion-shorthand/index.js +275 -0
- package/dist/esm/rules/compiled/use-motion-token-values/index.js +499 -0
- package/dist/esm/rules/editor-example-type-import-required/index.js +314 -0
- package/dist/esm/rules/import/one-value-export-per-file/index.js +196 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/rules/compiled/expand-motion-shorthand/index.d.ts +3 -0
- package/dist/types/rules/compiled/use-motion-token-values/index.d.ts +3 -0
- package/dist/types/rules/editor-example-type-import-required/index.d.ts +4 -0
- package/dist/types/rules/import/one-value-export-per-file/index.d.ts +3 -0
- package/dist/types-ts4.5/index.d.ts +6 -0
- package/dist/types-ts4.5/rules/compiled/expand-motion-shorthand/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/compiled/use-motion-token-values/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/editor-example-type-import-required/index.d.ts +4 -0
- package/dist/types-ts4.5/rules/import/one-value-export-per-file/index.d.ts +3 -0
- package/package.json +2 -1
|
@@ -0,0 +1,275 @@
|
|
|
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
|
+
var EASING_KEYWORDS = ['ease', 'ease-in', 'ease-out', 'ease-in-out', 'linear', 'step-start', 'step-end'];
|
|
5
|
+
var KEYWORD_VALUES = ['none', 'all', 'inherit', 'initial', 'unset'];
|
|
6
|
+
var isDuration = function isDuration(token) {
|
|
7
|
+
return /^\d+(?:\.\d+)?m?s$/.test(token);
|
|
8
|
+
};
|
|
9
|
+
var isEasing = function isEasing(token) {
|
|
10
|
+
return EASING_KEYWORDS.includes(token) || token.startsWith('cubic-bezier(') || token.startsWith('steps(');
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Tokenizes a CSS shorthand value string, respecting function boundaries.
|
|
14
|
+
* e.g. 'opacity 200ms cubic-bezier(0.4, 0, 0, 1) 0ms' →
|
|
15
|
+
* ['opacity', '200ms', 'cubic-bezier(0.4, 0, 0, 1)', '0ms']
|
|
16
|
+
* Splits on whitespace only when not inside parentheses.
|
|
17
|
+
*/
|
|
18
|
+
var tokenizeShorthand = function tokenizeShorthand(value) {
|
|
19
|
+
var tokens = [];
|
|
20
|
+
var depth = 0;
|
|
21
|
+
var current = '';
|
|
22
|
+
for (var i = 0; i < value.length; i++) {
|
|
23
|
+
var ch = value[i];
|
|
24
|
+
if (ch === '(') {
|
|
25
|
+
depth++;
|
|
26
|
+
current += ch;
|
|
27
|
+
} else if (ch === ')') {
|
|
28
|
+
depth--;
|
|
29
|
+
current += ch;
|
|
30
|
+
} else if (/\s/.test(ch) && depth === 0) {
|
|
31
|
+
if (current.length > 0) {
|
|
32
|
+
tokens.push(current);
|
|
33
|
+
current = '';
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
current += ch;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (current.length > 0) {
|
|
40
|
+
tokens.push(current);
|
|
41
|
+
}
|
|
42
|
+
return tokens;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// Splits on top-level commas (outside function parens) — preserves cubic-bezier(...) commas.
|
|
46
|
+
var splitOnTopLevelCommas = function splitOnTopLevelCommas(value) {
|
|
47
|
+
var parts = [];
|
|
48
|
+
var depth = 0;
|
|
49
|
+
var current = '';
|
|
50
|
+
var _iterator = _createForOfIteratorHelper(value),
|
|
51
|
+
_step;
|
|
52
|
+
try {
|
|
53
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
+
var ch = _step.value;
|
|
55
|
+
if (ch === '(') {
|
|
56
|
+
depth++;
|
|
57
|
+
current += ch;
|
|
58
|
+
} else if (ch === ')') {
|
|
59
|
+
depth--;
|
|
60
|
+
current += ch;
|
|
61
|
+
} else if (ch === ',' && depth === 0) {
|
|
62
|
+
parts.push(current.trim());
|
|
63
|
+
current = '';
|
|
64
|
+
} else {
|
|
65
|
+
current += ch;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
} catch (err) {
|
|
69
|
+
_iterator.e(err);
|
|
70
|
+
} finally {
|
|
71
|
+
_iterator.f();
|
|
72
|
+
}
|
|
73
|
+
if (current.trim().length > 0) {
|
|
74
|
+
parts.push(current.trim());
|
|
75
|
+
}
|
|
76
|
+
return parts;
|
|
77
|
+
};
|
|
78
|
+
var parseTransition = function parseTransition(value) {
|
|
79
|
+
var parts = tokenizeShorthand(value.trim());
|
|
80
|
+
var result = {};
|
|
81
|
+
var durationCount = 0;
|
|
82
|
+
var _iterator2 = _createForOfIteratorHelper(parts),
|
|
83
|
+
_step2;
|
|
84
|
+
try {
|
|
85
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
86
|
+
var part = _step2.value;
|
|
87
|
+
if (isDuration(part)) {
|
|
88
|
+
if (durationCount === 0) {
|
|
89
|
+
result.transitionDuration = part;
|
|
90
|
+
} else {
|
|
91
|
+
result.transitionDelay = part;
|
|
92
|
+
}
|
|
93
|
+
durationCount++;
|
|
94
|
+
} else if (isEasing(part)) {
|
|
95
|
+
result.transitionTimingFunction = part;
|
|
96
|
+
} else {
|
|
97
|
+
result.transitionProperty = part;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
_iterator2.e(err);
|
|
102
|
+
} finally {
|
|
103
|
+
_iterator2.f();
|
|
104
|
+
}
|
|
105
|
+
return result;
|
|
106
|
+
};
|
|
107
|
+
var parseAnimation = function parseAnimation(value) {
|
|
108
|
+
var parts = tokenizeShorthand(value.trim());
|
|
109
|
+
var result = {};
|
|
110
|
+
var durationCount = 0;
|
|
111
|
+
var _iterator3 = _createForOfIteratorHelper(parts),
|
|
112
|
+
_step3;
|
|
113
|
+
try {
|
|
114
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
115
|
+
var part = _step3.value;
|
|
116
|
+
if (isDuration(part)) {
|
|
117
|
+
if (durationCount === 0) {
|
|
118
|
+
result.animationDuration = part;
|
|
119
|
+
} else {
|
|
120
|
+
result.animationDelay = part;
|
|
121
|
+
}
|
|
122
|
+
durationCount++;
|
|
123
|
+
} else if (isEasing(part)) {
|
|
124
|
+
result.animationTimingFunction = part;
|
|
125
|
+
} else if (part === 'infinite' || /^\d+(\.\d+)?$/.test(part)) {
|
|
126
|
+
result.animationIterationCount = part;
|
|
127
|
+
} else if (['normal', 'reverse', 'alternate', 'alternate-reverse'].includes(part)) {
|
|
128
|
+
result.animationDirection = part;
|
|
129
|
+
} else if (['none', 'forwards', 'backwards', 'both'].includes(part)) {
|
|
130
|
+
result.animationFillMode = part;
|
|
131
|
+
} else if (['running', 'paused'].includes(part)) {
|
|
132
|
+
result.animationPlayState = part;
|
|
133
|
+
} else {
|
|
134
|
+
result.animationName = part;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} catch (err) {
|
|
138
|
+
_iterator3.e(err);
|
|
139
|
+
} finally {
|
|
140
|
+
_iterator3.f();
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Combine sub-property values across comma-separated transitions/animations.
|
|
146
|
+
// If no segment explicitly set this sub-property, omit it entirely.
|
|
147
|
+
// Otherwise, fill missing slots with the CSS spec default to preserve positional alignment.
|
|
148
|
+
var combineSubPropertyValues = function combineSubPropertyValues(segments, subProperty, defaultValue) {
|
|
149
|
+
if (segments.every(function (s) {
|
|
150
|
+
return s[subProperty] === undefined;
|
|
151
|
+
})) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
return segments.map(function (s) {
|
|
155
|
+
var _s$subProperty;
|
|
156
|
+
return (_s$subProperty = s[subProperty]) !== null && _s$subProperty !== void 0 ? _s$subProperty : defaultValue;
|
|
157
|
+
}).join(', ');
|
|
158
|
+
};
|
|
159
|
+
var buildTransitionFix = function buildTransitionFix(segments, indent) {
|
|
160
|
+
var lines = [];
|
|
161
|
+
var property = combineSubPropertyValues(segments, 'transitionProperty', 'all');
|
|
162
|
+
var duration = combineSubPropertyValues(segments, 'transitionDuration', '0s');
|
|
163
|
+
var timing = combineSubPropertyValues(segments, 'transitionTimingFunction', 'ease');
|
|
164
|
+
var delay = combineSubPropertyValues(segments, 'transitionDelay', '0s');
|
|
165
|
+
if (property !== undefined) lines.push("transitionProperty: '".concat(property, "'"));
|
|
166
|
+
if (duration !== undefined) lines.push("transitionDuration: '".concat(duration, "'"));
|
|
167
|
+
if (timing !== undefined) lines.push("transitionTimingFunction: '".concat(timing, "'"));
|
|
168
|
+
if (delay !== undefined) lines.push("transitionDelay: '".concat(delay, "'"));
|
|
169
|
+
return lines.join(",\n".concat(indent));
|
|
170
|
+
};
|
|
171
|
+
var buildAnimationFix = function buildAnimationFix(segments, indent) {
|
|
172
|
+
var lines = [];
|
|
173
|
+
var name = combineSubPropertyValues(segments, 'animationName', 'none');
|
|
174
|
+
var duration = combineSubPropertyValues(segments, 'animationDuration', '0s');
|
|
175
|
+
var timing = combineSubPropertyValues(segments, 'animationTimingFunction', 'ease');
|
|
176
|
+
var delay = combineSubPropertyValues(segments, 'animationDelay', '0s');
|
|
177
|
+
var iter = combineSubPropertyValues(segments, 'animationIterationCount', '1');
|
|
178
|
+
var direction = combineSubPropertyValues(segments, 'animationDirection', 'normal');
|
|
179
|
+
var fill = combineSubPropertyValues(segments, 'animationFillMode', 'none');
|
|
180
|
+
var playState = combineSubPropertyValues(segments, 'animationPlayState', 'running');
|
|
181
|
+
if (name !== undefined) lines.push("animationName: '".concat(name, "'"));
|
|
182
|
+
if (duration !== undefined) lines.push("animationDuration: '".concat(duration, "'"));
|
|
183
|
+
if (timing !== undefined) lines.push("animationTimingFunction: '".concat(timing, "'"));
|
|
184
|
+
if (delay !== undefined) lines.push("animationDelay: '".concat(delay, "'"));
|
|
185
|
+
if (iter !== undefined) lines.push("animationIterationCount: '".concat(iter, "'"));
|
|
186
|
+
if (direction !== undefined) lines.push("animationDirection: '".concat(direction, "'"));
|
|
187
|
+
if (fill !== undefined) lines.push("animationFillMode: '".concat(fill, "'"));
|
|
188
|
+
if (playState !== undefined) lines.push("animationPlayState: '".concat(playState, "'"));
|
|
189
|
+
return lines.join(",\n".concat(indent));
|
|
190
|
+
};
|
|
191
|
+
var TRANSITION_SUB_PROPERTIES = ['transitionProperty', 'transitionDuration', 'transitionTimingFunction', 'transitionDelay'];
|
|
192
|
+
var ANIMATION_SUB_PROPERTIES = ['animationName', 'animationDuration', 'animationTimingFunction', 'animationDelay', 'animationIterationCount', 'animationDirection', 'animationFillMode', 'animationPlayState'];
|
|
193
|
+
var executeExpandTransitionRule = function executeExpandTransitionRule(context, node, property) {
|
|
194
|
+
var _context$sourceCode, _node$loc;
|
|
195
|
+
if (node.value.type === 'CallExpression') {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (node.value.type === 'TemplateLiteral') {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (node.value.type !== 'Literal' || typeof node.value.value !== 'string') {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
var rawValue = node.value.value;
|
|
205
|
+
if (KEYWORD_VALUES.includes(rawValue)) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
var subProperties = property === 'transition' ? TRANSITION_SUB_PROPERTIES : ANIMATION_SUB_PROPERTIES;
|
|
209
|
+
|
|
210
|
+
// Extract leading whitespace to preserve indentation style (tabs vs spaces)
|
|
211
|
+
var sourceCode = (_context$sourceCode = context.sourceCode) !== null && _context$sourceCode !== void 0 ? _context$sourceCode : context.getSourceCode();
|
|
212
|
+
var nodeStart = (_node$loc = node.loc) === null || _node$loc === void 0 ? void 0 : _node$loc.start;
|
|
213
|
+
var indent = '\t';
|
|
214
|
+
if (nodeStart) {
|
|
215
|
+
var _sourceCode$lines;
|
|
216
|
+
var lineText = (_sourceCode$lines = sourceCode.lines[nodeStart.line - 1]) !== null && _sourceCode$lines !== void 0 ? _sourceCode$lines : '';
|
|
217
|
+
var leadingWhitespace = lineText.match(/^(\s*)/);
|
|
218
|
+
if (leadingWhitespace) {
|
|
219
|
+
indent = leadingWhitespace[1];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
var segmentStrings = splitOnTopLevelCommas(rawValue);
|
|
223
|
+
if (property === 'transition') {
|
|
224
|
+
var segments = segmentStrings.map(parseTransition);
|
|
225
|
+
var fixText = buildTransitionFix(segments, indent);
|
|
226
|
+
context.report({
|
|
227
|
+
node: node,
|
|
228
|
+
messageId: 'expandTransitionShorthand',
|
|
229
|
+
data: {
|
|
230
|
+
property: property,
|
|
231
|
+
subProperties: subProperties.join(', ')
|
|
232
|
+
},
|
|
233
|
+
fix: function fix(fixer) {
|
|
234
|
+
return fixer.replaceText(node, fixText);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
} else {
|
|
238
|
+
var _segments = segmentStrings.map(parseAnimation);
|
|
239
|
+
var _fixText = buildAnimationFix(_segments, indent);
|
|
240
|
+
context.report({
|
|
241
|
+
node: node,
|
|
242
|
+
messageId: 'expandTransitionShorthand',
|
|
243
|
+
data: {
|
|
244
|
+
property: property,
|
|
245
|
+
subProperties: subProperties.join(', ')
|
|
246
|
+
},
|
|
247
|
+
fix: function fix(fixer) {
|
|
248
|
+
return fixer.replaceText(node, _fixText);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
export var expandTransitionShorthand = {
|
|
254
|
+
meta: {
|
|
255
|
+
type: 'suggestion',
|
|
256
|
+
fixable: 'code',
|
|
257
|
+
docs: {
|
|
258
|
+
url: 'https://bitbucket.org/atlassian/atlassian-frontend-monorepo/src/master/platform/packages/platform/eslint-plugin/src/rules/compiled/expand-transition-shorthand/'
|
|
259
|
+
},
|
|
260
|
+
messages: {
|
|
261
|
+
expandTransitionShorthand: "Use {{ subProperties }} instead of the '{{ property }}' shorthand so that individual values can be replaced with motion tokens."
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
create: function create(context) {
|
|
265
|
+
return {
|
|
266
|
+
'Property[key.name="transition"]': function PropertyKeyNameTransition(node) {
|
|
267
|
+
executeExpandTransitionRule(context, node, 'transition');
|
|
268
|
+
},
|
|
269
|
+
'Property[key.name="animation"]': function PropertyKeyNameAnimation(node) {
|
|
270
|
+
executeExpandTransitionRule(context, node, 'animation');
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
export default expandTransitionShorthand;
|