@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.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 +8 -0
- package/constellation/index/migration-guide.mdx +309 -0
- package/constellation/index/overview.mdx +4 -0
- package/constellation/index/props.mdx +9 -5
- package/dist/types/rules/no-unsafe-selectors/constants.d.ts +1 -4
- package/index.js +9 -9
- package/package.json +3 -3
- package/scripts/codegen.tsx +223 -284
- package/src/rules/__tests__/utils/_tester.tsx +24 -24
- package/src/rules/atlaskit-theme/README.md +21 -19
- package/src/rules/atlaskit-theme/__tests__/test.ts +53 -53
- package/src/rules/atlaskit-theme/index.ts +107 -115
- package/src/rules/convert-props-syntax/README.md +32 -22
- package/src/rules/convert-props-syntax/__tests__/invalid.test.tsx +46 -46
- package/src/rules/convert-props-syntax/__tests__/rule.test.tsx +175 -175
- package/src/rules/convert-props-syntax/__tests__/type-annotations.test.tsx +52 -52
- package/src/rules/convert-props-syntax/__tests__/unusual-properties.test.tsx +33 -33
- package/src/rules/convert-props-syntax/index.tsx +356 -386
- package/src/rules/enforce-style-prop/README.md +21 -18
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +90 -96
- package/src/rules/enforce-style-prop/index.tsx +144 -160
- package/src/rules/external-rules.tsx +163 -164
- package/src/rules/local-cx-xcss/README.md +10 -6
- package/src/rules/local-cx-xcss/__tests__/rule.test.tsx +26 -26
- package/src/rules/local-cx-xcss/index.tsx +46 -56
- package/src/rules/no-array-arguments/README.md +2 -1
- package/src/rules/no-array-arguments/__tests__/rule.test.tsx +37 -46
- package/src/rules/no-array-arguments/index.tsx +68 -69
- package/src/rules/no-classname-prop/README.md +7 -4
- package/src/rules/no-classname-prop/__tests__/rule.test.tsx +22 -22
- package/src/rules/no-classname-prop/index.tsx +25 -25
- package/src/rules/no-container-queries/README.md +11 -9
- package/src/rules/no-container-queries/__tests__/rule.test.tsx +47 -50
- package/src/rules/no-container-queries/index.tsx +75 -81
- package/src/rules/no-dynamic-styles/README.md +16 -19
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +58 -67
- package/src/rules/no-dynamic-styles/index.tsx +45 -48
- package/src/rules/no-exported-styles/README.md +17 -12
- package/src/rules/no-exported-styles/__tests__/rule.test.tsx +102 -111
- package/src/rules/no-exported-styles/index.tsx +36 -36
- package/src/rules/no-global-styles/README.md +15 -14
- package/src/rules/no-global-styles/__tests__/no-css-modules.test.tsx +28 -28
- package/src/rules/no-global-styles/__tests__/no-global-styles.test.tsx +37 -37
- package/src/rules/no-global-styles/index.tsx +59 -62
- package/src/rules/no-important-styles/README.md +5 -3
- package/src/rules/no-important-styles/__tests__/rule.test.tsx +66 -66
- package/src/rules/no-important-styles/index.tsx +49 -49
- package/src/rules/no-imported-style-values/README.md +23 -15
- package/src/rules/no-imported-style-values/__tests__/rule.test.tsx +123 -123
- package/src/rules/no-imported-style-values/index.tsx +116 -120
- package/src/rules/no-nested-selectors/README.md +15 -13
- package/src/rules/no-nested-selectors/__tests__/rule.test.tsx +128 -128
- package/src/rules/no-styled/README.md +14 -9
- package/src/rules/no-styled/__tests__/rule.test.tsx +31 -31
- package/src/rules/no-styled/index.tsx +34 -41
- package/src/rules/no-unsafe-selectors/README.md +103 -93
- package/src/rules/no-unsafe-selectors/__tests__/no-grouped-at-rules.test.tsx +21 -24
- package/src/rules/no-unsafe-selectors/__tests__/no-increased-specificity.test.tsx +44 -44
- package/src/rules/no-unsafe-selectors/__tests__/no-keyframes-at-rules.test.tsx +21 -21
- package/src/rules/no-unsafe-selectors/__tests__/no-legacy-pseudo-element-syntax.test.tsx +57 -57
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-at-rules.test.tsx +58 -58
- package/src/rules/no-unsafe-selectors/__tests__/no-restricted-pseudos.test.tsx +85 -85
- package/src/rules/no-unsafe-selectors/__tests__/no-selectors-object.test.tsx +12 -12
- package/src/rules/no-unsafe-selectors/__tests__/no-unparsable-selectors.test.tsx +23 -23
- package/src/rules/no-unsafe-selectors/__tests__/rule.test.tsx +114 -114
- package/src/rules/no-unsafe-selectors/constants.tsx +69 -77
- package/src/rules/no-unsafe-selectors/source-position-utils.tsx +38 -38
- package/src/rules/no-unsafe-selectors/walk-css-map.tsx +178 -184
- package/src/rules/no-unsafe-values/README.md +34 -40
- package/src/rules/no-unsafe-values/__tests__/no-array-values.test.tsx +13 -13
- package/src/rules/no-unsafe-values/__tests__/no-conditional-values.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-dynamic-keys.test.tsx +104 -104
- package/src/rules/no-unsafe-values/__tests__/no-function-calls.test.tsx +128 -128
- package/src/rules/no-unsafe-values/__tests__/no-identifier-arguments.test.tsx +23 -23
- package/src/rules/no-unsafe-values/__tests__/no-object-access.test.tsx +38 -38
- package/src/rules/no-unsafe-values/__tests__/no-object-references.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-spread-elements.test.tsx +18 -18
- package/src/rules/no-unsafe-values/__tests__/no-unsafe-values.test.tsx +28 -28
- package/src/rules/no-unsafe-values/__tests__/no-variables.test.tsx +47 -47
- package/src/rules/no-unsafe-values/index.tsx +76 -78
- package/src/rules/no-unsafe-values/messages.tsx +12 -12
- package/src/rules/no-unsafe-values/utils.tsx +370 -382
- package/src/rules/use-compiled/README.md +11 -8
- package/src/rules/use-compiled/__tests__/can-auto-fix.test.tsx +32 -32
- package/src/rules/use-compiled/__tests__/css.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/imports.test.tsx +90 -95
- package/src/rules/use-compiled/__tests__/keyframes.test.tsx +47 -47
- package/src/rules/use-compiled/__tests__/pragma.test.tsx +64 -64
- package/src/rules/use-compiled/__tests__/styled.test.tsx +53 -53
- package/src/rules/use-compiled/__tests__/use-compiled.test.tsx +10 -10
- package/src/rules/use-compiled/index.tsx +203 -226
- package/src/rules/use-compiled/is-safe.tsx +113 -117
- package/src/rules/use-compiled/utils.tsx +14 -18
- package/src/rules/utils/create-rule-with-typed-config.tsx +62 -63
- package/src/rules/utils/create-rule.tsx +3 -6
|
@@ -4,185 +4,169 @@ import type { SpreadElement, Property } from 'estree-jsx';
|
|
|
4
4
|
import { createLintRule } from '../utils/create-rule';
|
|
5
5
|
import type { Rule, Scope } from 'eslint';
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
getAllowedFunctionCalls,
|
|
8
|
+
isAllowListedVariable,
|
|
9
9
|
} from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
10
10
|
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
11
11
|
|
|
12
12
|
type ObjPropertyType = Property | SpreadElement;
|
|
13
|
-
type IdentifierWithParent = Scope.Reference['identifier'] &
|
|
14
|
-
Rule.NodeParentExtension;
|
|
13
|
+
type IdentifierWithParent = Scope.Reference['identifier'] & Rule.NodeParentExtension;
|
|
15
14
|
|
|
16
|
-
const isParameter = (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!definitions || !definitions.length) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
15
|
+
const isParameter = (context: Rule.RuleContext, identifier: Identifier): boolean => {
|
|
16
|
+
const definitions = findVariable({
|
|
17
|
+
sourceCode: context.sourceCode,
|
|
18
|
+
identifier: identifier,
|
|
19
|
+
})?.defs;
|
|
20
|
+
if (!definitions || !definitions.length) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const result = definitions[0];
|
|
25
|
+
return result.type === 'Parameter';
|
|
30
26
|
};
|
|
31
27
|
|
|
32
|
-
const isIdentifierAllowed = (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
sourceCode: context.sourceCode,
|
|
38
|
-
identifier: identifier,
|
|
39
|
-
});
|
|
28
|
+
const isIdentifierAllowed = (context: Rule.RuleContext, identifier: Identifier): boolean => {
|
|
29
|
+
const variable = findVariable({
|
|
30
|
+
sourceCode: context.sourceCode,
|
|
31
|
+
identifier: identifier,
|
|
32
|
+
});
|
|
40
33
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
if (!variable) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
44
37
|
|
|
45
|
-
|
|
38
|
+
const variableDefinition = variable.defs[0].node;
|
|
46
39
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
40
|
+
// If identifier is a RestElement, report warning
|
|
41
|
+
if ((variable.identifiers[0] as IdentifierWithParent).parent?.type === 'RestElement') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
54
44
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
45
|
+
// Checking if identifier has been destructured from props within function
|
|
46
|
+
if (variableDefinition.type === 'VariableDeclarator') {
|
|
47
|
+
// If it's a let variable, ignore
|
|
48
|
+
if (variableDefinition.parent.kind === 'let') {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
// If it's initialised by a call expression, ignore
|
|
52
|
+
if (variableDefinition.init?.type === 'CallExpression') {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
// Destructured from member expression
|
|
56
|
+
// e.g. const width = props.width
|
|
57
|
+
if (variableDefinition.init?.type === 'MemberExpression') {
|
|
58
|
+
return isParameter(context, variableDefinition.init.object);
|
|
59
|
+
}
|
|
60
|
+
// Destructured from object pattern
|
|
61
|
+
// e.g. const { width } = props
|
|
62
|
+
return isParameter(context, variableDefinition.init);
|
|
63
|
+
}
|
|
64
|
+
// If identifier has not been deconstructed from parameter or is a RestElement, report warning
|
|
65
|
+
return isParameter(context, identifier);
|
|
76
66
|
};
|
|
77
67
|
|
|
78
|
-
function isPropertyValueAllowed(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
const varType = variable.type;
|
|
68
|
+
function isPropertyValueAllowed(property: ObjPropertyType, context: Rule.RuleContext): boolean {
|
|
69
|
+
if (property.type === 'SpreadElement') {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
// property.type === 'Property', moving on to check if value is static
|
|
73
|
+
if (property.value.type === 'Literal') {
|
|
74
|
+
return false;
|
|
75
|
+
} else if (property.value.type === 'Identifier') {
|
|
76
|
+
return isIdentifierAllowed(context, property.value);
|
|
77
|
+
} else if (
|
|
78
|
+
property.value.type === 'CallExpression' &&
|
|
79
|
+
property.value.callee.type === 'Identifier'
|
|
80
|
+
) {
|
|
81
|
+
const variable = findVariable({
|
|
82
|
+
sourceCode: context.sourceCode,
|
|
83
|
+
identifier: property.value.callee,
|
|
84
|
+
});
|
|
85
|
+
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
86
|
+
const functionAllowList = getAllowedFunctionCalls(context.options);
|
|
87
|
+
if (
|
|
88
|
+
!variable ||
|
|
89
|
+
isAllowListedVariable({
|
|
90
|
+
allowList: functionAllowList,
|
|
91
|
+
variable,
|
|
92
|
+
})
|
|
93
|
+
) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
} else if (
|
|
97
|
+
property.value.type === 'MemberExpression' &&
|
|
98
|
+
property.value.object.type === 'Identifier'
|
|
99
|
+
) {
|
|
100
|
+
const definitions = findVariable({
|
|
101
|
+
sourceCode: context.sourceCode,
|
|
102
|
+
identifier: property.value.object,
|
|
103
|
+
})?.defs;
|
|
104
|
+
if (!definitions || !definitions.length) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
const variable = definitions[0];
|
|
108
|
+
if (!variable) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
const varType = variable.type;
|
|
125
112
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
113
|
+
if (varType === 'Variable') {
|
|
114
|
+
if (!variable.node.init) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const varSource = variable.node.init.type;
|
|
118
|
+
// Variables initialised by a call expression or object expression are ok
|
|
119
|
+
if (varSource === 'CallExpression' || varSource === 'ObjectExpression') {
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
// Check if member expression matches with function argument
|
|
123
|
+
} else if (varType !== 'Parameter') {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
141
128
|
}
|
|
142
129
|
|
|
143
130
|
export const rule = createLintRule({
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
// we've reached an attribute named style
|
|
131
|
+
meta: {
|
|
132
|
+
name: 'enforce-style-prop',
|
|
133
|
+
docs: {
|
|
134
|
+
description: 'Disallows usage of static styles in the `style` attribute in components',
|
|
135
|
+
recommended: true,
|
|
136
|
+
severity: 'warn',
|
|
137
|
+
},
|
|
138
|
+
messages: {
|
|
139
|
+
'enforce-style-prop':
|
|
140
|
+
'Avoid adding static values to the style prop. Use the css prop for static styles instead.',
|
|
141
|
+
},
|
|
142
|
+
type: 'problem',
|
|
143
|
+
},
|
|
144
|
+
create(context) {
|
|
145
|
+
return {
|
|
146
|
+
'JSXAttribute[name.name="style"] > JSXExpressionContainer': (node: Node) => {
|
|
147
|
+
if (!isNodeOfType(node, 'JSXExpressionContainer')) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// we've reached an attribute named style
|
|
167
151
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
152
|
+
if (node.expression.type === 'ObjectExpression') {
|
|
153
|
+
node.expression.properties.forEach((value) => {
|
|
154
|
+
if (!isPropertyValueAllowed(value, context)) {
|
|
155
|
+
context.report({
|
|
156
|
+
node: value,
|
|
157
|
+
messageId: 'enforce-style-prop',
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
} else {
|
|
162
|
+
context.report({
|
|
163
|
+
node: node,
|
|
164
|
+
messageId: 'enforce-style-prop',
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
},
|
|
186
170
|
});
|
|
187
171
|
|
|
188
172
|
export default rule;
|