@atlaskit/eslint-plugin-ui-styling-standard 0.11.4 → 0.11.6

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 (59) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +33 -3
  3. package/constellation/atlaskit-theme/usage.mdx +113 -0
  4. package/constellation/convert-props-syntax/usage.mdx +32 -22
  5. package/constellation/enforce-style-prop/usage.mdx +21 -18
  6. package/constellation/index/overview.mdx +91 -76
  7. package/constellation/index/props.mdx +2 -9
  8. package/constellation/local-cx-xcss/usage.mdx +10 -6
  9. package/constellation/no-array-arguments/usage.mdx +10 -9
  10. package/constellation/no-classname-prop/usage.mdx +7 -4
  11. package/constellation/no-container-queries/usage.mdx +17 -15
  12. package/constellation/no-dynamic-styles/usage.mdx +26 -29
  13. package/constellation/no-exported-styles/usage.mdx +23 -18
  14. package/constellation/no-important-styles/usage.mdx +5 -3
  15. package/constellation/no-imported-style-values/usage.mdx +30 -22
  16. package/constellation/no-nested-selectors/usage.mdx +22 -20
  17. package/constellation/no-unsafe-values/usage.mdx +45 -51
  18. package/dist/cjs/index.codegen.js +1 -1
  19. package/dist/cjs/presets/all.codegen.js +2 -1
  20. package/dist/cjs/presets/recommended.codegen.js +2 -1
  21. package/dist/cjs/rules/atlaskit-theme/index.js +95 -0
  22. package/dist/cjs/rules/enforce-style-prop/index.js +39 -26
  23. package/dist/cjs/rules/index.codegen.js +3 -1
  24. package/dist/es2019/index.codegen.js +1 -1
  25. package/dist/es2019/presets/all.codegen.js +2 -1
  26. package/dist/es2019/presets/recommended.codegen.js +2 -1
  27. package/dist/es2019/rules/atlaskit-theme/index.js +85 -0
  28. package/dist/es2019/rules/enforce-style-prop/index.js +34 -19
  29. package/dist/es2019/rules/index.codegen.js +3 -1
  30. package/dist/esm/index.codegen.js +1 -1
  31. package/dist/esm/presets/all.codegen.js +2 -1
  32. package/dist/esm/presets/recommended.codegen.js +2 -1
  33. package/dist/esm/rules/atlaskit-theme/index.js +89 -0
  34. package/dist/esm/rules/enforce-style-prop/index.js +39 -26
  35. package/dist/esm/rules/index.codegen.js +3 -1
  36. package/dist/types/index.codegen.d.ts +2 -0
  37. package/dist/types/presets/all.codegen.d.ts +2 -1
  38. package/dist/types/presets/recommended.codegen.d.ts +2 -1
  39. package/dist/types/rules/atlaskit-theme/index.d.ts +3 -0
  40. package/dist/types/rules/index.codegen.d.ts +1 -0
  41. package/dist/types-ts4.5/index.codegen.d.ts +2 -0
  42. package/dist/types-ts4.5/presets/all.codegen.d.ts +2 -1
  43. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +2 -1
  44. package/dist/types-ts4.5/rules/atlaskit-theme/index.d.ts +3 -0
  45. package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
  46. package/package.json +3 -3
  47. package/scripts/codegen.tsx +3 -10
  48. package/src/index.codegen.tsx +3 -3
  49. package/src/presets/all.codegen.tsx +66 -69
  50. package/src/presets/recommended.codegen.tsx +66 -69
  51. package/src/rules/atlaskit-theme/README.md +109 -0
  52. package/src/rules/atlaskit-theme/__tests__/test.ts +122 -0
  53. package/src/rules/atlaskit-theme/index.ts +136 -0
  54. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +18 -0
  55. package/src/rules/enforce-style-prop/index.tsx +42 -23
  56. package/src/rules/index.codegen.tsx +15 -13
  57. package/src/rules/no-exported-styles/index.tsx +1 -1
  58. package/src/rules/no-imported-style-values/index.tsx +1 -1
  59. package/tsconfig.app.json +3 -0
@@ -145,6 +145,24 @@ tester.run('enforce-style-prop', rule, {
145
145
  }
146
146
  `,
147
147
  },
148
+ {
149
+ name: 'Ignore function calls',
150
+ code: `
151
+ import { calcDefaultLayoutWidthByAppearance } from '../shared';
152
+ const Component = () => {
153
+ return (
154
+ <div
155
+ style={{
156
+ width: calcDefaultLayoutWidthByAppearance(
157
+ rendererAppearance,
158
+ tableNode,
159
+ ),
160
+ }}
161
+ />
162
+ );
163
+ };
164
+ `,
165
+ },
148
166
  ],
149
167
  invalid: [
150
168
  {
@@ -1,22 +1,26 @@
1
- import { Identifier, isNodeOfType, Node } from 'eslint-codemod-utils';
1
+ import { type Identifier, isNodeOfType, type Node } from 'eslint-codemod-utils';
2
2
  import type { SpreadElement, Property } from 'estree-jsx';
3
3
 
4
4
  import { createLintRule } from '../utils/create-rule';
5
5
  import type { Rule, Scope } from 'eslint';
6
+ import {
7
+ getAllowedFunctionCalls,
8
+ isAllowListedVariable,
9
+ } from '@atlaskit/eslint-utils/allowed-function-calls';
10
+ import { findVariable } from '@atlaskit/eslint-utils/find-variable';
6
11
 
7
12
  type ObjPropertyType = Property | SpreadElement;
8
13
  type IdentifierWithParent = Scope.Reference['identifier'] &
9
14
  Rule.NodeParentExtension;
10
15
 
11
- const findVariable = (
16
+ const isParameter = (
12
17
  context: Rule.RuleContext,
13
- name: string,
14
- ): Scope.Variable | undefined => {
15
- return context.getScope().variables.find((varb) => varb.name === name);
16
- };
17
-
18
- const isParameter = (context: Rule.RuleContext, variableName: string) => {
19
- const definitions = findVariable(context, variableName)?.defs;
18
+ identifier: Identifier,
19
+ ): boolean => {
20
+ const definitions = findVariable({
21
+ sourceCode: context.sourceCode,
22
+ identifier: identifier,
23
+ })?.defs;
20
24
  if (!definitions || !definitions.length) {
21
25
  return false;
22
26
  }
@@ -25,12 +29,14 @@ const isParameter = (context: Rule.RuleContext, variableName: string) => {
25
29
  return result.type === 'Parameter';
26
30
  };
27
31
 
28
- const checkIdentifier = (
32
+ const isIdentifierAllowed = (
29
33
  context: Rule.RuleContext,
30
34
  identifier: Identifier,
31
35
  ): boolean => {
32
- const val = identifier.name;
33
- const variable = findVariable(context, val);
36
+ const variable = findVariable({
37
+ sourceCode: context.sourceCode,
38
+ identifier: identifier,
39
+ });
34
40
 
35
41
  if (!variable) {
36
42
  return false;
@@ -59,16 +65,14 @@ const checkIdentifier = (
59
65
  // Destructured from member expression
60
66
  // e.g. const width = props.width
61
67
  if (variableDefinition.init?.type === 'MemberExpression') {
62
- const memberIdentifierName = variableDefinition.init.object.name;
63
- return isParameter(context, memberIdentifierName);
68
+ return isParameter(context, variableDefinition.init.object);
64
69
  }
65
70
  // Destructured from object pattern
66
71
  // e.g. const { width } = props
67
- const propName = variableDefinition.init?.name;
68
- return isParameter(context, propName);
72
+ return isParameter(context, variableDefinition.init);
69
73
  }
70
74
  // If identifier has not been deconstructed from parameter or is a RestElement, report warning
71
- return isParameter(context, val);
75
+ return isParameter(context, identifier);
72
76
  };
73
77
 
74
78
  function isPropertyValueAllowed(
@@ -82,19 +86,34 @@ function isPropertyValueAllowed(
82
86
  if (property.value.type === 'Literal') {
83
87
  return false;
84
88
  } else if (property.value.type === 'Identifier') {
85
- return checkIdentifier(context, property.value);
89
+ return isIdentifierAllowed(context, property.value);
86
90
  } else if (
87
91
  property.value.type === 'CallExpression' &&
88
- property.value.callee.type === 'Identifier' &&
89
- property.value.callee.name === 'token'
92
+ property.value.callee.type === 'Identifier'
90
93
  ) {
91
- return false;
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
+ }
92
109
  } else if (
93
110
  property.value.type === 'MemberExpression' &&
94
111
  property.value.object.type === 'Identifier'
95
112
  ) {
96
- const val = property.value.object.name;
97
- const definitions = findVariable(context, val)?.defs;
113
+ const definitions = findVariable({
114
+ sourceCode: context.sourceCode,
115
+ identifier: property.value.object,
116
+ })?.defs;
98
117
  if (!definitions || !definitions.length) {
99
118
  return false;
100
119
  }
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::648acb81f0f43d8ce56f7d6c22db8856>>
3
+ * @codegen <<SignedSource::78ffc29d20fd2fe3727a620cb4ddf192>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
+ import atlaskitTheme from './atlaskit-theme';
6
7
  import convertPropsSyntax from './convert-props-syntax';
7
8
  import enforceStyleProp from './enforce-style-prop';
8
9
  import localCxXcss from './local-cx-xcss';
@@ -17,16 +18,17 @@ import noNestedSelectors from './no-nested-selectors';
17
18
  import noUnsafeValues from './no-unsafe-values';
18
19
 
19
20
  export default {
20
- 'convert-props-syntax': convertPropsSyntax,
21
- 'enforce-style-prop': enforceStyleProp,
22
- 'local-cx-xcss': localCxXcss,
23
- 'no-array-arguments': noArrayArguments,
24
- 'no-classname-prop': noClassnameProp,
25
- 'no-container-queries': noContainerQueries,
26
- 'no-dynamic-styles': noDynamicStyles,
27
- 'no-exported-styles': noExportedStyles,
28
- 'no-important-styles': noImportantStyles,
29
- 'no-imported-style-values': noImportedStyleValues,
30
- 'no-nested-selectors': noNestedSelectors,
31
- 'no-unsafe-values': noUnsafeValues,
21
+ 'atlaskit-theme': atlaskitTheme,
22
+ 'convert-props-syntax': convertPropsSyntax,
23
+ 'enforce-style-prop': enforceStyleProp,
24
+ 'local-cx-xcss': localCxXcss,
25
+ 'no-array-arguments': noArrayArguments,
26
+ 'no-classname-prop': noClassnameProp,
27
+ 'no-container-queries': noContainerQueries,
28
+ 'no-dynamic-styles': noDynamicStyles,
29
+ 'no-exported-styles': noExportedStyles,
30
+ 'no-important-styles': noImportantStyles,
31
+ 'no-imported-style-values': noImportedStyleValues,
32
+ 'no-nested-selectors': noNestedSelectors,
33
+ 'no-unsafe-values': noUnsafeValues,
32
34
  };
@@ -5,7 +5,7 @@ import {
5
5
  isKeyframes,
6
6
  isCssMap,
7
7
  isXcss,
8
- SupportedNameChecker,
8
+ type SupportedNameChecker,
9
9
  } from '@atlaskit/eslint-utils/is-supported-import';
10
10
  import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
11
11
  import { createNoExportedRule } from '@atlaskit/eslint-utils/create-no-exported-rule';
@@ -7,7 +7,7 @@ import type { JSONSchema4 } from '@typescript-eslint/utils/dist/json-schema';
7
7
  import { findVariable } from '@atlaskit/eslint-utils/find-variable';
8
8
  import type { Rule } from 'eslint';
9
9
  import {
10
- AllowList,
10
+ type AllowList,
11
11
  getAllowedDynamicKeys,
12
12
  getAllowedFunctionCalls,
13
13
  isAllowListedVariable,
package/tsconfig.app.json CHANGED
@@ -33,6 +33,9 @@
33
33
  "outDir": "../../../tsDist/@atlaskit__eslint-plugin-ui-styling-standard/app"
34
34
  },
35
35
  "references": [
36
+ {
37
+ "path": "../../../build/formatting/tsconfig.app.json"
38
+ },
36
39
  {
37
40
  "path": "../eslint-utils/tsconfig.app.json"
38
41
  },