@atlaskit/eslint-plugin-ui-styling-standard 2.1.9 → 2.2.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 +16 -0
- package/README.md +2 -1
- package/dist/cjs/index.codegen.js +2 -2
- package/dist/cjs/presets/all-flat.codegen.js +3 -2
- package/dist/cjs/presets/all.codegen.js +3 -2
- package/dist/cjs/presets/recommended-flat.codegen.js +3 -2
- package/dist/cjs/presets/recommended.codegen.js +3 -2
- package/dist/cjs/rules/atlaskit-theme/index.js +159 -52
- package/dist/cjs/rules/index.codegen.js +4 -2
- package/dist/cjs/rules/no-atlaskit-theme/index.js +34 -0
- package/dist/es2019/index.codegen.js +2 -2
- package/dist/es2019/presets/all-flat.codegen.js +3 -2
- package/dist/es2019/presets/all.codegen.js +3 -2
- package/dist/es2019/presets/recommended-flat.codegen.js +3 -2
- package/dist/es2019/presets/recommended.codegen.js +3 -2
- package/dist/es2019/rules/atlaskit-theme/index.js +117 -50
- package/dist/es2019/rules/index.codegen.js +4 -2
- package/dist/es2019/rules/no-atlaskit-theme/index.js +28 -0
- package/dist/esm/index.codegen.js +2 -2
- package/dist/esm/presets/all-flat.codegen.js +3 -2
- package/dist/esm/presets/all.codegen.js +3 -2
- package/dist/esm/presets/recommended-flat.codegen.js +3 -2
- package/dist/esm/presets/recommended.codegen.js +3 -2
- package/dist/esm/rules/atlaskit-theme/index.js +159 -53
- package/dist/esm/rules/index.codegen.js +4 -2
- package/dist/esm/rules/no-atlaskit-theme/index.js +28 -0
- 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/dist/types/rules/no-atlaskit-theme/index.d.ts +3 -0
- package/package.json +1 -1
|
@@ -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::094f8a058153c7e839c5d98d2718ca4e>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -9,6 +9,7 @@ import convertPropsSyntax from './convert-props-syntax';
|
|
|
9
9
|
import enforceStyleProp from './enforce-style-prop';
|
|
10
10
|
import localCxXcss from './local-cx-xcss';
|
|
11
11
|
import noArrayArguments from './no-array-arguments';
|
|
12
|
+
import noAtlaskitTheme from './no-atlaskit-theme';
|
|
12
13
|
import noClassnameProp from './no-classname-prop';
|
|
13
14
|
import noContainerQueries from './no-container-queries';
|
|
14
15
|
import noDynamicStyles from './no-dynamic-styles';
|
|
@@ -28,6 +29,7 @@ export const rules = {
|
|
|
28
29
|
'enforce-style-prop': enforceStyleProp,
|
|
29
30
|
'local-cx-xcss': localCxXcss,
|
|
30
31
|
'no-array-arguments': noArrayArguments,
|
|
32
|
+
'no-atlaskit-theme': noAtlaskitTheme,
|
|
31
33
|
'no-classname-prop': noClassnameProp,
|
|
32
34
|
'no-container-queries': noContainerQueries,
|
|
33
35
|
'no-dynamic-styles': noDynamicStyles,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
const rule = createLintRule({
|
|
3
|
+
meta: {
|
|
4
|
+
name: 'no-atlaskit-theme',
|
|
5
|
+
docs: {
|
|
6
|
+
description: 'Disallow imports from `@atlaskit/theme`',
|
|
7
|
+
recommended: true,
|
|
8
|
+
severity: 'warn'
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
'no-atlaskit-theme': 'Do not import `@atlaskit/theme`. Use `@atlaskit/tokens` or Atlassian Design System components instead.'
|
|
12
|
+
},
|
|
13
|
+
type: 'problem'
|
|
14
|
+
},
|
|
15
|
+
create(context) {
|
|
16
|
+
return {
|
|
17
|
+
// esquery regexes cannot contain a raw `/`, so the path separator is `\x2F`.
|
|
18
|
+
// Unanchored at the end, so this matches `@atlaskit/theme` and any subpath.
|
|
19
|
+
'ImportDeclaration[source.value=/^@atlaskit\\x2Ftheme(\\x2F|$)/]'(node) {
|
|
20
|
+
context.report({
|
|
21
|
+
node,
|
|
22
|
+
messageId: 'no-atlaskit-theme'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
export default rule;
|
|
@@ -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::7f3972a0198dc6de5194e21d5f32c3b0>>
|
|
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';
|
|
@@ -16,6 +16,7 @@ var config = {
|
|
|
16
16
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
17
17
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
19
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
21
22
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -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::138a044301c208ca5eecc78433523b0b>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
var config = {
|
|
@@ -12,6 +12,7 @@ var config = {
|
|
|
12
12
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
13
13
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'warn',
|
|
15
16
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -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::7f3972a0198dc6de5194e21d5f32c3b0>>
|
|
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';
|
|
@@ -16,6 +16,7 @@ var config = {
|
|
|
16
16
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
17
17
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
18
18
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
19
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'warn',
|
|
19
20
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
20
21
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
21
22
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -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::138a044301c208ca5eecc78433523b0b>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
var config = {
|
|
@@ -12,6 +12,7 @@ var config = {
|
|
|
12
12
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'error',
|
|
13
13
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'error',
|
|
14
14
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'error',
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-atlaskit-theme': 'warn',
|
|
15
16
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'error',
|
|
16
17
|
'@atlaskit/ui-styling-standard/no-container-queries': 'error',
|
|
17
18
|
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'error',
|
|
@@ -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::094f8a058153c7e839c5d98d2718ca4e>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import atlaskitTheme from './atlaskit-theme';
|
|
@@ -9,6 +9,7 @@ import convertPropsSyntax from './convert-props-syntax';
|
|
|
9
9
|
import enforceStyleProp from './enforce-style-prop';
|
|
10
10
|
import localCxXcss from './local-cx-xcss';
|
|
11
11
|
import noArrayArguments from './no-array-arguments';
|
|
12
|
+
import noAtlaskitTheme from './no-atlaskit-theme';
|
|
12
13
|
import noClassnameProp from './no-classname-prop';
|
|
13
14
|
import noContainerQueries from './no-container-queries';
|
|
14
15
|
import noDynamicStyles from './no-dynamic-styles';
|
|
@@ -28,6 +29,7 @@ export var rules = {
|
|
|
28
29
|
'enforce-style-prop': enforceStyleProp,
|
|
29
30
|
'local-cx-xcss': localCxXcss,
|
|
30
31
|
'no-array-arguments': noArrayArguments,
|
|
32
|
+
'no-atlaskit-theme': noAtlaskitTheme,
|
|
31
33
|
'no-classname-prop': noClassnameProp,
|
|
32
34
|
'no-container-queries': noContainerQueries,
|
|
33
35
|
'no-dynamic-styles': noDynamicStyles,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createLintRule } from '../utils/create-rule';
|
|
2
|
+
var rule = createLintRule({
|
|
3
|
+
meta: {
|
|
4
|
+
name: 'no-atlaskit-theme',
|
|
5
|
+
docs: {
|
|
6
|
+
description: 'Disallow imports from `@atlaskit/theme`',
|
|
7
|
+
recommended: true,
|
|
8
|
+
severity: 'warn'
|
|
9
|
+
},
|
|
10
|
+
messages: {
|
|
11
|
+
'no-atlaskit-theme': 'Do not import `@atlaskit/theme`. Use `@atlaskit/tokens` or Atlassian Design System components instead.'
|
|
12
|
+
},
|
|
13
|
+
type: 'problem'
|
|
14
|
+
},
|
|
15
|
+
create: function create(context) {
|
|
16
|
+
return {
|
|
17
|
+
// esquery regexes cannot contain a raw `/`, so the path separator is `\x2F`.
|
|
18
|
+
// Unanchored at the end, so this matches `@atlaskit/theme` and any subpath.
|
|
19
|
+
'ImportDeclaration[source.value=/^@atlaskit\\x2Ftheme(\\x2F|$)/]': function ImportDeclarationSourceValue_AtlaskitX2FthemeX2F$_(node) {
|
|
20
|
+
context.report({
|
|
21
|
+
node: node,
|
|
22
|
+
messageId: 'no-atlaskit-theme'
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
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::ef33ad38180e99be70285ddb225c56b9>>
|
|
4
|
+
* @codegenCommand afm workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import type { ESLint } from 'eslint';
|
|
7
7
|
export declare const plugin: ESLint.Plugin;
|