@atlaskit/eslint-plugin-ui-styling-standard 0.15.2 → 0.16.1

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