@atlaskit/eslint-plugin-ui-styling-standard 0.7.0 → 0.7.2
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 +13 -0
- package/README.md +17 -16
- package/constellation/index/overview.mdx +17 -16
- package/constellation/no-container-queries/usage.mdx +50 -0
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/convert-props-syntax/index.js +1 -1
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/cjs/rules/local-cx-xcss/index.js +1 -1
- package/dist/cjs/rules/no-container-queries/index.js +76 -0
- package/dist/cjs/rules/no-important-styles/index.js +1 -1
- package/dist/es2019/presets/all.codegen.js +2 -1
- package/dist/es2019/presets/recommended.codegen.js +2 -1
- package/dist/es2019/rules/convert-props-syntax/index.js +1 -1
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/es2019/rules/local-cx-xcss/index.js +1 -1
- package/dist/es2019/rules/no-container-queries/index.js +70 -0
- package/dist/es2019/rules/no-important-styles/index.js +1 -1
- package/dist/esm/presets/all.codegen.js +2 -1
- package/dist/esm/presets/recommended.codegen.js +2 -1
- package/dist/esm/rules/convert-props-syntax/index.js +1 -1
- package/dist/esm/rules/index.codegen.js +3 -1
- package/dist/esm/rules/local-cx-xcss/index.js +1 -1
- package/dist/esm/rules/no-container-queries/index.js +69 -0
- package/dist/esm/rules/no-important-styles/index.js +1 -1
- package/dist/types/index.codegen.d.ts +2 -0
- package/dist/types/presets/all.codegen.d.ts +2 -1
- package/dist/types/presets/recommended.codegen.d.ts +2 -1
- package/dist/types/rules/index.codegen.d.ts +1 -0
- package/dist/types/rules/no-container-queries/index.d.ts +2 -0
- package/dist/types-ts4.5/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/dist/types-ts4.5/rules/no-container-queries/index.d.ts +2 -0
- package/package.json +3 -2
- package/src/presets/all.codegen.tsx +2 -1
- package/src/presets/recommended.codegen.tsx +2 -1
- package/src/rules/convert-props-syntax/index.tsx +4 -1
- package/src/rules/index.codegen.tsx +3 -1
- package/src/rules/local-cx-xcss/index.tsx +4 -1
- package/src/rules/no-container-queries/README.md +48 -0
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +142 -0
- package/src/rules/no-container-queries/index.tsx +100 -0
- package/src/rules/no-important-styles/index.tsx +1 -1
- package/tsconfig.app.json +3 -0
- package/dist/cjs/rules/utils/is-supported-import.js +0 -160
- package/dist/es2019/rules/utils/is-supported-import.js +0 -150
- package/dist/esm/rules/utils/is-supported-import.js +0 -154
- package/dist/types/rules/utils/is-supported-import.d.ts +0 -46
- package/dist/types-ts4.5/rules/utils/is-supported-import.d.ts +0 -46
- package/src/rules/utils/README.md +0 -1
- package/src/rules/utils/is-supported-import.tsx +0 -227
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
// This should be kept in sync with
|
|
2
|
-
// packages/design-system/eslint-plugin/src/rules/utils/is-supported-import.tsx
|
|
3
|
-
// whenever possible.
|
|
4
|
-
//
|
|
5
|
-
// TODO: would having an @atlassian/eslint-plugin-design-system-common
|
|
6
|
-
// package be useful?
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
9
|
-
import type { Rule, Scope } from 'eslint';
|
|
10
|
-
import type { CallExpression } from 'estree';
|
|
11
|
-
|
|
12
|
-
type Definition = Scope.Definition;
|
|
13
|
-
type Callee = CallExpression['callee'];
|
|
14
|
-
type Reference = Scope.Reference;
|
|
15
|
-
|
|
16
|
-
export const CSS_IN_JS_IMPORTS = {
|
|
17
|
-
compiled: '@compiled/react',
|
|
18
|
-
emotionReact: '@emotion/react',
|
|
19
|
-
emotionCore: '@emotion/core',
|
|
20
|
-
emotionStyled: '@emotion/styled',
|
|
21
|
-
styledComponents: 'styled-components',
|
|
22
|
-
atlaskitCss: '@atlaskit/css',
|
|
23
|
-
atlaskitPrimitives: '@atlaskit/primitives',
|
|
24
|
-
} as const;
|
|
25
|
-
|
|
26
|
-
// A CSS-in-JS library an import of a valid css, cx, cssMap, etc.
|
|
27
|
-
// function might originate from, e.g. @compiled/react, @emotion/core.
|
|
28
|
-
export type ImportSource = string;
|
|
29
|
-
|
|
30
|
-
export type SupportedNameChecker = (
|
|
31
|
-
nodeToCheck: Callee,
|
|
32
|
-
referencesInScope: Reference[],
|
|
33
|
-
importSources: ImportSource[],
|
|
34
|
-
) => boolean;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* By default all known import sources are checked against.
|
|
38
|
-
*/
|
|
39
|
-
export const DEFAULT_IMPORT_SOURCES: ImportSource[] =
|
|
40
|
-
Object.values(CSS_IN_JS_IMPORTS);
|
|
41
|
-
|
|
42
|
-
const getIdentifierNode = (node: Callee) => {
|
|
43
|
-
let identifierNode = node.type === 'Identifier' ? node : undefined;
|
|
44
|
-
if (!identifierNode) {
|
|
45
|
-
// Handles styled.div`` case
|
|
46
|
-
if (node.type === 'MemberExpression' && node.object.type === 'Identifier') {
|
|
47
|
-
identifierNode = node.object;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Handles styled(Component)`` case
|
|
51
|
-
if (node.type === 'CallExpression' && node.callee.type === 'Identifier') {
|
|
52
|
-
identifierNode = node.callee;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return identifierNode;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Given the ESLint rule context, extract and parse the value of the importSources rule option.
|
|
60
|
-
* The importSources option is used to override which libraries an ESLint rule applies to.
|
|
61
|
-
*
|
|
62
|
-
* @param context The rule context.
|
|
63
|
-
* @returns An array of strings representing what CSS-in-JS packages that should be checked, based
|
|
64
|
-
* on the rule options configuration.
|
|
65
|
-
*/
|
|
66
|
-
export const getImportSources = (context: Rule.RuleContext): ImportSource[] => {
|
|
67
|
-
const options = context.options;
|
|
68
|
-
if (!options.length) {
|
|
69
|
-
return DEFAULT_IMPORT_SOURCES;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (options[0].importSources && Array.isArray(options[0].importSources)) {
|
|
73
|
-
return options[0].importSources;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return DEFAULT_IMPORT_SOURCES;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const isSupportedImportWrapper = (
|
|
80
|
-
functionName: string,
|
|
81
|
-
defaultFromImportSources: ImportSource[] = [],
|
|
82
|
-
): SupportedNameChecker => {
|
|
83
|
-
const checkDefinitionHasImport = (
|
|
84
|
-
def: Definition,
|
|
85
|
-
importSources: ImportSource[],
|
|
86
|
-
) => {
|
|
87
|
-
if (def.type !== 'ImportBinding') {
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
!def.parent ||
|
|
93
|
-
!importSources.includes(def.parent.source.value as ImportSource)
|
|
94
|
-
) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Matches the imported name from a named import
|
|
99
|
-
// import { functionName, functioName as otherName } from 'import-source';
|
|
100
|
-
const isNamedImport =
|
|
101
|
-
def.node.type === 'ImportSpecifier' &&
|
|
102
|
-
def.node.imported.name === functionName;
|
|
103
|
-
|
|
104
|
-
// Must explicitly match the local name from a default import
|
|
105
|
-
// import functionName from 'import-source';
|
|
106
|
-
const isDefaultImportMatchingLocal =
|
|
107
|
-
def.node.type === 'ImportDefaultSpecifier' &&
|
|
108
|
-
def.node.local.name === functionName;
|
|
109
|
-
|
|
110
|
-
// Can match any local name from a default import
|
|
111
|
-
// import anything from 'import-source'
|
|
112
|
-
const isKnownDefaultImport =
|
|
113
|
-
def.node.type === 'ImportDefaultSpecifier' &&
|
|
114
|
-
defaultFromImportSources.includes(
|
|
115
|
-
def.parent.source.value as ImportSource,
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
return (
|
|
119
|
-
isNamedImport || isDefaultImportMatchingLocal || isKnownDefaultImport
|
|
120
|
-
);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Checks whether:
|
|
125
|
-
*
|
|
126
|
-
* 1. A function name `nodeToCheck` matches the name of the function we
|
|
127
|
-
* want to check for (e.g. `cx`, `css`, `cssMap`, or `keyframes`), and
|
|
128
|
-
* 2. Whether `nodeToCheck` originates from one of the libraries listed
|
|
129
|
-
* in `importSources`.
|
|
130
|
-
*
|
|
131
|
-
* @param nodeToCheck The function callee we are checking (e.g. The `css` in `css()`).
|
|
132
|
-
* @param referencesInScope List of references that are in scope. We'll use this
|
|
133
|
-
* to check where the function callee is imported from.
|
|
134
|
-
* @param importSources List of libraries that we want to ensure `nodeToCheck`
|
|
135
|
-
* comes from.
|
|
136
|
-
*
|
|
137
|
-
* @returns Whether the above conditions are true.
|
|
138
|
-
*/
|
|
139
|
-
const isSupportedImport = (
|
|
140
|
-
nodeToCheck: Callee,
|
|
141
|
-
referencesInScope: Reference[],
|
|
142
|
-
importSources: ImportSource[],
|
|
143
|
-
): boolean => {
|
|
144
|
-
const identifierNode = getIdentifierNode(nodeToCheck);
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
identifierNode?.type === 'Identifier' &&
|
|
148
|
-
referencesInScope.some(
|
|
149
|
-
(reference) =>
|
|
150
|
-
reference.identifier === identifierNode &&
|
|
151
|
-
reference.resolved?.defs.some((def) =>
|
|
152
|
-
checkDefinitionHasImport(def, importSources),
|
|
153
|
-
),
|
|
154
|
-
)
|
|
155
|
-
);
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
return isSupportedImport;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// Unused functions have been commented out until we implement corresponding
|
|
162
|
-
// eslint rules which use them
|
|
163
|
-
//
|
|
164
|
-
export const isCss = isSupportedImportWrapper('css');
|
|
165
|
-
export const isCxFunction = isSupportedImportWrapper('cx');
|
|
166
|
-
export const isCssMap = isSupportedImportWrapper('cssMap');
|
|
167
|
-
export const isKeyframes = isSupportedImportWrapper('keyframes');
|
|
168
|
-
// `styled` is also the explicit default of `styled-components` and `@emotion/styled`, so we also match on default imports generally
|
|
169
|
-
export const isStyled = isSupportedImportWrapper('styled', [
|
|
170
|
-
'styled-components',
|
|
171
|
-
'@emotion/styled',
|
|
172
|
-
]);
|
|
173
|
-
export const isXcss = isSupportedImportWrapper('xcss');
|
|
174
|
-
|
|
175
|
-
export const isImportedFrom =
|
|
176
|
-
(moduleName: string, exactMatch = true) =>
|
|
177
|
-
(
|
|
178
|
-
nodeToCheck: Callee,
|
|
179
|
-
referencesInScope: Reference[],
|
|
180
|
-
/**
|
|
181
|
-
* If we strictly have specific import sources in the config scope, pass them to make this more performant.
|
|
182
|
-
* Pass `null` if you don't care if its configured or not.
|
|
183
|
-
*/
|
|
184
|
-
importSources: ImportSource[] | null = null,
|
|
185
|
-
): boolean => {
|
|
186
|
-
if (
|
|
187
|
-
importSources &&
|
|
188
|
-
!importSources.some(
|
|
189
|
-
(importSource) =>
|
|
190
|
-
importSource === moduleName ||
|
|
191
|
-
(!exactMatch && importSource.startsWith(moduleName)),
|
|
192
|
-
)
|
|
193
|
-
) {
|
|
194
|
-
// Don't go through the trouble of checking the import sources does not include this
|
|
195
|
-
// We'll assume this is skipped elsewhere.
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const identifierNode = getIdentifierNode(nodeToCheck);
|
|
200
|
-
|
|
201
|
-
return (
|
|
202
|
-
identifierNode?.type === 'Identifier' &&
|
|
203
|
-
referencesInScope.some(
|
|
204
|
-
(reference) =>
|
|
205
|
-
reference.identifier === identifierNode &&
|
|
206
|
-
reference.resolved?.defs.some((def) => {
|
|
207
|
-
return (
|
|
208
|
-
def.type === 'ImportBinding' &&
|
|
209
|
-
(def.parent?.source.value === moduleName ||
|
|
210
|
-
(!exactMatch &&
|
|
211
|
-
String(def.parent?.source.value)?.startsWith(moduleName)))
|
|
212
|
-
);
|
|
213
|
-
}),
|
|
214
|
-
)
|
|
215
|
-
);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Determine if this node is specifically from a `'styled-components'` import.
|
|
220
|
-
* This is because `styled-components@3.4` APIs are not consistent with Emotion and Compiled,
|
|
221
|
-
* we need to handle them differently in a few scenarios.
|
|
222
|
-
*
|
|
223
|
-
* This can be cleaned up when `'styled-components'` is no longer a valid ImportSource.
|
|
224
|
-
*/
|
|
225
|
-
export const isStyledComponents = isImportedFrom('styled-components');
|
|
226
|
-
export const isCompiled = isImportedFrom('@compiled/', false);
|
|
227
|
-
export const isEmotion = isImportedFrom('@emotion/', false);
|