@atlaskit/eslint-plugin-ui-styling-standard 0.11.5 → 0.12.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 +17 -0
- package/README.md +11 -7
- package/constellation/atlaskit-theme/usage.mdx +113 -0
- package/constellation/convert-props-syntax/usage.mdx +32 -22
- package/constellation/enforce-style-prop/usage.mdx +21 -18
- package/constellation/index/overview.mdx +92 -76
- package/constellation/local-cx-xcss/usage.mdx +10 -6
- package/constellation/no-array-arguments/usage.mdx +10 -9
- package/constellation/no-classname-prop/usage.mdx +7 -4
- package/constellation/no-container-queries/usage.mdx +17 -15
- package/constellation/no-dynamic-styles/usage.mdx +26 -29
- package/constellation/no-exported-styles/usage.mdx +23 -18
- package/constellation/no-important-styles/usage.mdx +5 -3
- package/constellation/no-imported-style-values/usage.mdx +30 -22
- package/constellation/no-nested-selectors/usage.mdx +22 -20
- package/constellation/no-unsafe-values/usage.mdx +45 -51
- package/constellation/use-compiled/usage.mdx +51 -0
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended.codegen.js +3 -1
- package/dist/cjs/rules/atlaskit-theme/index.js +95 -0
- package/dist/cjs/rules/index.codegen.js +6 -2
- package/dist/cjs/rules/use-compiled/index.js +257 -0
- package/dist/cjs/rules/use-compiled/is-safe.js +130 -0
- package/dist/cjs/rules/use-compiled/utils.js +26 -0
- package/dist/es2019/index.codegen.js +1 -1
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended.codegen.js +3 -1
- package/dist/es2019/rules/atlaskit-theme/index.js +85 -0
- package/dist/es2019/rules/index.codegen.js +6 -2
- package/dist/es2019/rules/use-compiled/index.js +182 -0
- package/dist/es2019/rules/use-compiled/is-safe.js +118 -0
- package/dist/es2019/rules/use-compiled/utils.js +15 -0
- package/dist/esm/index.codegen.js +1 -1
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended.codegen.js +3 -1
- package/dist/esm/rules/atlaskit-theme/index.js +89 -0
- package/dist/esm/rules/index.codegen.js +6 -2
- package/dist/esm/rules/use-compiled/index.js +250 -0
- package/dist/esm/rules/use-compiled/is-safe.js +121 -0
- package/dist/esm/rules/use-compiled/utils.js +17 -0
- package/dist/types/index.codegen.d.ts +4 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/presets/recommended.codegen.d.ts +3 -1
- package/dist/types/rules/atlaskit-theme/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/use-compiled/index.d.ts +3 -0
- package/dist/types/rules/use-compiled/is-safe.d.ts +10 -0
- package/dist/types/rules/use-compiled/utils.d.ts +6 -0
- package/dist/types-ts4.5/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/atlaskit-theme/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/use-compiled/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/use-compiled/is-safe.d.ts +10 -0
- package/dist/types-ts4.5/rules/use-compiled/utils.d.ts +6 -0
- package/package.json +3 -2
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +67 -69
- package/src/presets/recommended.codegen.tsx +67 -69
- package/src/rules/atlaskit-theme/README.md +109 -0
- package/src/rules/atlaskit-theme/__tests__/test.ts +122 -0
- package/src/rules/atlaskit-theme/index.ts +136 -0
- package/src/rules/index.codegen.tsx +17 -13
- package/src/rules/use-compiled/README.md +49 -0
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +73 -0
- package/src/rules/use-compiled/__tests__/css.test.tsx +126 -0
- package/src/rules/use-compiled/__tests__/imports.test.tsx +139 -0
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +140 -0
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +108 -0
- package/src/rules/use-compiled/__tests__/styled.test.tsx +114 -0
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +15 -0
- package/src/rules/use-compiled/index.tsx +275 -0
- package/src/rules/use-compiled/is-safe.tsx +163 -0
- package/src/rules/use-compiled/utils.tsx +37 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.rule = exports.default = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
12
|
+
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
13
|
+
var _createRule = require("../utils/create-rule");
|
|
14
|
+
var _utils = require("./utils");
|
|
15
|
+
var _isSafe = require("./is-safe");
|
|
16
|
+
var SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
|
|
17
|
+
var SUPPORTED_IMPORT_MAP = {
|
|
18
|
+
'@emotion/core': SUPPORTED_EMOTION_IMPORTS,
|
|
19
|
+
'@emotion/react': SUPPORTED_EMOTION_IMPORTS,
|
|
20
|
+
'@emotion/styled': new Set(['default']),
|
|
21
|
+
'styled-components': new Set(['default', 'css', 'keyframes'])
|
|
22
|
+
};
|
|
23
|
+
function isSupportedImportSource(importSource) {
|
|
24
|
+
return importSource in SUPPORTED_IMPORT_MAP;
|
|
25
|
+
}
|
|
26
|
+
var schema = {
|
|
27
|
+
type: 'array',
|
|
28
|
+
items: [{
|
|
29
|
+
type: 'object',
|
|
30
|
+
properties: {
|
|
31
|
+
canAutoFix: {
|
|
32
|
+
type: 'boolean'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
additionalProperties: false
|
|
36
|
+
}]
|
|
37
|
+
};
|
|
38
|
+
var defaultConfig = {
|
|
39
|
+
canAutoFix: false
|
|
40
|
+
};
|
|
41
|
+
function readConfig(context) {
|
|
42
|
+
var _ref = context.options,
|
|
43
|
+
_ref2 = (0, _slicedToArray2.default)(_ref, 1),
|
|
44
|
+
config = _ref2[0];
|
|
45
|
+
return Object.assign({}, defaultConfig, config);
|
|
46
|
+
}
|
|
47
|
+
var rule = exports.rule = (0, _createRule.createLintRule)({
|
|
48
|
+
meta: {
|
|
49
|
+
name: 'use-compiled',
|
|
50
|
+
type: 'problem',
|
|
51
|
+
fixable: 'code',
|
|
52
|
+
docs: {
|
|
53
|
+
description: 'Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries',
|
|
54
|
+
recommended: true,
|
|
55
|
+
severity: 'warn'
|
|
56
|
+
},
|
|
57
|
+
messages: {
|
|
58
|
+
'use-compiled': "Use '@compiled/react' instead of '{{importSource}}'"
|
|
59
|
+
},
|
|
60
|
+
schema: schema
|
|
61
|
+
},
|
|
62
|
+
create: function create(context) {
|
|
63
|
+
var config = readConfig(context);
|
|
64
|
+
return {
|
|
65
|
+
Program: function Program() {
|
|
66
|
+
var pragma = context.getSourceCode().getAllComments().find(function (n) {
|
|
67
|
+
return n.value.includes('@jsxImportSource @emotion/react');
|
|
68
|
+
});
|
|
69
|
+
if (!pragma) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
context.report({
|
|
73
|
+
messageId: 'use-compiled',
|
|
74
|
+
data: {
|
|
75
|
+
importSource: '@emotion/react'
|
|
76
|
+
},
|
|
77
|
+
loc: pragma.loc,
|
|
78
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
79
|
+
var importDeclarations, hasEmotionImport, hasCompiledImport;
|
|
80
|
+
return _regenerator.default.wrap(function fix$(_context) {
|
|
81
|
+
while (1) switch (_context.prev = _context.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
if (config.canAutoFix) {
|
|
84
|
+
_context.next = 2;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
return _context.abrupt("return");
|
|
88
|
+
case 2:
|
|
89
|
+
importDeclarations = context.getSourceCode().ast.body.filter(function (node) {
|
|
90
|
+
return node.type === 'ImportDeclaration';
|
|
91
|
+
});
|
|
92
|
+
hasEmotionImport = importDeclarations.some(function (importDeclaration) {
|
|
93
|
+
var importSource = importDeclaration.source.value;
|
|
94
|
+
return importSource.startsWith('@emotion/');
|
|
95
|
+
});
|
|
96
|
+
hasCompiledImport = importDeclarations.some(function (importDeclaration) {
|
|
97
|
+
return importDeclaration.source.value === '@compiled/react';
|
|
98
|
+
});
|
|
99
|
+
if (!(hasEmotionImport || !hasCompiledImport)) {
|
|
100
|
+
_context.next = 7;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
return _context.abrupt("return");
|
|
104
|
+
case 7:
|
|
105
|
+
_context.next = 9;
|
|
106
|
+
return fixer.replaceText(
|
|
107
|
+
// @ts-expect-error - types don't accept comment nodes
|
|
108
|
+
pragma, "/** @jsxImportSource @compiled/react */");
|
|
109
|
+
case 9:
|
|
110
|
+
case "end":
|
|
111
|
+
return _context.stop();
|
|
112
|
+
}
|
|
113
|
+
}, fix);
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
ImportDeclaration: function (_ImportDeclaration) {
|
|
118
|
+
function ImportDeclaration(_x) {
|
|
119
|
+
return _ImportDeclaration.apply(this, arguments);
|
|
120
|
+
}
|
|
121
|
+
ImportDeclaration.toString = function () {
|
|
122
|
+
return _ImportDeclaration.toString();
|
|
123
|
+
};
|
|
124
|
+
return ImportDeclaration;
|
|
125
|
+
}(function (node) {
|
|
126
|
+
var importSource = node.source.value;
|
|
127
|
+
if (!isSupportedImportSource(importSource)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
context.report({
|
|
131
|
+
node: node.source,
|
|
132
|
+
messageId: 'use-compiled',
|
|
133
|
+
data: {
|
|
134
|
+
importSource: importSource
|
|
135
|
+
},
|
|
136
|
+
fix: /*#__PURE__*/_regenerator.default.mark(function fix(fixer) {
|
|
137
|
+
var specifiers;
|
|
138
|
+
return _regenerator.default.wrap(function fix$(_context2) {
|
|
139
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
140
|
+
case 0:
|
|
141
|
+
if (config.canAutoFix) {
|
|
142
|
+
_context2.next = 2;
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
return _context2.abrupt("return");
|
|
146
|
+
case 2:
|
|
147
|
+
specifiers = getSpecifiers({
|
|
148
|
+
context: context,
|
|
149
|
+
node: node,
|
|
150
|
+
importSource: importSource
|
|
151
|
+
});
|
|
152
|
+
if (specifiers) {
|
|
153
|
+
_context2.next = 5;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
return _context2.abrupt("return");
|
|
157
|
+
case 5:
|
|
158
|
+
return _context2.delegateYield(fixImport({
|
|
159
|
+
context: context,
|
|
160
|
+
fixer: fixer,
|
|
161
|
+
node: node,
|
|
162
|
+
specifiers: specifiers
|
|
163
|
+
}), "t0", 6);
|
|
164
|
+
case 6:
|
|
165
|
+
case "end":
|
|
166
|
+
return _context2.stop();
|
|
167
|
+
}
|
|
168
|
+
}, fix);
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
})
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
var _default = exports.default = rule;
|
|
176
|
+
function getSpecifiers(_ref3) {
|
|
177
|
+
var context = _ref3.context,
|
|
178
|
+
node = _ref3.node,
|
|
179
|
+
importSource = _ref3.importSource;
|
|
180
|
+
var supportedImports = SUPPORTED_IMPORT_MAP[importSource];
|
|
181
|
+
|
|
182
|
+
// We aren't supporting namespace imports
|
|
183
|
+
if (node.specifiers.some(_utils.isImportNamespaceSpecifier)) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
var defaultSpecifier = node.specifiers.find(_utils.isImportDefaultSpecifier);
|
|
187
|
+
if (defaultSpecifier) {
|
|
188
|
+
if (!supportedImports.has('default')) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
var styled = (0, _findVariable.findVariable)({
|
|
192
|
+
identifier: defaultSpecifier.local,
|
|
193
|
+
sourceCode: context.getSourceCode()
|
|
194
|
+
});
|
|
195
|
+
if (!styled || !(0, _isSafe.isSafeStyled)(styled)) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
var namedSpecifiers = node.specifiers.filter(_utils.isImportSpecifier);
|
|
200
|
+
if (!namedSpecifiers.every(function (specifier) {
|
|
201
|
+
return (0, _isSafe.isSafeUsage)({
|
|
202
|
+
context: context,
|
|
203
|
+
specifier: specifier,
|
|
204
|
+
supportedImports: supportedImports
|
|
205
|
+
});
|
|
206
|
+
})) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (defaultSpecifier) {
|
|
210
|
+
return [].concat((0, _toConsumableArray2.default)(namedSpecifiers), [
|
|
211
|
+
// ASSUMPTION: the default import, if allowed, is for `styled`
|
|
212
|
+
(0, _eslintCodemodUtils.importSpecifier)({
|
|
213
|
+
imported: (0, _eslintCodemodUtils.identifier)('styled'),
|
|
214
|
+
local: node.specifiers[0].local
|
|
215
|
+
})]);
|
|
216
|
+
}
|
|
217
|
+
return namedSpecifiers;
|
|
218
|
+
}
|
|
219
|
+
function fixImport(_ref4) {
|
|
220
|
+
var context = _ref4.context,
|
|
221
|
+
fixer = _ref4.fixer,
|
|
222
|
+
node = _ref4.node,
|
|
223
|
+
specifiers = _ref4.specifiers;
|
|
224
|
+
return /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
225
|
+
var compiledImport;
|
|
226
|
+
return _regenerator.default.wrap(function _callee$(_context3) {
|
|
227
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
228
|
+
case 0:
|
|
229
|
+
compiledImport = (0, _utils.getFirstImportFromSource)(context, '@compiled/react');
|
|
230
|
+
if (!compiledImport) {
|
|
231
|
+
_context3.next = 8;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
_context3.next = 4;
|
|
235
|
+
return fixer.remove(node);
|
|
236
|
+
case 4:
|
|
237
|
+
_context3.next = 6;
|
|
238
|
+
return fixer.replaceText(compiledImport, buildImportDeclaration(compiledImport.specifiers.concat(specifiers), '@compiled/react'));
|
|
239
|
+
case 6:
|
|
240
|
+
_context3.next = 10;
|
|
241
|
+
break;
|
|
242
|
+
case 8:
|
|
243
|
+
_context3.next = 10;
|
|
244
|
+
return fixer.replaceText(node, buildImportDeclaration(specifiers, '@compiled/react'));
|
|
245
|
+
case 10:
|
|
246
|
+
case "end":
|
|
247
|
+
return _context3.stop();
|
|
248
|
+
}
|
|
249
|
+
}, _callee);
|
|
250
|
+
})();
|
|
251
|
+
}
|
|
252
|
+
function buildImportDeclaration(specifiers, source) {
|
|
253
|
+
return "".concat((0, _eslintCodemodUtils.importDeclaration)({
|
|
254
|
+
specifiers: specifiers,
|
|
255
|
+
source: (0, _eslintCodemodUtils.literal)(source)
|
|
256
|
+
}), ";");
|
|
257
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isSafeCss = isSafeCss;
|
|
7
|
+
exports.isSafeKeyframes = isSafeKeyframes;
|
|
8
|
+
exports.isSafeStyled = isSafeStyled;
|
|
9
|
+
exports.isSafeUsage = isSafeUsage;
|
|
10
|
+
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
11
|
+
var _findVariable = require("@atlaskit/eslint-utils/find-variable");
|
|
12
|
+
function isSafeUsage(_ref) {
|
|
13
|
+
var context = _ref.context,
|
|
14
|
+
specifier = _ref.specifier,
|
|
15
|
+
supportedImports = _ref.supportedImports;
|
|
16
|
+
var importName = specifier.imported.name;
|
|
17
|
+
if (!supportedImports.has(importName)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
if (importName === 'css') {
|
|
21
|
+
var css = (0, _findVariable.findVariable)({
|
|
22
|
+
identifier: specifier.local,
|
|
23
|
+
sourceCode: context.getSourceCode()
|
|
24
|
+
});
|
|
25
|
+
return css !== null && isSafeCss(css);
|
|
26
|
+
}
|
|
27
|
+
if (importName === 'keyframes') {
|
|
28
|
+
var keyframes = (0, _findVariable.findVariable)({
|
|
29
|
+
identifier: specifier.local,
|
|
30
|
+
sourceCode: context.getSourceCode()
|
|
31
|
+
});
|
|
32
|
+
return keyframes !== null && isSafeKeyframes(keyframes);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
function isSafeKeyframes(keyframes) {
|
|
37
|
+
return keyframes.references.every(function (ref) {
|
|
38
|
+
var callExpression = (0, _eslintCodemodUtils.closestOfType)(ref.identifier, 'CallExpression');
|
|
39
|
+
if (!callExpression) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (callExpression.callee !== ref.identifier) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (callExpression.arguments.length !== 1) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
var argument = callExpression.arguments[0];
|
|
49
|
+
if (argument.type !== 'ObjectExpression') {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return argument.properties.every(function (property) {
|
|
53
|
+
return isSafeProperty(property, isSafeKeyframePropertyValue);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function isSafeKeyframePropertyValue(value) {
|
|
58
|
+
if (value.type !== 'ObjectExpression') {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return isSafeStyleObject(value);
|
|
62
|
+
}
|
|
63
|
+
function isSafeCss(css) {
|
|
64
|
+
return css.references.every(function (ref) {
|
|
65
|
+
var callExpression = (0, _eslintCodemodUtils.closestOfType)(ref.identifier, 'CallExpression');
|
|
66
|
+
if (!callExpression) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
if (callExpression.callee !== ref.identifier) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
return callExpression.arguments.every(isSafeStyleArgument);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function isSafeStyled(styled) {
|
|
76
|
+
return styled.references.every(function (ref) {
|
|
77
|
+
var callExpression = (0, _eslintCodemodUtils.closestOfType)(ref.identifier, 'CallExpression');
|
|
78
|
+
if (!callExpression) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* If it's not in the form `styled.tagName()`
|
|
84
|
+
* then we consider it unsafe to auto-fix.
|
|
85
|
+
*/
|
|
86
|
+
if (callExpression.callee.type !== 'MemberExpression' || callExpression.callee.object !== ref.identifier) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return callExpression.arguments.every(isSafeStyleArgument);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Determines if a style argument is safe for auto-fix conversion.
|
|
95
|
+
*/
|
|
96
|
+
function isSafeStyleArgument(arg) {
|
|
97
|
+
if (arg.type === 'ObjectExpression') {
|
|
98
|
+
return isSafeStyleObject(arg);
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
function isSafeStyleObject(object) {
|
|
103
|
+
return object.properties.every(function (property) {
|
|
104
|
+
return isSafeProperty(property, isSafeStyleValue);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function isSafeStyleValue(value) {
|
|
108
|
+
if (value.type === 'Literal') {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
function isSafeProperty(property, isSafePropertyValue) {
|
|
114
|
+
if (property.type === 'SpreadElement') {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (property.method || property.shorthand || property.kind !== 'init') {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (!hasSafeKey(property)) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return isSafePropertyValue(property.value);
|
|
124
|
+
}
|
|
125
|
+
function hasSafeKey(property) {
|
|
126
|
+
if (property.computed) {
|
|
127
|
+
return property.key.type === 'Literal';
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFirstImportFromSource = getFirstImportFromSource;
|
|
7
|
+
exports.isImportDefaultSpecifier = isImportDefaultSpecifier;
|
|
8
|
+
exports.isImportNamespaceSpecifier = isImportNamespaceSpecifier;
|
|
9
|
+
exports.isImportSpecifier = isImportSpecifier;
|
|
10
|
+
function getFirstImportFromSource(context, source) {
|
|
11
|
+
return context.getSourceCode().ast.body.filter(isImportDeclaration).find(function (node) {
|
|
12
|
+
return node.source.value === source;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
function isImportDeclaration(node) {
|
|
16
|
+
return node.type === 'ImportDeclaration';
|
|
17
|
+
}
|
|
18
|
+
function isImportSpecifier(specifier) {
|
|
19
|
+
return specifier.type === 'ImportSpecifier';
|
|
20
|
+
}
|
|
21
|
+
function isImportDefaultSpecifier(specifier) {
|
|
22
|
+
return specifier.type === 'ImportDefaultSpecifier';
|
|
23
|
+
}
|
|
24
|
+
function isImportNamespaceSpecifier(specifier) {
|
|
25
|
+
return specifier.type === 'ImportNamespaceSpecifier';
|
|
26
|
+
}
|
|
@@ -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::16a3441765e5a97f9f32de7fd0de17f0>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import all from './presets/all.codegen';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::752a442dd46681814ab73f7fa9c05374>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
|
|
9
10
|
'@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
|
|
10
11
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
@@ -18,6 +19,7 @@ export default {
|
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
21
23
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
22
24
|
excludeReactComponents: true
|
|
23
25
|
}],
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::752a442dd46681814ab73f7fa9c05374>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
|
|
9
10
|
'@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
|
|
10
11
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
@@ -18,6 +19,7 @@ export default {
|
|
|
18
19
|
'@atlaskit/ui-styling-standard/no-imported-style-values': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-unsafe-values': 'warn',
|
|
22
|
+
'@atlaskit/ui-styling-standard/use-compiled': 'warn',
|
|
21
23
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
22
24
|
excludeReactComponents: true
|
|
23
25
|
}],
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
const isIdentifierReferenced = (hasImportSpecifier, node, references) => references.some(reference => {
|
|
4
|
+
var _reference$resolved;
|
|
5
|
+
return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(hasImportSpecifier));
|
|
6
|
+
});
|
|
7
|
+
const isTypographyImportSpecifier = def => {
|
|
8
|
+
var _def$parent, _def$parent2, _def$parent3;
|
|
9
|
+
return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && (def.node.imported.name === 'typography' && ((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value) === '@atlaskit/theme' || ((_def$parent3 = def.parent) === null || _def$parent3 === void 0 ? void 0 : _def$parent3.source.value) === '@atlaskit/theme/typography');
|
|
10
|
+
};
|
|
11
|
+
const isElevationImportSpecifier = def => {
|
|
12
|
+
var _def$parent4, _def$parent5, _def$parent6;
|
|
13
|
+
return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent4 = def.parent) === null || _def$parent4 === void 0 ? void 0 : _def$parent4.type) === 'ImportDeclaration' && (def.node.imported.name === 'elevation' && ((_def$parent5 = def.parent) === null || _def$parent5 === void 0 ? void 0 : _def$parent5.source.value) === '@atlaskit/theme' || ((_def$parent6 = def.parent) === null || _def$parent6 === void 0 ? void 0 : _def$parent6.source.value) === '@atlaskit/theme/elevation');
|
|
14
|
+
};
|
|
15
|
+
const isSkeletonShimmerImportSpecifier = def => {
|
|
16
|
+
var _def$parent7, _def$parent8, _def$parent9, _def$parent9$source$v;
|
|
17
|
+
return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent7 = def.parent) === null || _def$parent7 === void 0 ? void 0 : _def$parent7.type) === 'ImportDeclaration' && def.node.imported.name === 'skeletonShimmer' && typeof ((_def$parent8 = def.parent) === null || _def$parent8 === void 0 ? void 0 : _def$parent8.source.value) === 'string' && ((_def$parent9 = def.parent) === null || _def$parent9 === void 0 ? void 0 : (_def$parent9$source$v = _def$parent9.source.value) === null || _def$parent9$source$v === void 0 ? void 0 : _def$parent9$source$v.startsWith('@atlaskit/theme'));
|
|
18
|
+
};
|
|
19
|
+
const checkIdentifier = (node, context, references) => {
|
|
20
|
+
if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
|
|
21
|
+
context.report({
|
|
22
|
+
messageId: 'usingTypography',
|
|
23
|
+
node
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
|
|
27
|
+
context.report({
|
|
28
|
+
messageId: 'usingElevation',
|
|
29
|
+
node
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)) {
|
|
33
|
+
context.report({
|
|
34
|
+
messageId: 'usingSkeletonShimmer',
|
|
35
|
+
node
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export const rule = createLintRule({
|
|
40
|
+
meta: {
|
|
41
|
+
name: 'atlaskit-theme',
|
|
42
|
+
docs: {
|
|
43
|
+
description: 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
|
|
44
|
+
recommended: true,
|
|
45
|
+
severity: 'error'
|
|
46
|
+
},
|
|
47
|
+
messages: {
|
|
48
|
+
usingTypography: 'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
|
|
49
|
+
usingElevation: 'Elevation does not work with Compiled. Please use a token with a fallback instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
|
|
50
|
+
usingSkeletonShimmer: 'Skeleton Shimmer does not work with Compiled. Please use an SVG skeleton instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage'
|
|
51
|
+
},
|
|
52
|
+
schema: [],
|
|
53
|
+
type: 'problem'
|
|
54
|
+
},
|
|
55
|
+
create(context) {
|
|
56
|
+
const importSources = getImportSources(context);
|
|
57
|
+
return {
|
|
58
|
+
'CallExpression Identifier': node => {
|
|
59
|
+
const {
|
|
60
|
+
references
|
|
61
|
+
} = context.getScope();
|
|
62
|
+
const ancestors = context.getAncestors();
|
|
63
|
+
|
|
64
|
+
// Check if ancestor node is a call expression to Compiled
|
|
65
|
+
if (ancestors.some(ancestor => ancestor.type === 'CallExpression' && ancestor.callee && isCompiled(ancestor.callee, references, importSources))) {
|
|
66
|
+
// Check identifier for violations
|
|
67
|
+
checkIdentifier(node, context, references);
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
'TaggedTemplateExpression Identifier': node => {
|
|
71
|
+
const {
|
|
72
|
+
references
|
|
73
|
+
} = context.getScope();
|
|
74
|
+
const ancestors = context.getAncestors();
|
|
75
|
+
|
|
76
|
+
// Check if ancestor node is a tagged template expression to Compiled
|
|
77
|
+
if (ancestors.some(ancestor => ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && isCompiled(ancestor.tag, references, importSources))) {
|
|
78
|
+
// Check identifier for violations
|
|
79
|
+
checkIdentifier(node, context, references);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
export default rule;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::be177a361ddc1a7a41d843680299e318>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
|
+
import atlaskitTheme from './atlaskit-theme';
|
|
6
7
|
import convertPropsSyntax from './convert-props-syntax';
|
|
7
8
|
import enforceStyleProp from './enforce-style-prop';
|
|
8
9
|
import localCxXcss from './local-cx-xcss';
|
|
@@ -15,7 +16,9 @@ import noImportantStyles from './no-important-styles';
|
|
|
15
16
|
import noImportedStyleValues from './no-imported-style-values';
|
|
16
17
|
import noNestedSelectors from './no-nested-selectors';
|
|
17
18
|
import noUnsafeValues from './no-unsafe-values';
|
|
19
|
+
import useCompiled from './use-compiled';
|
|
18
20
|
export default {
|
|
21
|
+
'atlaskit-theme': atlaskitTheme,
|
|
19
22
|
'convert-props-syntax': convertPropsSyntax,
|
|
20
23
|
'enforce-style-prop': enforceStyleProp,
|
|
21
24
|
'local-cx-xcss': localCxXcss,
|
|
@@ -27,5 +30,6 @@ export default {
|
|
|
27
30
|
'no-important-styles': noImportantStyles,
|
|
28
31
|
'no-imported-style-values': noImportedStyleValues,
|
|
29
32
|
'no-nested-selectors': noNestedSelectors,
|
|
30
|
-
'no-unsafe-values': noUnsafeValues
|
|
33
|
+
'no-unsafe-values': noUnsafeValues,
|
|
34
|
+
'use-compiled': useCompiled
|
|
31
35
|
};
|