@atlaskit/eslint-plugin-ui-styling-standard 0.11.4 → 0.11.5
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/README.md +30 -3
- package/constellation/index/props.mdx +2 -9
- package/dist/cjs/rules/enforce-style-prop/index.js +39 -26
- package/dist/es2019/rules/enforce-style-prop/index.js +34 -19
- package/dist/esm/rules/enforce-style-prop/index.js +39 -26
- package/package.json +3 -3
- package/scripts/codegen.tsx +3 -10
- 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/no-exported-styles/index.tsx +1 -1
- package/src/rules/no-imported-style-values/index.tsx +1 -1
- package/tsconfig.app.json +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-ui-styling-standard
|
|
2
2
|
|
|
3
|
+
## 0.11.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#96532](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/96532)
|
|
8
|
+
[`d54c7df2e836`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/d54c7df2e836) -
|
|
9
|
+
Editing enforce-style-prop rule to use eslint utils functions
|
|
10
|
+
|
|
3
11
|
## 0.11.4
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# UI Styling Standard ESLint Plugin
|
|
2
2
|
|
|
3
|
-
The UI Styling Standard
|
|
3
|
+
The UI Styling Standard is a set of principles to guide styling UI code across Atlassian's frontend codebases and ecosystem.
|
|
4
|
+
|
|
5
|
+
These are the current ESLint rules that enforce and help comply with the UI Styling Standard today, but more are planned to support the standard over time.
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
You must use the recommended config to follow the styling standards at Atlassian,
|
|
10
|
+
which will ensure compatability and performance with the design system.
|
|
11
|
+
|
|
12
|
+
```diff
|
|
13
|
+
module.exports = {
|
|
14
|
+
extends: [
|
|
15
|
+
+ 'plugin:@atlaskit/ui-styling-standard/recommended',
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
We don't recommended maintaining your own configuration.
|
|
21
|
+
If you do not use our config you will need to specify individual rules and configuration.
|
|
22
|
+
Add the plugin to your `.eslintrc.js` file and enable individual rules as you're ready to adopt.
|
|
23
|
+
|
|
24
|
+
```diff
|
|
25
|
+
module.exports = {
|
|
26
|
+
plugins: [
|
|
27
|
+
+ '@atlaskit/ui-styling-standard',
|
|
28
|
+
],
|
|
29
|
+
rules: [
|
|
30
|
+
+ '@atlaskit/ui-styling-standard/convert-props-syntax': 'warn',
|
|
31
|
+
+ '@atlaskit/design-system/local-cx-xcss': 'error',
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
```
|
|
8
35
|
|
|
9
36
|
## Rules
|
|
10
37
|
|
|
@@ -11,22 +11,15 @@ module.exports = {
|
|
|
11
11
|
|
|
12
12
|
We don't recommended maintaining your own configuration.
|
|
13
13
|
If you do not use our config you will need to specify individual rules and configuration.
|
|
14
|
-
Add the plugin to your `.eslintrc.js` file.
|
|
14
|
+
Add the plugin to your `.eslintrc.js` file and enable individual rules as you're ready to adopt.
|
|
15
15
|
|
|
16
16
|
```diff
|
|
17
17
|
module.exports = {
|
|
18
18
|
plugins: [
|
|
19
19
|
+ '@atlaskit/ui-styling-standard',
|
|
20
20
|
],
|
|
21
|
-
};
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Enable individual rules as that you're ready to adopt.
|
|
25
|
-
|
|
26
|
-
```diff
|
|
27
|
-
module.exports = {
|
|
28
21
|
rules: [
|
|
29
|
-
+ '@atlaskit/
|
|
22
|
+
+ '@atlaskit/ui-styling-standard/convert-props-syntax': 'warn',
|
|
30
23
|
+ '@atlaskit/design-system/local-cx-xcss': 'error',
|
|
31
24
|
],
|
|
32
25
|
};
|
|
@@ -6,24 +6,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.rule = exports.default = void 0;
|
|
7
7
|
var _eslintCodemodUtils = require("eslint-codemod-utils");
|
|
8
8
|
var _createRule = require("../utils/create-rule");
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
var isParameter = function isParameter(context, variableName) {
|
|
9
|
+
var _allowedFunctionCalls = require("@atlaskit/eslint-utils/allowed-function-calls");
|
|
10
|
+
var _findVariable3 = require("@atlaskit/eslint-utils/find-variable");
|
|
11
|
+
var isParameter = function isParameter(context, identifier) {
|
|
15
12
|
var _findVariable;
|
|
16
|
-
var definitions = (_findVariable =
|
|
13
|
+
var definitions = (_findVariable = (0, _findVariable3.findVariable)({
|
|
14
|
+
sourceCode: context.sourceCode,
|
|
15
|
+
identifier: identifier
|
|
16
|
+
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
17
17
|
if (!definitions || !definitions.length) {
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
20
|
var result = definitions[0];
|
|
21
21
|
return result.type === 'Parameter';
|
|
22
22
|
};
|
|
23
|
-
var
|
|
23
|
+
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
24
24
|
var _parent;
|
|
25
|
-
var
|
|
26
|
-
|
|
25
|
+
var variable = (0, _findVariable3.findVariable)({
|
|
26
|
+
sourceCode: context.sourceCode,
|
|
27
|
+
identifier: identifier
|
|
28
|
+
});
|
|
27
29
|
if (!variable) {
|
|
28
30
|
return false;
|
|
29
31
|
}
|
|
@@ -36,7 +38,7 @@ var checkIdentifier = function checkIdentifier(context, identifier) {
|
|
|
36
38
|
|
|
37
39
|
// Checking if identifier has been destructured from props within function
|
|
38
40
|
if (variableDefinition.type === 'VariableDeclarator') {
|
|
39
|
-
var _variableDefinition$i, _variableDefinition$i2
|
|
41
|
+
var _variableDefinition$i, _variableDefinition$i2;
|
|
40
42
|
// If it's a let variable, ignore
|
|
41
43
|
if (variableDefinition.parent.kind === 'let') {
|
|
42
44
|
return true;
|
|
@@ -48,16 +50,14 @@ var checkIdentifier = function checkIdentifier(context, identifier) {
|
|
|
48
50
|
// Destructured from member expression
|
|
49
51
|
// e.g. const width = props.width
|
|
50
52
|
if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
|
|
51
|
-
|
|
52
|
-
return isParameter(context, memberIdentifierName);
|
|
53
|
+
return isParameter(context, variableDefinition.init.object);
|
|
53
54
|
}
|
|
54
55
|
// Destructured from object pattern
|
|
55
56
|
// e.g. const { width } = props
|
|
56
|
-
|
|
57
|
-
return isParameter(context, propName);
|
|
57
|
+
return isParameter(context, variableDefinition.init);
|
|
58
58
|
}
|
|
59
59
|
// If identifier has not been deconstructed from parameter or is a RestElement, report warning
|
|
60
|
-
return isParameter(context,
|
|
60
|
+
return isParameter(context, identifier);
|
|
61
61
|
};
|
|
62
62
|
function isPropertyValueAllowed(property, context) {
|
|
63
63
|
if (property.type === 'SpreadElement') {
|
|
@@ -67,26 +67,39 @@ function isPropertyValueAllowed(property, context) {
|
|
|
67
67
|
if (property.value.type === 'Literal') {
|
|
68
68
|
return false;
|
|
69
69
|
} else if (property.value.type === 'Identifier') {
|
|
70
|
-
return
|
|
71
|
-
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier'
|
|
72
|
-
|
|
70
|
+
return isIdentifierAllowed(context, property.value);
|
|
71
|
+
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
72
|
+
var variable = (0, _findVariable3.findVariable)({
|
|
73
|
+
sourceCode: context.sourceCode,
|
|
74
|
+
identifier: property.value.callee
|
|
75
|
+
});
|
|
76
|
+
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
77
|
+
var functionAllowList = (0, _allowedFunctionCalls.getAllowedFunctionCalls)(context.options);
|
|
78
|
+
if (!variable || (0, _allowedFunctionCalls.isAllowListedVariable)({
|
|
79
|
+
allowList: functionAllowList,
|
|
80
|
+
variable: variable
|
|
81
|
+
})) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
73
84
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
74
85
|
var _findVariable2;
|
|
75
|
-
var
|
|
76
|
-
|
|
86
|
+
var definitions = (_findVariable2 = (0, _findVariable3.findVariable)({
|
|
87
|
+
sourceCode: context.sourceCode,
|
|
88
|
+
identifier: property.value.object
|
|
89
|
+
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
77
90
|
if (!definitions || !definitions.length) {
|
|
78
91
|
return false;
|
|
79
92
|
}
|
|
80
|
-
var
|
|
81
|
-
if (!
|
|
93
|
+
var _variable = definitions[0];
|
|
94
|
+
if (!_variable) {
|
|
82
95
|
return false;
|
|
83
96
|
}
|
|
84
|
-
var varType =
|
|
97
|
+
var varType = _variable.type;
|
|
85
98
|
if (varType === 'Variable') {
|
|
86
|
-
if (!
|
|
99
|
+
if (!_variable.node.init) {
|
|
87
100
|
return false;
|
|
88
101
|
}
|
|
89
|
-
var varSource =
|
|
102
|
+
var varSource = _variable.node.init.type;
|
|
90
103
|
// Variables initialised by a call expression or object expression are ok
|
|
91
104
|
if (varSource === 'CallExpression' || varSource === 'ObjectExpression') {
|
|
92
105
|
return true;
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const isParameter = (context, variableName) => {
|
|
3
|
+
import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
4
|
+
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
5
|
+
const isParameter = (context, identifier) => {
|
|
7
6
|
var _findVariable;
|
|
8
|
-
const definitions = (_findVariable = findVariable(
|
|
7
|
+
const definitions = (_findVariable = findVariable({
|
|
8
|
+
sourceCode: context.sourceCode,
|
|
9
|
+
identifier: identifier
|
|
10
|
+
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
9
11
|
if (!definitions || !definitions.length) {
|
|
10
12
|
return false;
|
|
11
13
|
}
|
|
12
14
|
const result = definitions[0];
|
|
13
15
|
return result.type === 'Parameter';
|
|
14
16
|
};
|
|
15
|
-
const
|
|
17
|
+
const isIdentifierAllowed = (context, identifier) => {
|
|
16
18
|
var _parent;
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
+
const variable = findVariable({
|
|
20
|
+
sourceCode: context.sourceCode,
|
|
21
|
+
identifier: identifier
|
|
22
|
+
});
|
|
19
23
|
if (!variable) {
|
|
20
24
|
return false;
|
|
21
25
|
}
|
|
@@ -28,7 +32,7 @@ const checkIdentifier = (context, identifier) => {
|
|
|
28
32
|
|
|
29
33
|
// Checking if identifier has been destructured from props within function
|
|
30
34
|
if (variableDefinition.type === 'VariableDeclarator') {
|
|
31
|
-
var _variableDefinition$i, _variableDefinition$i2
|
|
35
|
+
var _variableDefinition$i, _variableDefinition$i2;
|
|
32
36
|
// If it's a let variable, ignore
|
|
33
37
|
if (variableDefinition.parent.kind === 'let') {
|
|
34
38
|
return true;
|
|
@@ -40,16 +44,14 @@ const checkIdentifier = (context, identifier) => {
|
|
|
40
44
|
// Destructured from member expression
|
|
41
45
|
// e.g. const width = props.width
|
|
42
46
|
if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
|
|
43
|
-
|
|
44
|
-
return isParameter(context, memberIdentifierName);
|
|
47
|
+
return isParameter(context, variableDefinition.init.object);
|
|
45
48
|
}
|
|
46
49
|
// Destructured from object pattern
|
|
47
50
|
// e.g. const { width } = props
|
|
48
|
-
|
|
49
|
-
return isParameter(context, propName);
|
|
51
|
+
return isParameter(context, variableDefinition.init);
|
|
50
52
|
}
|
|
51
53
|
// If identifier has not been deconstructed from parameter or is a RestElement, report warning
|
|
52
|
-
return isParameter(context,
|
|
54
|
+
return isParameter(context, identifier);
|
|
53
55
|
};
|
|
54
56
|
function isPropertyValueAllowed(property, context) {
|
|
55
57
|
if (property.type === 'SpreadElement') {
|
|
@@ -59,13 +61,26 @@ function isPropertyValueAllowed(property, context) {
|
|
|
59
61
|
if (property.value.type === 'Literal') {
|
|
60
62
|
return false;
|
|
61
63
|
} else if (property.value.type === 'Identifier') {
|
|
62
|
-
return
|
|
63
|
-
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier'
|
|
64
|
-
|
|
64
|
+
return isIdentifierAllowed(context, property.value);
|
|
65
|
+
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
66
|
+
const variable = findVariable({
|
|
67
|
+
sourceCode: context.sourceCode,
|
|
68
|
+
identifier: property.value.callee
|
|
69
|
+
});
|
|
70
|
+
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
71
|
+
const functionAllowList = getAllowedFunctionCalls(context.options);
|
|
72
|
+
if (!variable || isAllowListedVariable({
|
|
73
|
+
allowList: functionAllowList,
|
|
74
|
+
variable
|
|
75
|
+
})) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
65
78
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
66
79
|
var _findVariable2;
|
|
67
|
-
const
|
|
68
|
-
|
|
80
|
+
const definitions = (_findVariable2 = findVariable({
|
|
81
|
+
sourceCode: context.sourceCode,
|
|
82
|
+
identifier: property.value.object
|
|
83
|
+
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
69
84
|
if (!definitions || !definitions.length) {
|
|
70
85
|
return false;
|
|
71
86
|
}
|
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
2
|
import { createLintRule } from '../utils/create-rule';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
7
|
-
};
|
|
8
|
-
var isParameter = function isParameter(context, variableName) {
|
|
3
|
+
import { getAllowedFunctionCalls, isAllowListedVariable } from '@atlaskit/eslint-utils/allowed-function-calls';
|
|
4
|
+
import { findVariable } from '@atlaskit/eslint-utils/find-variable';
|
|
5
|
+
var isParameter = function isParameter(context, identifier) {
|
|
9
6
|
var _findVariable;
|
|
10
|
-
var definitions = (_findVariable = findVariable(
|
|
7
|
+
var definitions = (_findVariable = findVariable({
|
|
8
|
+
sourceCode: context.sourceCode,
|
|
9
|
+
identifier: identifier
|
|
10
|
+
})) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
11
11
|
if (!definitions || !definitions.length) {
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
var result = definitions[0];
|
|
15
15
|
return result.type === 'Parameter';
|
|
16
16
|
};
|
|
17
|
-
var
|
|
17
|
+
var isIdentifierAllowed = function isIdentifierAllowed(context, identifier) {
|
|
18
18
|
var _parent;
|
|
19
|
-
var
|
|
20
|
-
|
|
19
|
+
var variable = findVariable({
|
|
20
|
+
sourceCode: context.sourceCode,
|
|
21
|
+
identifier: identifier
|
|
22
|
+
});
|
|
21
23
|
if (!variable) {
|
|
22
24
|
return false;
|
|
23
25
|
}
|
|
@@ -30,7 +32,7 @@ var checkIdentifier = function checkIdentifier(context, identifier) {
|
|
|
30
32
|
|
|
31
33
|
// Checking if identifier has been destructured from props within function
|
|
32
34
|
if (variableDefinition.type === 'VariableDeclarator') {
|
|
33
|
-
var _variableDefinition$i, _variableDefinition$i2
|
|
35
|
+
var _variableDefinition$i, _variableDefinition$i2;
|
|
34
36
|
// If it's a let variable, ignore
|
|
35
37
|
if (variableDefinition.parent.kind === 'let') {
|
|
36
38
|
return true;
|
|
@@ -42,16 +44,14 @@ var checkIdentifier = function checkIdentifier(context, identifier) {
|
|
|
42
44
|
// Destructured from member expression
|
|
43
45
|
// e.g. const width = props.width
|
|
44
46
|
if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
|
|
45
|
-
|
|
46
|
-
return isParameter(context, memberIdentifierName);
|
|
47
|
+
return isParameter(context, variableDefinition.init.object);
|
|
47
48
|
}
|
|
48
49
|
// Destructured from object pattern
|
|
49
50
|
// e.g. const { width } = props
|
|
50
|
-
|
|
51
|
-
return isParameter(context, propName);
|
|
51
|
+
return isParameter(context, variableDefinition.init);
|
|
52
52
|
}
|
|
53
53
|
// If identifier has not been deconstructed from parameter or is a RestElement, report warning
|
|
54
|
-
return isParameter(context,
|
|
54
|
+
return isParameter(context, identifier);
|
|
55
55
|
};
|
|
56
56
|
function isPropertyValueAllowed(property, context) {
|
|
57
57
|
if (property.type === 'SpreadElement') {
|
|
@@ -61,26 +61,39 @@ function isPropertyValueAllowed(property, context) {
|
|
|
61
61
|
if (property.value.type === 'Literal') {
|
|
62
62
|
return false;
|
|
63
63
|
} else if (property.value.type === 'Identifier') {
|
|
64
|
-
return
|
|
65
|
-
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier'
|
|
66
|
-
|
|
64
|
+
return isIdentifierAllowed(context, property.value);
|
|
65
|
+
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier') {
|
|
66
|
+
var variable = findVariable({
|
|
67
|
+
sourceCode: context.sourceCode,
|
|
68
|
+
identifier: property.value.callee
|
|
69
|
+
});
|
|
70
|
+
// Anything returned by getAllowedFunctionCalls should be used in css prop instead
|
|
71
|
+
var functionAllowList = getAllowedFunctionCalls(context.options);
|
|
72
|
+
if (!variable || isAllowListedVariable({
|
|
73
|
+
allowList: functionAllowList,
|
|
74
|
+
variable: variable
|
|
75
|
+
})) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
67
78
|
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
68
79
|
var _findVariable2;
|
|
69
|
-
var
|
|
70
|
-
|
|
80
|
+
var definitions = (_findVariable2 = findVariable({
|
|
81
|
+
sourceCode: context.sourceCode,
|
|
82
|
+
identifier: property.value.object
|
|
83
|
+
})) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
71
84
|
if (!definitions || !definitions.length) {
|
|
72
85
|
return false;
|
|
73
86
|
}
|
|
74
|
-
var
|
|
75
|
-
if (!
|
|
87
|
+
var _variable = definitions[0];
|
|
88
|
+
if (!_variable) {
|
|
76
89
|
return false;
|
|
77
90
|
}
|
|
78
|
-
var varType =
|
|
91
|
+
var varType = _variable.type;
|
|
79
92
|
if (varType === 'Variable') {
|
|
80
|
-
if (!
|
|
93
|
+
if (!_variable.node.init) {
|
|
81
94
|
return false;
|
|
82
95
|
}
|
|
83
|
-
var varSource =
|
|
96
|
+
var varSource = _variable.node.init.type;
|
|
84
97
|
// Variables initialised by a call expression or object expression are ok
|
|
85
98
|
if (varSource === 'CallExpression' || varSource === 'ObjectExpression') {
|
|
86
99
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-ui-styling-standard",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.5",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "The eslint plugin to enforce and educate on Atlassian's UI Styling Standard",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,8 +49,9 @@
|
|
|
49
49
|
"outdent": "^0.5.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
+
"@af/formatting": "*",
|
|
52
53
|
"@atlaskit/ds-lib": "^2.3.0",
|
|
53
|
-
"@atlaskit/eslint-plugin-design-system": "^9.
|
|
54
|
+
"@atlaskit/eslint-plugin-design-system": "^9.7.0",
|
|
54
55
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
55
56
|
"@atlassian/codegen": "*",
|
|
56
57
|
"@compiled/eslint-plugin": "^0.13.6",
|
|
@@ -58,7 +59,6 @@
|
|
|
58
59
|
"@types/estraverse": "^5.1.7",
|
|
59
60
|
"eslint": "^8.49.0",
|
|
60
61
|
"lodash": "^4.17.21",
|
|
61
|
-
"prettier": "^2.8.0",
|
|
62
62
|
"ts-node": "^10.9.1",
|
|
63
63
|
"tsconfig-paths": "^4.2.0",
|
|
64
64
|
"typescript": "~5.4.2"
|
package/scripts/codegen.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { extname, join, relative } from 'path';
|
|
|
4
4
|
|
|
5
5
|
import camelCase from 'lodash/camelCase';
|
|
6
6
|
import outdent from 'outdent';
|
|
7
|
-
import
|
|
7
|
+
import format from '@af/formatting/sync';
|
|
8
8
|
|
|
9
9
|
import { createSignedArtifact } from '@atlassian/codegen';
|
|
10
10
|
|
|
@@ -155,19 +155,12 @@ async function generatePresetConfig(
|
|
|
155
155
|
* Write contents to a given file, creating a signed artifact if it's not a markdown file.
|
|
156
156
|
*/
|
|
157
157
|
async function writeFile(filepath: string, code: string) {
|
|
158
|
-
const config = await resolveConfig(filepath);
|
|
159
158
|
await fs.writeFile(
|
|
160
159
|
filepath,
|
|
161
160
|
extname(filepath).includes('.md')
|
|
162
|
-
? format(code,
|
|
163
|
-
...config,
|
|
164
|
-
filepath,
|
|
165
|
-
})
|
|
161
|
+
? format(code, 'markdown')
|
|
166
162
|
: createSignedArtifact(
|
|
167
|
-
format(code,
|
|
168
|
-
...config,
|
|
169
|
-
filepath,
|
|
170
|
-
}),
|
|
163
|
+
format(code, 'typescript'),
|
|
171
164
|
codegenCommand,
|
|
172
165
|
),
|
|
173
166
|
);
|
|
@@ -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
|
}
|
|
@@ -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