@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.
- package/CHANGELOG.md +16 -0
- package/README.md +33 -3
- package/constellation/atlaskit-theme/usage.mdx +113 -0
- package/constellation/convert-props-syntax/usage.mdx +32 -22
- package/constellation/enforce-style-prop/usage.mdx +21 -18
- package/constellation/index/overview.mdx +91 -76
- package/constellation/index/props.mdx +2 -9
- package/constellation/local-cx-xcss/usage.mdx +10 -6
- package/constellation/no-array-arguments/usage.mdx +10 -9
- package/constellation/no-classname-prop/usage.mdx +7 -4
- package/constellation/no-container-queries/usage.mdx +17 -15
- package/constellation/no-dynamic-styles/usage.mdx +26 -29
- package/constellation/no-exported-styles/usage.mdx +23 -18
- package/constellation/no-important-styles/usage.mdx +5 -3
- package/constellation/no-imported-style-values/usage.mdx +30 -22
- package/constellation/no-nested-selectors/usage.mdx +22 -20
- package/constellation/no-unsafe-values/usage.mdx +45 -51
- package/dist/cjs/index.codegen.js +1 -1
- package/dist/cjs/presets/all.codegen.js +2 -1
- package/dist/cjs/presets/recommended.codegen.js +2 -1
- package/dist/cjs/rules/atlaskit-theme/index.js +95 -0
- package/dist/cjs/rules/enforce-style-prop/index.js +39 -26
- package/dist/cjs/rules/index.codegen.js +3 -1
- package/dist/es2019/index.codegen.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/atlaskit-theme/index.js +85 -0
- package/dist/es2019/rules/enforce-style-prop/index.js +34 -19
- package/dist/es2019/rules/index.codegen.js +3 -1
- package/dist/esm/index.codegen.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/atlaskit-theme/index.js +89 -0
- package/dist/esm/rules/enforce-style-prop/index.js +39 -26
- package/dist/esm/rules/index.codegen.js +3 -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/atlaskit-theme/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +1 -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/atlaskit-theme/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +1 -0
- package/package.json +3 -3
- package/scripts/codegen.tsx +3 -10
- package/src/index.codegen.tsx +3 -3
- package/src/presets/all.codegen.tsx +66 -69
- package/src/presets/recommended.codegen.tsx +66 -69
- package/src/rules/atlaskit-theme/README.md +109 -0
- package/src/rules/atlaskit-theme/__tests__/test.ts +122 -0
- package/src/rules/atlaskit-theme/index.ts +136 -0
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +18 -0
- package/src/rules/enforce-style-prop/index.tsx +42 -23
- package/src/rules/index.codegen.tsx +15 -13
- package/src/rules/no-exported-styles/index.tsx +1 -1
- package/src/rules/no-imported-style-values/index.tsx +1 -1
- 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
|
|
16
|
+
const isParameter = (
|
|
12
17
|
context: Rule.RuleContext,
|
|
13
|
-
|
|
14
|
-
):
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
32
|
+
const isIdentifierAllowed = (
|
|
29
33
|
context: Rule.RuleContext,
|
|
30
34
|
identifier: Identifier,
|
|
31
35
|
): boolean => {
|
|
32
|
-
const
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
|
97
|
-
|
|
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::
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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