@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,182 @@
|
|
|
1
|
+
import { identifier, importDeclaration, importSpecifier, literal } from 'eslint-codemod-utils';
|
|
2
|
+
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
3
|
+
import { createLintRule } from '../utils/create-rule';
|
|
4
|
+
import { getFirstImportFromSource, isImportDefaultSpecifier, isImportNamespaceSpecifier, isImportSpecifier } from './utils';
|
|
5
|
+
import { isSafeStyled, isSafeUsage } from './is-safe';
|
|
6
|
+
const SUPPORTED_EMOTION_IMPORTS = new Set(['css', 'keyframes', 'ClassNames', 'jsx']);
|
|
7
|
+
const SUPPORTED_IMPORT_MAP = {
|
|
8
|
+
'@emotion/core': SUPPORTED_EMOTION_IMPORTS,
|
|
9
|
+
'@emotion/react': SUPPORTED_EMOTION_IMPORTS,
|
|
10
|
+
'@emotion/styled': new Set(['default']),
|
|
11
|
+
'styled-components': new Set(['default', 'css', 'keyframes'])
|
|
12
|
+
};
|
|
13
|
+
function isSupportedImportSource(importSource) {
|
|
14
|
+
return importSource in SUPPORTED_IMPORT_MAP;
|
|
15
|
+
}
|
|
16
|
+
const schema = {
|
|
17
|
+
type: 'array',
|
|
18
|
+
items: [{
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
canAutoFix: {
|
|
22
|
+
type: 'boolean'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
additionalProperties: false
|
|
26
|
+
}]
|
|
27
|
+
};
|
|
28
|
+
const defaultConfig = {
|
|
29
|
+
canAutoFix: false
|
|
30
|
+
};
|
|
31
|
+
function readConfig(context) {
|
|
32
|
+
const [config] = context.options;
|
|
33
|
+
return Object.assign({}, defaultConfig, config);
|
|
34
|
+
}
|
|
35
|
+
export const rule = createLintRule({
|
|
36
|
+
meta: {
|
|
37
|
+
name: 'use-compiled',
|
|
38
|
+
type: 'problem',
|
|
39
|
+
fixable: 'code',
|
|
40
|
+
docs: {
|
|
41
|
+
description: 'Ensures usage of `@compiled/react` instead of other CSS-in-JS libraries',
|
|
42
|
+
recommended: true,
|
|
43
|
+
severity: 'warn'
|
|
44
|
+
},
|
|
45
|
+
messages: {
|
|
46
|
+
'use-compiled': `Use '@compiled/react' instead of '{{importSource}}'`
|
|
47
|
+
},
|
|
48
|
+
schema
|
|
49
|
+
},
|
|
50
|
+
create(context) {
|
|
51
|
+
const config = readConfig(context);
|
|
52
|
+
return {
|
|
53
|
+
Program() {
|
|
54
|
+
const pragma = context.getSourceCode().getAllComments().find(n => n.value.includes('@jsxImportSource @emotion/react'));
|
|
55
|
+
if (!pragma) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
context.report({
|
|
59
|
+
messageId: 'use-compiled',
|
|
60
|
+
data: {
|
|
61
|
+
importSource: '@emotion/react'
|
|
62
|
+
},
|
|
63
|
+
loc: pragma.loc,
|
|
64
|
+
*fix(fixer) {
|
|
65
|
+
if (!config.canAutoFix) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const importDeclarations = context.getSourceCode().ast.body.filter(node => node.type === 'ImportDeclaration');
|
|
69
|
+
const hasEmotionImport = importDeclarations.some(importDeclaration => {
|
|
70
|
+
const importSource = importDeclaration.source.value;
|
|
71
|
+
return importSource.startsWith('@emotion/');
|
|
72
|
+
});
|
|
73
|
+
const hasCompiledImport = importDeclarations.some(importDeclaration => importDeclaration.source.value === '@compiled/react');
|
|
74
|
+
if (hasEmotionImport || !hasCompiledImport) {
|
|
75
|
+
// Considering this unsafe to auto-fix
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
yield fixer.replaceText(
|
|
79
|
+
// @ts-expect-error - types don't accept comment nodes
|
|
80
|
+
pragma, `/** @jsxImportSource @compiled/react */`);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
ImportDeclaration(node) {
|
|
85
|
+
const importSource = node.source.value;
|
|
86
|
+
if (!isSupportedImportSource(importSource)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
context.report({
|
|
90
|
+
node: node.source,
|
|
91
|
+
messageId: 'use-compiled',
|
|
92
|
+
data: {
|
|
93
|
+
importSource
|
|
94
|
+
},
|
|
95
|
+
*fix(fixer) {
|
|
96
|
+
if (!config.canAutoFix) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const specifiers = getSpecifiers({
|
|
100
|
+
context,
|
|
101
|
+
node,
|
|
102
|
+
importSource
|
|
103
|
+
});
|
|
104
|
+
if (!specifiers) {
|
|
105
|
+
// Cannot safely auto-fix
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
yield* fixImport({
|
|
109
|
+
context,
|
|
110
|
+
fixer,
|
|
111
|
+
node,
|
|
112
|
+
specifiers
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
export default rule;
|
|
121
|
+
function getSpecifiers({
|
|
122
|
+
context,
|
|
123
|
+
node,
|
|
124
|
+
importSource
|
|
125
|
+
}) {
|
|
126
|
+
const supportedImports = SUPPORTED_IMPORT_MAP[importSource];
|
|
127
|
+
|
|
128
|
+
// We aren't supporting namespace imports
|
|
129
|
+
if (node.specifiers.some(isImportNamespaceSpecifier)) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const defaultSpecifier = node.specifiers.find(isImportDefaultSpecifier);
|
|
133
|
+
if (defaultSpecifier) {
|
|
134
|
+
if (!supportedImports.has('default')) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const styled = findVariable({
|
|
138
|
+
identifier: defaultSpecifier.local,
|
|
139
|
+
sourceCode: context.getSourceCode()
|
|
140
|
+
});
|
|
141
|
+
if (!styled || !isSafeStyled(styled)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const namedSpecifiers = node.specifiers.filter(isImportSpecifier);
|
|
146
|
+
if (!namedSpecifiers.every(specifier => isSafeUsage({
|
|
147
|
+
context,
|
|
148
|
+
specifier,
|
|
149
|
+
supportedImports
|
|
150
|
+
}))) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (defaultSpecifier) {
|
|
154
|
+
return [...namedSpecifiers,
|
|
155
|
+
// ASSUMPTION: the default import, if allowed, is for `styled`
|
|
156
|
+
importSpecifier({
|
|
157
|
+
imported: identifier('styled'),
|
|
158
|
+
local: node.specifiers[0].local
|
|
159
|
+
})];
|
|
160
|
+
}
|
|
161
|
+
return namedSpecifiers;
|
|
162
|
+
}
|
|
163
|
+
function* fixImport({
|
|
164
|
+
context,
|
|
165
|
+
fixer,
|
|
166
|
+
node,
|
|
167
|
+
specifiers
|
|
168
|
+
}) {
|
|
169
|
+
const compiledImport = getFirstImportFromSource(context, '@compiled/react');
|
|
170
|
+
if (compiledImport) {
|
|
171
|
+
yield fixer.remove(node);
|
|
172
|
+
yield fixer.replaceText(compiledImport, buildImportDeclaration(compiledImport.specifiers.concat(specifiers), '@compiled/react'));
|
|
173
|
+
} else {
|
|
174
|
+
yield fixer.replaceText(node, buildImportDeclaration(specifiers, '@compiled/react'));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function buildImportDeclaration(specifiers, source) {
|
|
178
|
+
return `${importDeclaration({
|
|
179
|
+
specifiers,
|
|
180
|
+
source: literal(source)
|
|
181
|
+
})};`;
|
|
182
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { closestOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
3
|
+
export function isSafeUsage({
|
|
4
|
+
context,
|
|
5
|
+
specifier,
|
|
6
|
+
supportedImports
|
|
7
|
+
}) {
|
|
8
|
+
const importName = specifier.imported.name;
|
|
9
|
+
if (!supportedImports.has(importName)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
if (importName === 'css') {
|
|
13
|
+
const css = findVariable({
|
|
14
|
+
identifier: specifier.local,
|
|
15
|
+
sourceCode: context.getSourceCode()
|
|
16
|
+
});
|
|
17
|
+
return css !== null && isSafeCss(css);
|
|
18
|
+
}
|
|
19
|
+
if (importName === 'keyframes') {
|
|
20
|
+
const keyframes = findVariable({
|
|
21
|
+
identifier: specifier.local,
|
|
22
|
+
sourceCode: context.getSourceCode()
|
|
23
|
+
});
|
|
24
|
+
return keyframes !== null && isSafeKeyframes(keyframes);
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
export function isSafeKeyframes(keyframes) {
|
|
29
|
+
return keyframes.references.every(ref => {
|
|
30
|
+
const callExpression = closestOfType(ref.identifier, 'CallExpression');
|
|
31
|
+
if (!callExpression) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (callExpression.callee !== ref.identifier) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (callExpression.arguments.length !== 1) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const argument = callExpression.arguments[0];
|
|
41
|
+
if (argument.type !== 'ObjectExpression') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
return argument.properties.every(property => isSafeProperty(property, isSafeKeyframePropertyValue));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function isSafeKeyframePropertyValue(value) {
|
|
48
|
+
if (value.type !== 'ObjectExpression') {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
return isSafeStyleObject(value);
|
|
52
|
+
}
|
|
53
|
+
export function isSafeCss(css) {
|
|
54
|
+
return css.references.every(ref => {
|
|
55
|
+
const callExpression = closestOfType(ref.identifier, 'CallExpression');
|
|
56
|
+
if (!callExpression) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (callExpression.callee !== ref.identifier) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return callExpression.arguments.every(isSafeStyleArgument);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
export function isSafeStyled(styled) {
|
|
66
|
+
return styled.references.every(ref => {
|
|
67
|
+
const callExpression = closestOfType(ref.identifier, 'CallExpression');
|
|
68
|
+
if (!callExpression) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* If it's not in the form `styled.tagName()`
|
|
74
|
+
* then we consider it unsafe to auto-fix.
|
|
75
|
+
*/
|
|
76
|
+
if (callExpression.callee.type !== 'MemberExpression' || callExpression.callee.object !== ref.identifier) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return callExpression.arguments.every(isSafeStyleArgument);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Determines if a style argument is safe for auto-fix conversion.
|
|
85
|
+
*/
|
|
86
|
+
function isSafeStyleArgument(arg) {
|
|
87
|
+
if (arg.type === 'ObjectExpression') {
|
|
88
|
+
return isSafeStyleObject(arg);
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
function isSafeStyleObject(object) {
|
|
93
|
+
return object.properties.every(property => isSafeProperty(property, isSafeStyleValue));
|
|
94
|
+
}
|
|
95
|
+
function isSafeStyleValue(value) {
|
|
96
|
+
if (value.type === 'Literal') {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
function isSafeProperty(property, isSafePropertyValue) {
|
|
102
|
+
if (property.type === 'SpreadElement') {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
if (property.method || property.shorthand || property.kind !== 'init') {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (!hasSafeKey(property)) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return isSafePropertyValue(property.value);
|
|
112
|
+
}
|
|
113
|
+
function hasSafeKey(property) {
|
|
114
|
+
if (property.computed) {
|
|
115
|
+
return property.key.type === 'Literal';
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function getFirstImportFromSource(context, source) {
|
|
2
|
+
return context.getSourceCode().ast.body.filter(isImportDeclaration).find(node => node.source.value === source);
|
|
3
|
+
}
|
|
4
|
+
function isImportDeclaration(node) {
|
|
5
|
+
return node.type === 'ImportDeclaration';
|
|
6
|
+
}
|
|
7
|
+
export function isImportSpecifier(specifier) {
|
|
8
|
+
return specifier.type === 'ImportSpecifier';
|
|
9
|
+
}
|
|
10
|
+
export function isImportDefaultSpecifier(specifier) {
|
|
11
|
+
return specifier.type === 'ImportDefaultSpecifier';
|
|
12
|
+
}
|
|
13
|
+
export function isImportNamespaceSpecifier(specifier) {
|
|
14
|
+
return specifier.type === 'ImportNamespaceSpecifier';
|
|
15
|
+
}
|
|
@@ -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,89 @@
|
|
|
1
|
+
import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
var isIdentifierReferenced = function isIdentifierReferenced(hasImportSpecifier, node, references) {
|
|
4
|
+
return references.some(function (reference) {
|
|
5
|
+
var _reference$resolved;
|
|
6
|
+
return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(hasImportSpecifier));
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
var isTypographyImportSpecifier = function isTypographyImportSpecifier(def) {
|
|
10
|
+
var _def$parent, _def$parent2, _def$parent3;
|
|
11
|
+
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');
|
|
12
|
+
};
|
|
13
|
+
var isElevationImportSpecifier = function isElevationImportSpecifier(def) {
|
|
14
|
+
var _def$parent4, _def$parent5, _def$parent6;
|
|
15
|
+
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');
|
|
16
|
+
};
|
|
17
|
+
var isSkeletonShimmerImportSpecifier = function isSkeletonShimmerImportSpecifier(def) {
|
|
18
|
+
var _def$parent7, _def$parent8, _def$parent9;
|
|
19
|
+
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 || (_def$parent9 = _def$parent9.source.value) === null || _def$parent9 === void 0 ? void 0 : _def$parent9.startsWith('@atlaskit/theme'));
|
|
20
|
+
};
|
|
21
|
+
var checkIdentifier = function checkIdentifier(node, context, references) {
|
|
22
|
+
if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
|
|
23
|
+
context.report({
|
|
24
|
+
messageId: 'usingTypography',
|
|
25
|
+
node: node
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
|
|
29
|
+
context.report({
|
|
30
|
+
messageId: 'usingElevation',
|
|
31
|
+
node: node
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)) {
|
|
35
|
+
context.report({
|
|
36
|
+
messageId: 'usingSkeletonShimmer',
|
|
37
|
+
node: node
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export var rule = createLintRule({
|
|
42
|
+
meta: {
|
|
43
|
+
name: 'atlaskit-theme',
|
|
44
|
+
docs: {
|
|
45
|
+
description: 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
|
|
46
|
+
recommended: true,
|
|
47
|
+
severity: 'error'
|
|
48
|
+
},
|
|
49
|
+
messages: {
|
|
50
|
+
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',
|
|
51
|
+
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',
|
|
52
|
+
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'
|
|
53
|
+
},
|
|
54
|
+
schema: [],
|
|
55
|
+
type: 'problem'
|
|
56
|
+
},
|
|
57
|
+
create: function create(context) {
|
|
58
|
+
var importSources = getImportSources(context);
|
|
59
|
+
return {
|
|
60
|
+
'CallExpression Identifier': function CallExpressionIdentifier(node) {
|
|
61
|
+
var _context$getScope = context.getScope(),
|
|
62
|
+
references = _context$getScope.references;
|
|
63
|
+
var ancestors = context.getAncestors();
|
|
64
|
+
|
|
65
|
+
// Check if ancestor node is a call expression to Compiled
|
|
66
|
+
if (ancestors.some(function (ancestor) {
|
|
67
|
+
return ancestor.type === 'CallExpression' && ancestor.callee && isCompiled(ancestor.callee, references, importSources);
|
|
68
|
+
})) {
|
|
69
|
+
// Check identifier for violations
|
|
70
|
+
checkIdentifier(node, context, references);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
'TaggedTemplateExpression Identifier': function TaggedTemplateExpressionIdentifier(node) {
|
|
74
|
+
var _context$getScope2 = context.getScope(),
|
|
75
|
+
references = _context$getScope2.references;
|
|
76
|
+
var ancestors = context.getAncestors();
|
|
77
|
+
|
|
78
|
+
// Check if ancestor node is a tagged template expression to Compiled
|
|
79
|
+
if (ancestors.some(function (ancestor) {
|
|
80
|
+
return ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && isCompiled(ancestor.tag, references, importSources);
|
|
81
|
+
})) {
|
|
82
|
+
// Check identifier for violations
|
|
83
|
+
checkIdentifier(node, context, references);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
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
|
};
|