@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
|
@@ -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,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';
|
|
@@ -16,6 +17,7 @@ import noImportedStyleValues from './no-imported-style-values';
|
|
|
16
17
|
import noNestedSelectors from './no-nested-selectors';
|
|
17
18
|
import noUnsafeValues from './no-unsafe-values';
|
|
18
19
|
export default {
|
|
20
|
+
'atlaskit-theme': atlaskitTheme,
|
|
19
21
|
'convert-props-syntax': convertPropsSyntax,
|
|
20
22
|
'enforce-style-prop': enforceStyleProp,
|
|
21
23
|
'local-cx-xcss': localCxXcss,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::16a3441765e5a97f9f32de7fd0de17f0>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import all from './presets/all.codegen';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
|
|
9
10
|
'@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
|
|
10
11
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
export default {
|
|
7
7
|
plugins: ['@atlaskit/ui-styling-standard', '@atlaskit/design-system', '@compiled'],
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': 'error',
|
|
9
10
|
'@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
|
|
10
11
|
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { getImportSources, isCompiled } from '@atlaskit/eslint-utils/is-supported-import';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
var isIdentifierReferenced = function isIdentifierReferenced(hasImportSpecifier, node, references) {
|
|
4
|
+
return references.some(function (reference) {
|
|
5
|
+
var _reference$resolved;
|
|
6
|
+
return reference.identifier === node && ((_reference$resolved = reference.resolved) === null || _reference$resolved === void 0 ? void 0 : _reference$resolved.defs.some(hasImportSpecifier));
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
var isTypographyImportSpecifier = function isTypographyImportSpecifier(def) {
|
|
10
|
+
var _def$parent, _def$parent2, _def$parent3;
|
|
11
|
+
return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent = def.parent) === null || _def$parent === void 0 ? void 0 : _def$parent.type) === 'ImportDeclaration' && (def.node.imported.name === 'typography' && ((_def$parent2 = def.parent) === null || _def$parent2 === void 0 ? void 0 : _def$parent2.source.value) === '@atlaskit/theme' || ((_def$parent3 = def.parent) === null || _def$parent3 === void 0 ? void 0 : _def$parent3.source.value) === '@atlaskit/theme/typography');
|
|
12
|
+
};
|
|
13
|
+
var isElevationImportSpecifier = function isElevationImportSpecifier(def) {
|
|
14
|
+
var _def$parent4, _def$parent5, _def$parent6;
|
|
15
|
+
return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent4 = def.parent) === null || _def$parent4 === void 0 ? void 0 : _def$parent4.type) === 'ImportDeclaration' && (def.node.imported.name === 'elevation' && ((_def$parent5 = def.parent) === null || _def$parent5 === void 0 ? void 0 : _def$parent5.source.value) === '@atlaskit/theme' || ((_def$parent6 = def.parent) === null || _def$parent6 === void 0 ? void 0 : _def$parent6.source.value) === '@atlaskit/theme/elevation');
|
|
16
|
+
};
|
|
17
|
+
var isSkeletonShimmerImportSpecifier = function isSkeletonShimmerImportSpecifier(def) {
|
|
18
|
+
var _def$parent7, _def$parent8, _def$parent9;
|
|
19
|
+
return def.node.type === 'ImportSpecifier' && def.node.imported.type === 'Identifier' && ((_def$parent7 = def.parent) === null || _def$parent7 === void 0 ? void 0 : _def$parent7.type) === 'ImportDeclaration' && def.node.imported.name === 'skeletonShimmer' && typeof ((_def$parent8 = def.parent) === null || _def$parent8 === void 0 ? void 0 : _def$parent8.source.value) === 'string' && ((_def$parent9 = def.parent) === null || _def$parent9 === void 0 || (_def$parent9 = _def$parent9.source.value) === null || _def$parent9 === void 0 ? void 0 : _def$parent9.startsWith('@atlaskit/theme'));
|
|
20
|
+
};
|
|
21
|
+
var checkIdentifier = function checkIdentifier(node, context, references) {
|
|
22
|
+
if (isIdentifierReferenced(isTypographyImportSpecifier, node, references)) {
|
|
23
|
+
context.report({
|
|
24
|
+
messageId: 'usingTypography',
|
|
25
|
+
node: node
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (isIdentifierReferenced(isElevationImportSpecifier, node, references)) {
|
|
29
|
+
context.report({
|
|
30
|
+
messageId: 'usingElevation',
|
|
31
|
+
node: node
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
if (isIdentifierReferenced(isSkeletonShimmerImportSpecifier, node, references)) {
|
|
35
|
+
context.report({
|
|
36
|
+
messageId: 'usingSkeletonShimmer',
|
|
37
|
+
node: node
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export var rule = createLintRule({
|
|
42
|
+
meta: {
|
|
43
|
+
name: 'atlaskit-theme',
|
|
44
|
+
docs: {
|
|
45
|
+
description: 'Ban certain usages of `@atlaskit/theme` that `@compiled/react` does not understand',
|
|
46
|
+
recommended: true,
|
|
47
|
+
severity: 'error'
|
|
48
|
+
},
|
|
49
|
+
messages: {
|
|
50
|
+
usingTypography: 'Typography does not work with Compiled. Please utilise alternatives like Heading or tokens instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
|
|
51
|
+
usingElevation: 'Elevation does not work with Compiled. Please use a token with a fallback instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage',
|
|
52
|
+
usingSkeletonShimmer: 'Skeleton Shimmer does not work with Compiled. Please use an SVG skeleton instead and see https://atlassian.design/components/eslint-plugin-ui-styling-standard/atlaskit-theme/usage'
|
|
53
|
+
},
|
|
54
|
+
schema: [],
|
|
55
|
+
type: 'problem'
|
|
56
|
+
},
|
|
57
|
+
create: function create(context) {
|
|
58
|
+
var importSources = getImportSources(context);
|
|
59
|
+
return {
|
|
60
|
+
'CallExpression Identifier': function CallExpressionIdentifier(node) {
|
|
61
|
+
var _context$getScope = context.getScope(),
|
|
62
|
+
references = _context$getScope.references;
|
|
63
|
+
var ancestors = context.getAncestors();
|
|
64
|
+
|
|
65
|
+
// Check if ancestor node is a call expression to Compiled
|
|
66
|
+
if (ancestors.some(function (ancestor) {
|
|
67
|
+
return ancestor.type === 'CallExpression' && ancestor.callee && isCompiled(ancestor.callee, references, importSources);
|
|
68
|
+
})) {
|
|
69
|
+
// Check identifier for violations
|
|
70
|
+
checkIdentifier(node, context, references);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
'TaggedTemplateExpression Identifier': function TaggedTemplateExpressionIdentifier(node) {
|
|
74
|
+
var _context$getScope2 = context.getScope(),
|
|
75
|
+
references = _context$getScope2.references;
|
|
76
|
+
var ancestors = context.getAncestors();
|
|
77
|
+
|
|
78
|
+
// Check if ancestor node is a tagged template expression to Compiled
|
|
79
|
+
if (ancestors.some(function (ancestor) {
|
|
80
|
+
return ancestor.type === 'TaggedTemplateExpression' && ancestor.tag && isCompiled(ancestor.tag, references, importSources);
|
|
81
|
+
})) {
|
|
82
|
+
// Check identifier for violations
|
|
83
|
+
checkIdentifier(node, context, references);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
export default rule;
|
|
@@ -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;
|
|
@@ -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';
|
|
@@ -16,6 +17,7 @@ import noImportedStyleValues from './no-imported-style-values';
|
|
|
16
17
|
import noNestedSelectors from './no-nested-selectors';
|
|
17
18
|
import noUnsafeValues from './no-unsafe-values';
|
|
18
19
|
export default {
|
|
20
|
+
'atlaskit-theme': atlaskitTheme,
|
|
19
21
|
'convert-props-syntax': convertPropsSyntax,
|
|
20
22
|
'enforce-style-prop': enforceStyleProp,
|
|
21
23
|
'local-cx-xcss': localCxXcss,
|
|
@@ -3,6 +3,7 @@ export declare const configs: {
|
|
|
3
3
|
all: {
|
|
4
4
|
plugins: string[];
|
|
5
5
|
rules: {
|
|
6
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': string;
|
|
6
7
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
7
8
|
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
8
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
@@ -40,6 +41,7 @@ export declare const configs: {
|
|
|
40
41
|
recommended: {
|
|
41
42
|
plugins: string[];
|
|
42
43
|
rules: {
|
|
44
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': string;
|
|
43
45
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
44
46
|
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
45
47
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
plugins: string[];
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': string;
|
|
9
10
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
11
12
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
plugins: string[];
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': string;
|
|
9
10
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
11
12
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
@@ -3,6 +3,7 @@ export declare const configs: {
|
|
|
3
3
|
all: {
|
|
4
4
|
plugins: string[];
|
|
5
5
|
rules: {
|
|
6
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': string;
|
|
6
7
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
7
8
|
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
8
9
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
@@ -40,6 +41,7 @@ export declare const configs: {
|
|
|
40
41
|
recommended: {
|
|
41
42
|
plugins: string[];
|
|
42
43
|
rules: {
|
|
44
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': string;
|
|
43
45
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
44
46
|
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
45
47
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
plugins: string[];
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': string;
|
|
9
10
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
11
12
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::a0c326baf3aa4e87ac809b303ba34682>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
declare const _default: {
|
|
7
7
|
plugins: string[];
|
|
8
8
|
rules: {
|
|
9
|
+
'@atlaskit/ui-styling-standard/atlaskit-theme': string;
|
|
9
10
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
11
12
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
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.6",
|
|
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": "^
|
|
54
|
+
"@atlaskit/eslint-plugin-design-system": "^10.0.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
|
);
|
package/src/index.codegen.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::16a3441765e5a97f9f32de7fd0de17f0>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import all from './presets/all.codegen';
|
|
@@ -9,6 +9,6 @@ import recommended from './presets/recommended.codegen';
|
|
|
9
9
|
export { default as rules } from './rules/index.codegen';
|
|
10
10
|
|
|
11
11
|
export const configs = {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
all,
|
|
13
|
+
recommended,
|
|
14
14
|
};
|