@atlaskit/eslint-plugin-ui-styling-standard 2.1.8 → 2.1.10
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 +18 -0
- package/README.md +1 -1
- package/dist/cjs/index.codegen.js +2 -2
- package/dist/cjs/presets/all-flat.codegen.js +2 -2
- package/dist/cjs/presets/all.codegen.js +2 -2
- package/dist/cjs/presets/recommended-flat.codegen.js +2 -2
- package/dist/cjs/presets/recommended.codegen.js +2 -2
- package/dist/cjs/rules/atlaskit-theme/index.js +159 -52
- package/dist/cjs/rules/index.codegen.js +2 -2
- package/dist/cjs/rules/no-unsafe-selectors/index.js +99 -14
- package/dist/cjs/rules/no-unsafe-values/utils.js +6 -2
- package/dist/es2019/index.codegen.js +2 -2
- package/dist/es2019/presets/all-flat.codegen.js +2 -2
- package/dist/es2019/presets/all.codegen.js +2 -2
- package/dist/es2019/presets/recommended-flat.codegen.js +2 -2
- package/dist/es2019/presets/recommended.codegen.js +2 -2
- package/dist/es2019/rules/atlaskit-theme/index.js +117 -50
- package/dist/es2019/rules/index.codegen.js +2 -2
- package/dist/es2019/rules/no-unsafe-selectors/index.js +69 -2
- package/dist/es2019/rules/no-unsafe-values/utils.js +6 -2
- package/dist/esm/index.codegen.js +2 -2
- package/dist/esm/presets/all-flat.codegen.js +2 -2
- package/dist/esm/presets/all.codegen.js +2 -2
- package/dist/esm/presets/recommended-flat.codegen.js +2 -2
- package/dist/esm/presets/recommended.codegen.js +2 -2
- package/dist/esm/rules/atlaskit-theme/index.js +159 -53
- package/dist/esm/rules/index.codegen.js +2 -2
- package/dist/esm/rules/no-unsafe-selectors/index.js +99 -14
- package/dist/esm/rules/no-unsafe-values/utils.js +6 -2
- package/dist/types/index.codegen.d.ts +2 -2
- package/dist/types/presets/all-flat.codegen.d.ts +2 -2
- package/dist/types/presets/all.codegen.d.ts +2 -2
- package/dist/types/presets/recommended-flat.codegen.d.ts +2 -2
- package/dist/types/presets/recommended.codegen.d.ts +2 -2
- package/dist/types/rules/index.codegen.d.ts +2 -2
- package/package.json +2 -2
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
2
|
import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
3
|
import { createLintRule } from '../utils/create-rule';
|
|
4
|
-
const isIdentifierReferenced = (hasImportSpecifier, node, references) => references.some(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
4
|
const isTypographyImportSpecifier = def => {
|
|
9
5
|
var _def$parent, _def$parent2, _def$parent3;
|
|
10
6
|
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');
|
|
@@ -17,26 +13,79 @@ const isSkeletonShimmerImportSpecifier = def => {
|
|
|
17
13
|
var _def$parent7, _def$parent8, _def$parent9, _def$parent9$source$v;
|
|
18
14
|
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'));
|
|
19
15
|
};
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const bannedImportChecks = [{
|
|
17
|
+
messageId: 'usingTypography',
|
|
18
|
+
isBanned: isTypographyImportSpecifier
|
|
19
|
+
}, {
|
|
20
|
+
messageId: 'usingElevation',
|
|
21
|
+
isBanned: isElevationImportSpecifier
|
|
22
|
+
}, {
|
|
23
|
+
messageId: 'usingSkeletonShimmer',
|
|
24
|
+
isBanned: isSkeletonShimmerImportSpecifier
|
|
25
|
+
}];
|
|
26
|
+
function isAstNode(value) {
|
|
27
|
+
return typeof value === 'object' && value !== null && 'type' in value && typeof value.type === 'string';
|
|
28
|
+
}
|
|
29
|
+
function hasBannedThemeImport(sourceCode) {
|
|
30
|
+
for (const statement of sourceCode.ast.body) {
|
|
31
|
+
if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const source = statement.source.value;
|
|
35
|
+
if (!source.startsWith('@atlaskit/theme')) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
for (const specifier of statement.specifiers) {
|
|
39
|
+
if (specifier.type !== 'ImportSpecifier' || specifier.imported.type !== 'Identifier') {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const {
|
|
43
|
+
name
|
|
44
|
+
} = specifier.imported;
|
|
45
|
+
if (source === '@atlaskit/theme/typography' || source === '@atlaskit/theme/elevation') {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (source === '@atlaskit/theme' && (name === 'typography' || name === 'elevation')) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (name === 'skeletonShimmer') {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
26
55
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
function visitIdentifiers(node, visit) {
|
|
59
|
+
if (node.type === 'Identifier' && 'name' in node && typeof node.name === 'string') {
|
|
60
|
+
visit(node);
|
|
32
61
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
62
|
+
for (const key of Object.keys(node)) {
|
|
63
|
+
if (key === 'parent') {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const value = node[key];
|
|
67
|
+
if (Array.isArray(value)) {
|
|
68
|
+
for (const child of value) {
|
|
69
|
+
if (isAstNode(child)) {
|
|
70
|
+
visitIdentifiers(child, visit);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else if (isAstNode(value)) {
|
|
74
|
+
visitIdentifiers(value, visit);
|
|
75
|
+
}
|
|
38
76
|
}
|
|
39
|
-
}
|
|
77
|
+
}
|
|
78
|
+
function findReferencedVariable(scope, identifier) {
|
|
79
|
+
let current = scope;
|
|
80
|
+
while (current) {
|
|
81
|
+
const variable = current.set.get(identifier.name);
|
|
82
|
+
if (variable !== null && variable !== void 0 && variable.references.some(reference => reference.identifier === identifier)) {
|
|
83
|
+
return variable;
|
|
84
|
+
}
|
|
85
|
+
current = current.upper;
|
|
86
|
+
}
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
40
89
|
const rule = createLintRule({
|
|
41
90
|
meta: {
|
|
42
91
|
name: 'atlaskit-theme',
|
|
@@ -54,39 +103,57 @@ const rule = createLintRule({
|
|
|
54
103
|
type: 'problem'
|
|
55
104
|
},
|
|
56
105
|
create(context) {
|
|
106
|
+
const sourceCode = getSourceCode(context);
|
|
107
|
+
if (!hasBannedThemeImport(sourceCode)) {
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
57
110
|
const importSources = getImportSources(context);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
111
|
+
const reported = new WeakSet();
|
|
112
|
+
const reportBannedIdentifier = (identifier, scope) => {
|
|
113
|
+
if (identifier.name === 'fontFallback' || reported.has(identifier)) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const variable = findReferencedVariable(scope, identifier);
|
|
117
|
+
if (!variable) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let didReport = false;
|
|
121
|
+
for (const {
|
|
122
|
+
messageId,
|
|
123
|
+
isBanned
|
|
124
|
+
} of bannedImportChecks) {
|
|
125
|
+
if (variable.defs.some(isBanned)) {
|
|
126
|
+
context.report({
|
|
127
|
+
messageId,
|
|
128
|
+
node: identifier
|
|
129
|
+
});
|
|
130
|
+
didReport = true;
|
|
72
131
|
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
132
|
+
}
|
|
133
|
+
if (didReport) {
|
|
134
|
+
reported.add(identifier);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const lintCompiledInvocation = node => {
|
|
138
|
+
if (node.type !== 'CallExpression' && node.type !== 'TaggedTemplateExpression') {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const calleeOrTag = node.type === 'CallExpression' ? node.callee : node.tag;
|
|
142
|
+
const scope = getScope(context, node);
|
|
143
|
+
if (!isCompiled(calleeOrTag, scope.references, importSources)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const roots = node.type === 'CallExpression' ? node.arguments : node.quasi.expressions;
|
|
147
|
+
for (const root of roots) {
|
|
148
|
+
if (isAstNode(root)) {
|
|
149
|
+
visitIdentifiers(root, identifier => reportBannedIdentifier(identifier, scope));
|
|
87
150
|
}
|
|
88
151
|
}
|
|
89
152
|
};
|
|
153
|
+
return {
|
|
154
|
+
CallExpression: lintCompiledInvocation,
|
|
155
|
+
TaggedTemplateExpression: lintCompiledInvocation
|
|
156
|
+
};
|
|
90
157
|
}
|
|
91
158
|
});
|
|
92
159
|
export default rule;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
4
|
-
* @codegenCommand
|
|
3
|
+
* @codegen <<SignedSource::fe6f7ad579eba2900d5adf5ee934c020>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -1,17 +1,65 @@
|
|
|
1
|
+
import { getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
1
2
|
import { importSources } from '@atlaskit/eslint-utils/schema';
|
|
2
3
|
import { createLintRuleWithTypedConfig } from '../utils/create-rule-with-typed-config';
|
|
3
4
|
import { isSimpleSelector } from '../utils/is-simple-selector';
|
|
4
5
|
import { parseSelector } from '../utils/parse-selector';
|
|
5
6
|
import { getStyleCalls } from '../utils/style-calls';
|
|
6
7
|
import { walkStyleCallProperties } from '../utils/walk-style-call-properties';
|
|
8
|
+
import { allowedPseudos } from './constants';
|
|
7
9
|
import { lintSelector } from './lint-selector';
|
|
8
10
|
import { walkCssMapCall } from './walk-css-map';
|
|
9
|
-
import { allowedPseudos } from './constants';
|
|
10
11
|
const ignoredAtRules = new Set(['@container',
|
|
11
12
|
// ignored because it's covered by `no-container-queries`
|
|
12
13
|
'@media',
|
|
13
14
|
// ignored because it's covered by `no-nested-styles`
|
|
14
15
|
'@supports', '@property', '@starting-style']);
|
|
16
|
+
const canonicalMediaQueries = new Map([['media-above-xxs', '@media all'], ['media-above-xs', '@media (min-width: 30rem)'], ['media-above-sm', '@media (min-width: 48rem)'], ['media-above-md', '@media (min-width: 64rem)'], ['media-above-lg', '@media (min-width: 90rem)'], ['media-above-xl', '@media (min-width: 110.5rem)'], ['media-below-xs', '@media not all and (min-width: 30rem)'], ['media-below-sm', '@media not all and (min-width: 48rem)'], ['media-below-md', '@media not all and (min-width: 64rem)'], ['media-below-lg', '@media not all and (min-width: 90rem)'], ['media-below-xl', '@media not all and (min-width: 110.5rem)'], ['media-only-xxs', '@media (min-width: 0rem) and (max-width: 29.99rem)'], ['media-only-xs', '@media (min-width: 30rem) and (max-width: 47.99rem)'], ['media-only-sm', '@media (min-width: 48rem) and (max-width: 63.99rem)'], ['media-only-md', '@media (min-width: 64rem) and (max-width: 89.99rem)'], ['media-only-lg', '@media (min-width: 90rem) and (max-width: 110.49rem)'], ['media-only-xl', '@media (min-width: 110.5rem)'], ['media-dark-mode', '@media (prefers-color-scheme: dark)'], ['media-light-mode', '@media (prefers-color-scheme: light)'], ['media-reduced-motion', '@media (prefers-reduced-motion: reduce)'], ['media-reduced-transparency', '@media (prefers-reduced-transparency: reduce)'], ['media-forced-colors-active', '@media screen and (forced-colors: active)'], ['media-legacy-high-contrast', '@media screen and (-ms-high-contrast: active)'], ['media-forced-colors-or-legacy-high-contrast', '@media screen and (forced-colors: active), screen and (-ms-high-contrast: active)']]);
|
|
17
|
+
const unwrapTypeScriptExpression = node => {
|
|
18
|
+
let expression = node;
|
|
19
|
+
while (expression.type === 'TSAsExpression' || expression.type === 'TSTypeAssertion' || expression.type === 'TSNonNullExpression' || expression.type === 'TSSatisfiesExpression') {
|
|
20
|
+
expression = expression.expression;
|
|
21
|
+
}
|
|
22
|
+
return expression;
|
|
23
|
+
};
|
|
24
|
+
const isCanonicalTypedMediaKey = (node, importedMediaTypes) => {
|
|
25
|
+
if (node.type !== 'TSSatisfiesExpression') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const expression = unwrapTypeScriptExpression(node);
|
|
29
|
+
if (expression.type !== 'Literal' || typeof expression.value !== 'string') {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
let satisfiesExpression = node;
|
|
33
|
+
while (((_satisfiesExpression = satisfiesExpression) === null || _satisfiesExpression === void 0 ? void 0 : _satisfiesExpression.type) === 'TSSatisfiesExpression') {
|
|
34
|
+
var _satisfiesExpression, _satisfiesExpression$, _satisfiesExpression$2, _satisfiesExpression$3;
|
|
35
|
+
const typeName = (_satisfiesExpression$ = satisfiesExpression.typeAnnotation) === null || _satisfiesExpression$ === void 0 ? void 0 : (_satisfiesExpression$2 = _satisfiesExpression$.typeName) === null || _satisfiesExpression$2 === void 0 ? void 0 : _satisfiesExpression$2.name;
|
|
36
|
+
if (((_satisfiesExpression$3 = satisfiesExpression.typeAnnotation) === null || _satisfiesExpression$3 === void 0 ? void 0 : _satisfiesExpression$3.type) === 'TSTypeReference' && typeName) {
|
|
37
|
+
const source = importedMediaTypes.get(typeName);
|
|
38
|
+
if (source && canonicalMediaQueries.get(source) === expression.value) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
satisfiesExpression = satisfiesExpression.expression;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
46
|
+
const getImportedMediaTypeSources = context => {
|
|
47
|
+
const importedMediaTypes = new Map();
|
|
48
|
+
for (const statement of getSourceCode(context).ast.body) {
|
|
49
|
+
if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const match = statement.source.value.match(/^@atlaskit\/css\/at-rules\/(media-[a-z-]+)$/);
|
|
53
|
+
if (match) {
|
|
54
|
+
for (const specifier of statement.specifiers) {
|
|
55
|
+
if (specifier.type === 'ImportDefaultSpecifier') {
|
|
56
|
+
importedMediaTypes.set(specifier.local.name, match[1]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return importedMediaTypes;
|
|
62
|
+
};
|
|
15
63
|
const rule = createLintRuleWithTypedConfig({
|
|
16
64
|
meta: {
|
|
17
65
|
name: 'no-unsafe-selectors',
|
|
@@ -38,6 +86,7 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
38
86
|
'no-keyframes-at-rules': 'Use the CSS-in-JS `keyframes` API instead of `@keyframes` at-rules.',
|
|
39
87
|
'no-restricted-at-rules': '{{atRule}} at-rule is not allowed.',
|
|
40
88
|
'no-grouped-at-rules': 'Do not group at-rules. Write flattened at-rules instead.',
|
|
89
|
+
'no-noncanonical-media-query': 'Use the exact media query represented by the imported @atlaskit/css/at-rules type.',
|
|
41
90
|
/**
|
|
42
91
|
* Suggestion messages
|
|
43
92
|
*/
|
|
@@ -58,6 +107,7 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
58
107
|
create(context, config) {
|
|
59
108
|
return {
|
|
60
109
|
Program() {
|
|
110
|
+
const importedMediaTypes = getImportedMediaTypeSources(context);
|
|
61
111
|
for (const styleCall of getStyleCalls(context)) {
|
|
62
112
|
if (!config.importSources.includes(styleCall.importSource)) {
|
|
63
113
|
continue;
|
|
@@ -85,10 +135,27 @@ const rule = createLintRuleWithTypedConfig({
|
|
|
85
135
|
key,
|
|
86
136
|
value
|
|
87
137
|
}) => {
|
|
88
|
-
|
|
138
|
+
const keyType = key.type;
|
|
139
|
+
if (value.type !== 'ObjectExpression' || keyType !== 'Literal' && keyType !== 'TSSatisfiesExpression') {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (keyType === 'TSSatisfiesExpression') {
|
|
143
|
+
const unwrappedKey = unwrapTypeScriptExpression(key);
|
|
144
|
+
if (unwrappedKey.type === 'Literal' && typeof unwrappedKey.value === 'string') {
|
|
145
|
+
if (unwrappedKey.value.startsWith('@media') && !isCanonicalTypedMediaKey(key, importedMediaTypes)) {
|
|
146
|
+
context.report({
|
|
147
|
+
node: key,
|
|
148
|
+
messageId: 'no-noncanonical-media-query'
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
89
153
|
return;
|
|
90
154
|
}
|
|
91
155
|
const selectorText = key.value;
|
|
156
|
+
if (typeof selectorText !== 'string') {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
92
159
|
if (selectorText.includes('@')) {
|
|
93
160
|
lintAtRule({
|
|
94
161
|
context,
|
|
@@ -95,7 +95,7 @@ export class Linter {
|
|
|
95
95
|
/**
|
|
96
96
|
* Variables can be used if they resolve to a literal.
|
|
97
97
|
*/
|
|
98
|
-
if (initializer.type === 'Literal') {
|
|
98
|
+
if (unwrapSatisfiesExpression(initializer).type === 'Literal') {
|
|
99
99
|
return;
|
|
100
100
|
}
|
|
101
101
|
|
|
@@ -147,7 +147,11 @@ export class Linter {
|
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
isAllowedDynamicKey(expression) {
|
|
150
|
-
var _this$context$sourceC2;
|
|
150
|
+
var _typedExpression$expr, _this$context$sourceC2;
|
|
151
|
+
const typedExpression = expression;
|
|
152
|
+
if (typedExpression.type === 'TSSatisfiesExpression' && ((_typedExpression$expr = typedExpression.expression) === null || _typedExpression$expr === void 0 ? void 0 : _typedExpression$expr.type) === 'Literal' && typeof typedExpression.expression.value === 'string') {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
151
155
|
const identifier = findIdentifierNode(expression);
|
|
152
156
|
if (!identifier) {
|
|
153
157
|
return false;
|
|
@@ -3,8 +3,8 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
3
|
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) { _defineProperty(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; }
|
|
4
4
|
/**
|
|
5
5
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
6
|
-
* @codegen <<SignedSource::
|
|
7
|
-
* @codegenCommand
|
|
6
|
+
* @codegen <<SignedSource::ef33ad38180e99be70285ddb225c56b9>>
|
|
7
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import allFlat from './presets/all-flat.codegen';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
4
|
-
* @codegenCommand
|
|
3
|
+
* @codegen <<SignedSource::ff4acc6ff3441b1ae527ac8371a3717b>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as atlaskitDesignSystemPlugin from '@atlaskit/eslint-plugin-design-system';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
4
|
-
* @codegenCommand
|
|
3
|
+
* @codegen <<SignedSource::64e947d21ff9764f69587dd1641711b6>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
var config = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
4
|
-
* @codegenCommand
|
|
3
|
+
* @codegen <<SignedSource::ff4acc6ff3441b1ae527ac8371a3717b>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as atlaskitDesignSystemPlugin from '@atlaskit/eslint-plugin-design-system';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
4
|
-
* @codegenCommand
|
|
3
|
+
* @codegen <<SignedSource::64e947d21ff9764f69587dd1641711b6>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
var config = {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
|
+
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; } } }; }
|
|
3
|
+
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; } }
|
|
4
|
+
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; }
|
|
5
|
+
import { getScope, getSourceCode } from '@atlaskit/eslint-utils/context-compat';
|
|
2
6
|
import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
7
|
import { createLintRule } from '../utils/create-rule';
|
|
4
|
-
var isIdentifierReferenced = function isIdentifierReferenced(hasImportSpecifier, node, references) {
|
|
5
|
-
return references.some(function (reference) {
|
|
6
|
-
var _reference$resolved;
|
|
7
|
-
return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(hasImportSpecifier));
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
8
|
var isTypographyImportSpecifier = function isTypographyImportSpecifier(def) {
|
|
11
9
|
var _def$parent, _def$parent2, _def$parent3;
|
|
12
10
|
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');
|
|
@@ -19,26 +17,107 @@ var isSkeletonShimmerImportSpecifier = function isSkeletonShimmerImportSpecifier
|
|
|
19
17
|
var _def$parent7, _def$parent8, _def$parent9;
|
|
20
18
|
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'));
|
|
21
19
|
};
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
var bannedImportChecks = [{
|
|
21
|
+
messageId: 'usingTypography',
|
|
22
|
+
isBanned: isTypographyImportSpecifier
|
|
23
|
+
}, {
|
|
24
|
+
messageId: 'usingElevation',
|
|
25
|
+
isBanned: isElevationImportSpecifier
|
|
26
|
+
}, {
|
|
27
|
+
messageId: 'usingSkeletonShimmer',
|
|
28
|
+
isBanned: isSkeletonShimmerImportSpecifier
|
|
29
|
+
}];
|
|
30
|
+
function isAstNode(value) {
|
|
31
|
+
return _typeof(value) === 'object' && value !== null && 'type' in value && typeof value.type === 'string';
|
|
32
|
+
}
|
|
33
|
+
function hasBannedThemeImport(sourceCode) {
|
|
34
|
+
var _iterator = _createForOfIteratorHelper(sourceCode.ast.body),
|
|
35
|
+
_step;
|
|
36
|
+
try {
|
|
37
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
38
|
+
var statement = _step.value;
|
|
39
|
+
if (statement.type !== 'ImportDeclaration' || typeof statement.source.value !== 'string') {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
var source = statement.source.value;
|
|
43
|
+
if (!source.startsWith('@atlaskit/theme')) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
var _iterator2 = _createForOfIteratorHelper(statement.specifiers),
|
|
47
|
+
_step2;
|
|
48
|
+
try {
|
|
49
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
50
|
+
var specifier = _step2.value;
|
|
51
|
+
if (specifier.type !== 'ImportSpecifier' || specifier.imported.type !== 'Identifier') {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
var name = specifier.imported.name;
|
|
55
|
+
if (source === '@atlaskit/theme/typography' || source === '@atlaskit/theme/elevation') {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (source === '@atlaskit/theme' && (name === 'typography' || name === 'elevation')) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
if (name === 'skeletonShimmer') {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch (err) {
|
|
66
|
+
_iterator2.e(err);
|
|
67
|
+
} finally {
|
|
68
|
+
_iterator2.f();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
} catch (err) {
|
|
72
|
+
_iterator.e(err);
|
|
73
|
+
} finally {
|
|
74
|
+
_iterator.f();
|
|
28
75
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
function visitIdentifiers(node, visit) {
|
|
79
|
+
if (node.type === 'Identifier' && 'name' in node && typeof node.name === 'string') {
|
|
80
|
+
visit(node);
|
|
34
81
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
82
|
+
for (var _i = 0, _Object$keys = Object.keys(node); _i < _Object$keys.length; _i++) {
|
|
83
|
+
var key = _Object$keys[_i];
|
|
84
|
+
if (key === 'parent') {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
var value = node[key];
|
|
88
|
+
if (Array.isArray(value)) {
|
|
89
|
+
var _iterator3 = _createForOfIteratorHelper(value),
|
|
90
|
+
_step3;
|
|
91
|
+
try {
|
|
92
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
93
|
+
var child = _step3.value;
|
|
94
|
+
if (isAstNode(child)) {
|
|
95
|
+
visitIdentifiers(child, visit);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
_iterator3.e(err);
|
|
100
|
+
} finally {
|
|
101
|
+
_iterator3.f();
|
|
102
|
+
}
|
|
103
|
+
} else if (isAstNode(value)) {
|
|
104
|
+
visitIdentifiers(value, visit);
|
|
105
|
+
}
|
|
40
106
|
}
|
|
41
|
-
}
|
|
107
|
+
}
|
|
108
|
+
function findReferencedVariable(scope, identifier) {
|
|
109
|
+
var current = scope;
|
|
110
|
+
while (current) {
|
|
111
|
+
var variable = current.set.get(identifier.name);
|
|
112
|
+
if (variable !== null && variable !== void 0 && variable.references.some(function (reference) {
|
|
113
|
+
return reference.identifier === identifier;
|
|
114
|
+
})) {
|
|
115
|
+
return variable;
|
|
116
|
+
}
|
|
117
|
+
current = current.upper;
|
|
118
|
+
}
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
42
121
|
var rule = createLintRule({
|
|
43
122
|
meta: {
|
|
44
123
|
name: 'atlaskit-theme',
|
|
@@ -56,41 +135,68 @@ var rule = createLintRule({
|
|
|
56
135
|
type: 'problem'
|
|
57
136
|
},
|
|
58
137
|
create: function create(context) {
|
|
138
|
+
var sourceCode = getSourceCode(context);
|
|
139
|
+
if (!hasBannedThemeImport(sourceCode)) {
|
|
140
|
+
return {};
|
|
141
|
+
}
|
|
59
142
|
var importSources = getImportSources(context);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
143
|
+
var reported = new WeakSet();
|
|
144
|
+
var reportBannedIdentifier = function reportBannedIdentifier(identifier, scope) {
|
|
145
|
+
if (identifier.name === 'fontFallback' || reported.has(identifier)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
var variable = findReferencedVariable(scope, identifier);
|
|
149
|
+
if (!variable) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
var didReport = false;
|
|
153
|
+
for (var _i2 = 0, _bannedImportChecks = bannedImportChecks; _i2 < _bannedImportChecks.length; _i2++) {
|
|
154
|
+
var _bannedImportChecks$_ = _bannedImportChecks[_i2],
|
|
155
|
+
messageId = _bannedImportChecks$_.messageId,
|
|
156
|
+
isBanned = _bannedImportChecks$_.isBanned;
|
|
157
|
+
if (variable.defs.some(isBanned)) {
|
|
158
|
+
context.report({
|
|
159
|
+
messageId: messageId,
|
|
160
|
+
node: identifier
|
|
161
|
+
});
|
|
162
|
+
didReport = true;
|
|
75
163
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
164
|
+
}
|
|
165
|
+
if (didReport) {
|
|
166
|
+
reported.add(identifier);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
var lintCompiledInvocation = function lintCompiledInvocation(node) {
|
|
170
|
+
if (node.type !== 'CallExpression' && node.type !== 'TaggedTemplateExpression') {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
var calleeOrTag = node.type === 'CallExpression' ? node.callee : node.tag;
|
|
174
|
+
var scope = getScope(context, node);
|
|
175
|
+
if (!isCompiled(calleeOrTag, scope.references, importSources)) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
var roots = node.type === 'CallExpression' ? node.arguments : node.quasi.expressions;
|
|
179
|
+
var _iterator4 = _createForOfIteratorHelper(roots),
|
|
180
|
+
_step4;
|
|
181
|
+
try {
|
|
182
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
183
|
+
var root = _step4.value;
|
|
184
|
+
if (isAstNode(root)) {
|
|
185
|
+
visitIdentifiers(root, function (identifier) {
|
|
186
|
+
return reportBannedIdentifier(identifier, scope);
|
|
187
|
+
});
|
|
90
188
|
}
|
|
91
189
|
}
|
|
190
|
+
} catch (err) {
|
|
191
|
+
_iterator4.e(err);
|
|
192
|
+
} finally {
|
|
193
|
+
_iterator4.f();
|
|
92
194
|
}
|
|
93
195
|
};
|
|
196
|
+
return {
|
|
197
|
+
CallExpression: lintCompiledInvocation,
|
|
198
|
+
TaggedTemplateExpression: lintCompiledInvocation
|
|
199
|
+
};
|
|
94
200
|
}
|
|
95
201
|
});
|
|
96
202
|
export default rule;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
4
|
-
* @codegenCommand
|
|
3
|
+
* @codegen <<SignedSource::fe6f7ad579eba2900d5adf5ee934c020>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import atlaskitTheme from './atlaskit-theme';
|