@atlaskit/eslint-plugin-ui-styling-standard 0.9.0 → 0.10.0
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 +12 -0
- package/README.md +2 -0
- package/constellation/enforce-style-prop/usage.mdx +38 -0
- package/constellation/index/overview.mdx +2 -0
- package/constellation/no-dynamic-styles/usage.mdx +128 -0
- package/dist/cjs/presets/all.codegen.js +3 -1
- package/dist/cjs/presets/recommended.codegen.js +3 -1
- package/dist/cjs/rules/enforce-style-prop/index.js +141 -0
- package/dist/cjs/rules/index.codegen.js +5 -1
- package/dist/cjs/rules/no-dynamic-styles/index.js +69 -0
- package/dist/es2019/presets/all.codegen.js +3 -1
- package/dist/es2019/presets/recommended.codegen.js +3 -1
- package/dist/es2019/rules/enforce-style-prop/index.js +133 -0
- package/dist/es2019/rules/index.codegen.js +5 -1
- package/dist/es2019/rules/no-dynamic-styles/index.js +51 -0
- package/dist/esm/presets/all.codegen.js +3 -1
- package/dist/esm/presets/recommended.codegen.js +3 -1
- package/dist/esm/rules/enforce-style-prop/index.js +135 -0
- package/dist/esm/rules/index.codegen.js +5 -1
- package/dist/esm/rules/no-dynamic-styles/index.js +62 -0
- package/dist/types/index.codegen.d.ts +4 -0
- package/dist/types/presets/all.codegen.d.ts +3 -1
- package/dist/types/presets/recommended.codegen.d.ts +3 -1
- package/dist/types/rules/enforce-style-prop/index.d.ts +3 -0
- package/dist/types/rules/index.codegen.d.ts +2 -0
- package/dist/types/rules/no-dynamic-styles/index.d.ts +2 -0
- package/dist/types-ts4.5/index.codegen.d.ts +4 -0
- package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
- package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
- package/dist/types-ts4.5/rules/enforce-style-prop/index.d.ts +3 -0
- package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
- package/dist/types-ts4.5/rules/no-dynamic-styles/index.d.ts +2 -0
- package/package.json +3 -2
- package/src/presets/all.codegen.tsx +3 -1
- package/src/presets/recommended.codegen.tsx +3 -1
- package/src/rules/enforce-style-prop/README.md +36 -0
- package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +231 -0
- package/src/rules/enforce-style-prop/index.tsx +169 -0
- package/src/rules/index.codegen.tsx +5 -1
- package/src/rules/no-dynamic-styles/README.md +126 -0
- package/src/rules/no-dynamic-styles/__tests__/rule.test.tsx +128 -0
- package/src/rules/no-dynamic-styles/index.tsx +63 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
const findVariable = (context, name) => {
|
|
4
|
+
return context.getScope().variables.find(varb => varb.name === name);
|
|
5
|
+
};
|
|
6
|
+
const isParameter = (context, variableName) => {
|
|
7
|
+
var _findVariable;
|
|
8
|
+
const definitions = (_findVariable = findVariable(context, variableName)) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
9
|
+
if (!definitions || !definitions.length) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const result = definitions[0];
|
|
13
|
+
return result.type === 'Parameter';
|
|
14
|
+
};
|
|
15
|
+
const checkIdentifier = (context, identifier) => {
|
|
16
|
+
var _parent;
|
|
17
|
+
const val = identifier.name;
|
|
18
|
+
const variable = findVariable(context, val);
|
|
19
|
+
if (!variable) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const variableDefinition = variable.defs[0].node;
|
|
23
|
+
|
|
24
|
+
// If identifier is a RestElement, report warning
|
|
25
|
+
if (((_parent = variable.identifiers[0].parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'RestElement') {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Checking if identifier has been destructured from props within function
|
|
30
|
+
if (variableDefinition.type === 'VariableDeclarator') {
|
|
31
|
+
var _variableDefinition$i, _variableDefinition$i2, _variableDefinition$i3;
|
|
32
|
+
// If it's a let variable, ignore
|
|
33
|
+
if (variableDefinition.parent.kind === 'let') {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
// If it's initialised by a call expression, ignore
|
|
37
|
+
if (((_variableDefinition$i = variableDefinition.init) === null || _variableDefinition$i === void 0 ? void 0 : _variableDefinition$i.type) === 'CallExpression') {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
// Destructured from member expression
|
|
41
|
+
// e.g. const width = props.width
|
|
42
|
+
if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
|
|
43
|
+
const memberIdentifierName = variableDefinition.init.object.name;
|
|
44
|
+
return isParameter(context, memberIdentifierName);
|
|
45
|
+
}
|
|
46
|
+
// Destructured from object pattern
|
|
47
|
+
// e.g. const { width } = props
|
|
48
|
+
const propName = (_variableDefinition$i3 = variableDefinition.init) === null || _variableDefinition$i3 === void 0 ? void 0 : _variableDefinition$i3.name;
|
|
49
|
+
return isParameter(context, propName);
|
|
50
|
+
}
|
|
51
|
+
// If identifier has not been deconstructed from parameter or is a RestElement, report warning
|
|
52
|
+
return isParameter(context, val);
|
|
53
|
+
};
|
|
54
|
+
function isPropertyValueAllowed(property, context) {
|
|
55
|
+
if (property.type === 'SpreadElement') {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
// property.type === 'Property', moving on to check if value is static
|
|
59
|
+
if (property.value.type === 'Literal') {
|
|
60
|
+
return false;
|
|
61
|
+
} else if (property.value.type === 'Identifier') {
|
|
62
|
+
return checkIdentifier(context, property.value);
|
|
63
|
+
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier' && property.value.callee.name === 'token') {
|
|
64
|
+
return false;
|
|
65
|
+
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
66
|
+
var _findVariable2;
|
|
67
|
+
const val = property.value.object.name;
|
|
68
|
+
const definitions = (_findVariable2 = findVariable(context, val)) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
69
|
+
if (!definitions || !definitions.length) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
const variable = definitions[0];
|
|
73
|
+
if (!variable) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const varType = variable.type;
|
|
77
|
+
if (varType === 'Variable') {
|
|
78
|
+
if (!variable.node.init) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const varSource = variable.node.init.type;
|
|
82
|
+
// Variables initialised by a call expression or object expression are ok
|
|
83
|
+
if (varSource === 'CallExpression' || varSource === 'ObjectExpression') {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
// Check if member expression matches with function argument
|
|
87
|
+
} else if (varType !== 'Parameter') {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
export const rule = createLintRule({
|
|
94
|
+
meta: {
|
|
95
|
+
name: 'enforce-style-prop',
|
|
96
|
+
docs: {
|
|
97
|
+
description: 'Disallows usage of static styles in the `style` attribute in components',
|
|
98
|
+
recommended: true,
|
|
99
|
+
severity: 'warn'
|
|
100
|
+
},
|
|
101
|
+
messages: {
|
|
102
|
+
'enforce-style-prop': 'Avoid adding static values to the style prop. Use the css prop for static styles instead.'
|
|
103
|
+
},
|
|
104
|
+
type: 'problem'
|
|
105
|
+
},
|
|
106
|
+
create(context) {
|
|
107
|
+
return {
|
|
108
|
+
'JSXAttribute[name.name="style"] > JSXExpressionContainer': node => {
|
|
109
|
+
if (!isNodeOfType(node, 'JSXExpressionContainer')) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
// we've reached an attribute named style
|
|
113
|
+
|
|
114
|
+
if (node.expression.type === 'ObjectExpression') {
|
|
115
|
+
node.expression.properties.forEach(value => {
|
|
116
|
+
if (!isPropertyValueAllowed(value, context)) {
|
|
117
|
+
context.report({
|
|
118
|
+
node: value,
|
|
119
|
+
messageId: 'enforce-style-prop'
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
context.report({
|
|
125
|
+
node: node,
|
|
126
|
+
messageId: 'enforce-style-prop'
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
export default rule;
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::12e455a3866637a2dc91ce8751babd54>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import convertPropsSyntax from './convert-props-syntax';
|
|
7
|
+
import enforceStyleProp from './enforce-style-prop';
|
|
7
8
|
import localCxXcss from './local-cx-xcss';
|
|
8
9
|
import noArrayArguments from './no-array-arguments';
|
|
9
10
|
import noClassnameProp from './no-classname-prop';
|
|
10
11
|
import noContainerQueries from './no-container-queries';
|
|
12
|
+
import noDynamicStyles from './no-dynamic-styles';
|
|
11
13
|
import noImportantStyles from './no-important-styles';
|
|
12
14
|
import noNestedSelectors from './no-nested-selectors';
|
|
13
15
|
export default {
|
|
14
16
|
'convert-props-syntax': convertPropsSyntax,
|
|
17
|
+
'enforce-style-prop': enforceStyleProp,
|
|
15
18
|
'local-cx-xcss': localCxXcss,
|
|
16
19
|
'no-array-arguments': noArrayArguments,
|
|
17
20
|
'no-classname-prop': noClassnameProp,
|
|
18
21
|
'no-container-queries': noContainerQueries,
|
|
22
|
+
'no-dynamic-styles': noDynamicStyles,
|
|
19
23
|
'no-important-styles': noImportantStyles,
|
|
20
24
|
'no-nested-selectors': noNestedSelectors
|
|
21
25
|
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import esquery from 'esquery';
|
|
2
|
+
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
3
|
+
import { createLintRule } from '../utils/create-rule';
|
|
4
|
+
const schema = [{
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
importSources: {
|
|
8
|
+
type: 'array',
|
|
9
|
+
items: {
|
|
10
|
+
type: 'string'
|
|
11
|
+
},
|
|
12
|
+
uniqueItems: true
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}];
|
|
16
|
+
export const rule = createLintRule({
|
|
17
|
+
meta: {
|
|
18
|
+
name: 'no-dynamic-styles',
|
|
19
|
+
docs: {
|
|
20
|
+
description: 'Disallows use of dynamic styles in CSS-in-JS calls',
|
|
21
|
+
recommended: true,
|
|
22
|
+
severity: 'warn'
|
|
23
|
+
},
|
|
24
|
+
schema,
|
|
25
|
+
messages: {
|
|
26
|
+
'no-dynamic-styles': 'Dynamic styles are not allowed. Instead use the style prop to apply styles derived from component props.'
|
|
27
|
+
},
|
|
28
|
+
type: 'problem'
|
|
29
|
+
},
|
|
30
|
+
create(context) {
|
|
31
|
+
const importSources = getImportSources(context);
|
|
32
|
+
return {
|
|
33
|
+
CallExpression(node) {
|
|
34
|
+
const {
|
|
35
|
+
references
|
|
36
|
+
} = context.sourceCode.getScope(node);
|
|
37
|
+
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const matches = esquery(node, 'ArrowFunctionExpression, FunctionExpression');
|
|
41
|
+
for (const match of matches) {
|
|
42
|
+
context.report({
|
|
43
|
+
node: match,
|
|
44
|
+
messageId: 'no-dynamic-styles'
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
export default rule;
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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
9
|
'@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
|
|
10
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
12
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
14
16
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
15
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
16
18
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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
9
|
'@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
|
|
10
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
|
|
10
11
|
'@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
|
|
12
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-container-queries': 'warn',
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': 'warn',
|
|
14
16
|
'@atlaskit/ui-styling-standard/no-important-styles': 'warn',
|
|
15
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': 'warn',
|
|
16
18
|
'@atlaskit/design-system/consistent-css-prop-usage': ['warn', {
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { isNodeOfType } from 'eslint-codemod-utils';
|
|
2
|
+
import { createLintRule } from '../utils/create-rule';
|
|
3
|
+
var findVariable = function findVariable(context, name) {
|
|
4
|
+
return context.getScope().variables.find(function (varb) {
|
|
5
|
+
return varb.name === name;
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
var isParameter = function isParameter(context, variableName) {
|
|
9
|
+
var _findVariable;
|
|
10
|
+
var definitions = (_findVariable = findVariable(context, variableName)) === null || _findVariable === void 0 ? void 0 : _findVariable.defs;
|
|
11
|
+
if (!definitions || !definitions.length) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
var result = definitions[0];
|
|
15
|
+
return result.type === 'Parameter';
|
|
16
|
+
};
|
|
17
|
+
var checkIdentifier = function checkIdentifier(context, identifier) {
|
|
18
|
+
var _parent;
|
|
19
|
+
var val = identifier.name;
|
|
20
|
+
var variable = findVariable(context, val);
|
|
21
|
+
if (!variable) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
var variableDefinition = variable.defs[0].node;
|
|
25
|
+
|
|
26
|
+
// If identifier is a RestElement, report warning
|
|
27
|
+
if (((_parent = variable.identifiers[0].parent) === null || _parent === void 0 ? void 0 : _parent.type) === 'RestElement') {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Checking if identifier has been destructured from props within function
|
|
32
|
+
if (variableDefinition.type === 'VariableDeclarator') {
|
|
33
|
+
var _variableDefinition$i, _variableDefinition$i2, _variableDefinition$i3;
|
|
34
|
+
// If it's a let variable, ignore
|
|
35
|
+
if (variableDefinition.parent.kind === 'let') {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
// If it's initialised by a call expression, ignore
|
|
39
|
+
if (((_variableDefinition$i = variableDefinition.init) === null || _variableDefinition$i === void 0 ? void 0 : _variableDefinition$i.type) === 'CallExpression') {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
// Destructured from member expression
|
|
43
|
+
// e.g. const width = props.width
|
|
44
|
+
if (((_variableDefinition$i2 = variableDefinition.init) === null || _variableDefinition$i2 === void 0 ? void 0 : _variableDefinition$i2.type) === 'MemberExpression') {
|
|
45
|
+
var memberIdentifierName = variableDefinition.init.object.name;
|
|
46
|
+
return isParameter(context, memberIdentifierName);
|
|
47
|
+
}
|
|
48
|
+
// Destructured from object pattern
|
|
49
|
+
// e.g. const { width } = props
|
|
50
|
+
var propName = (_variableDefinition$i3 = variableDefinition.init) === null || _variableDefinition$i3 === void 0 ? void 0 : _variableDefinition$i3.name;
|
|
51
|
+
return isParameter(context, propName);
|
|
52
|
+
}
|
|
53
|
+
// If identifier has not been deconstructed from parameter or is a RestElement, report warning
|
|
54
|
+
return isParameter(context, val);
|
|
55
|
+
};
|
|
56
|
+
function isPropertyValueAllowed(property, context) {
|
|
57
|
+
if (property.type === 'SpreadElement') {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
// property.type === 'Property', moving on to check if value is static
|
|
61
|
+
if (property.value.type === 'Literal') {
|
|
62
|
+
return false;
|
|
63
|
+
} else if (property.value.type === 'Identifier') {
|
|
64
|
+
return checkIdentifier(context, property.value);
|
|
65
|
+
} else if (property.value.type === 'CallExpression' && property.value.callee.type === 'Identifier' && property.value.callee.name === 'token') {
|
|
66
|
+
return false;
|
|
67
|
+
} else if (property.value.type === 'MemberExpression' && property.value.object.type === 'Identifier') {
|
|
68
|
+
var _findVariable2;
|
|
69
|
+
var val = property.value.object.name;
|
|
70
|
+
var definitions = (_findVariable2 = findVariable(context, val)) === null || _findVariable2 === void 0 ? void 0 : _findVariable2.defs;
|
|
71
|
+
if (!definitions || !definitions.length) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
var variable = definitions[0];
|
|
75
|
+
if (!variable) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
var varType = variable.type;
|
|
79
|
+
if (varType === 'Variable') {
|
|
80
|
+
if (!variable.node.init) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
var varSource = variable.node.init.type;
|
|
84
|
+
// Variables initialised by a call expression or object expression are ok
|
|
85
|
+
if (varSource === 'CallExpression' || varSource === 'ObjectExpression') {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
// Check if member expression matches with function argument
|
|
89
|
+
} else if (varType !== 'Parameter') {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
export var rule = createLintRule({
|
|
96
|
+
meta: {
|
|
97
|
+
name: 'enforce-style-prop',
|
|
98
|
+
docs: {
|
|
99
|
+
description: 'Disallows usage of static styles in the `style` attribute in components',
|
|
100
|
+
recommended: true,
|
|
101
|
+
severity: 'warn'
|
|
102
|
+
},
|
|
103
|
+
messages: {
|
|
104
|
+
'enforce-style-prop': 'Avoid adding static values to the style prop. Use the css prop for static styles instead.'
|
|
105
|
+
},
|
|
106
|
+
type: 'problem'
|
|
107
|
+
},
|
|
108
|
+
create: function create(context) {
|
|
109
|
+
return {
|
|
110
|
+
'JSXAttribute[name.name="style"] > JSXExpressionContainer': function JSXAttributeNameNameStyleJSXExpressionContainer(node) {
|
|
111
|
+
if (!isNodeOfType(node, 'JSXExpressionContainer')) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// we've reached an attribute named style
|
|
115
|
+
|
|
116
|
+
if (node.expression.type === 'ObjectExpression') {
|
|
117
|
+
node.expression.properties.forEach(function (value) {
|
|
118
|
+
if (!isPropertyValueAllowed(value, context)) {
|
|
119
|
+
context.report({
|
|
120
|
+
node: value,
|
|
121
|
+
messageId: 'enforce-style-prop'
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
} else {
|
|
126
|
+
context.report({
|
|
127
|
+
node: node,
|
|
128
|
+
messageId: 'enforce-style-prop'
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
export default rule;
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::12e455a3866637a2dc91ce8751babd54>>
|
|
4
4
|
* @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
|
|
5
5
|
*/
|
|
6
6
|
import convertPropsSyntax from './convert-props-syntax';
|
|
7
|
+
import enforceStyleProp from './enforce-style-prop';
|
|
7
8
|
import localCxXcss from './local-cx-xcss';
|
|
8
9
|
import noArrayArguments from './no-array-arguments';
|
|
9
10
|
import noClassnameProp from './no-classname-prop';
|
|
10
11
|
import noContainerQueries from './no-container-queries';
|
|
12
|
+
import noDynamicStyles from './no-dynamic-styles';
|
|
11
13
|
import noImportantStyles from './no-important-styles';
|
|
12
14
|
import noNestedSelectors from './no-nested-selectors';
|
|
13
15
|
export default {
|
|
14
16
|
'convert-props-syntax': convertPropsSyntax,
|
|
17
|
+
'enforce-style-prop': enforceStyleProp,
|
|
15
18
|
'local-cx-xcss': localCxXcss,
|
|
16
19
|
'no-array-arguments': noArrayArguments,
|
|
17
20
|
'no-classname-prop': noClassnameProp,
|
|
18
21
|
'no-container-queries': noContainerQueries,
|
|
22
|
+
'no-dynamic-styles': noDynamicStyles,
|
|
19
23
|
'no-important-styles': noImportantStyles,
|
|
20
24
|
'no-nested-selectors': noNestedSelectors
|
|
21
25
|
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
import esquery from 'esquery';
|
|
5
|
+
import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
|
|
6
|
+
import { createLintRule } from '../utils/create-rule';
|
|
7
|
+
var schema = [{
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
importSources: {
|
|
11
|
+
type: 'array',
|
|
12
|
+
items: {
|
|
13
|
+
type: 'string'
|
|
14
|
+
},
|
|
15
|
+
uniqueItems: true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}];
|
|
19
|
+
export var rule = createLintRule({
|
|
20
|
+
meta: {
|
|
21
|
+
name: 'no-dynamic-styles',
|
|
22
|
+
docs: {
|
|
23
|
+
description: 'Disallows use of dynamic styles in CSS-in-JS calls',
|
|
24
|
+
recommended: true,
|
|
25
|
+
severity: 'warn'
|
|
26
|
+
},
|
|
27
|
+
schema: schema,
|
|
28
|
+
messages: {
|
|
29
|
+
'no-dynamic-styles': 'Dynamic styles are not allowed. Instead use the style prop to apply styles derived from component props.'
|
|
30
|
+
},
|
|
31
|
+
type: 'problem'
|
|
32
|
+
},
|
|
33
|
+
create: function create(context) {
|
|
34
|
+
var importSources = getImportSources(context);
|
|
35
|
+
return {
|
|
36
|
+
CallExpression: function CallExpression(node) {
|
|
37
|
+
var _context$sourceCode$g = context.sourceCode.getScope(node),
|
|
38
|
+
references = _context$sourceCode$g.references;
|
|
39
|
+
if (!hasStyleObjectArguments(node.callee, references, importSources)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
var matches = esquery(node, 'ArrowFunctionExpression, FunctionExpression');
|
|
43
|
+
var _iterator = _createForOfIteratorHelper(matches),
|
|
44
|
+
_step;
|
|
45
|
+
try {
|
|
46
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
47
|
+
var match = _step.value;
|
|
48
|
+
context.report({
|
|
49
|
+
node: match,
|
|
50
|
+
messageId: 'no-dynamic-styles'
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
} catch (err) {
|
|
54
|
+
_iterator.e(err);
|
|
55
|
+
} finally {
|
|
56
|
+
_iterator.f();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
export default rule;
|
|
@@ -4,10 +4,12 @@ export declare const configs: {
|
|
|
4
4
|
plugins: string[];
|
|
5
5
|
rules: {
|
|
6
6
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
7
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
7
8
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
8
9
|
'@atlaskit/ui-styling-standard/no-array-arguments': string;
|
|
9
10
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
12
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
11
13
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
12
14
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
13
15
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -36,10 +38,12 @@ export declare const configs: {
|
|
|
36
38
|
plugins: string[];
|
|
37
39
|
rules: {
|
|
38
40
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
41
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
39
42
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
40
43
|
'@atlaskit/ui-styling-standard/no-array-arguments': string;
|
|
41
44
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
42
45
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
46
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
43
47
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
44
48
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
45
49
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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
9
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
10
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': string;
|
|
12
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
14
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
15
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
16
18
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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
9
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
10
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': string;
|
|
12
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
14
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
15
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
16
18
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
'convert-props-syntax': import("eslint").Rule.RuleModule;
|
|
3
|
+
'enforce-style-prop': import("eslint").Rule.RuleModule;
|
|
3
4
|
'local-cx-xcss': import("eslint").Rule.RuleModule;
|
|
4
5
|
'no-array-arguments': import("eslint").Rule.RuleModule;
|
|
5
6
|
'no-classname-prop': import("eslint").Rule.RuleModule;
|
|
6
7
|
'no-container-queries': import("eslint").Rule.RuleModule;
|
|
8
|
+
'no-dynamic-styles': import("eslint").Rule.RuleModule;
|
|
7
9
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
8
10
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
9
11
|
};
|
|
@@ -4,10 +4,12 @@ export declare const configs: {
|
|
|
4
4
|
plugins: string[];
|
|
5
5
|
rules: {
|
|
6
6
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
7
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
7
8
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
8
9
|
'@atlaskit/ui-styling-standard/no-array-arguments': string;
|
|
9
10
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
12
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
11
13
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
12
14
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
13
15
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -36,10 +38,12 @@ export declare const configs: {
|
|
|
36
38
|
plugins: string[];
|
|
37
39
|
rules: {
|
|
38
40
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
41
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
39
42
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
40
43
|
'@atlaskit/ui-styling-standard/no-array-arguments': string;
|
|
41
44
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
42
45
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
46
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
43
47
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
44
48
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
45
49
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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
9
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
10
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': string;
|
|
12
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
14
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
15
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
16
18
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::8859bbdd2c4bf68ed4a1780f0e776e47>>
|
|
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
9
|
'@atlaskit/ui-styling-standard/convert-props-syntax': string;
|
|
10
|
+
'@atlaskit/ui-styling-standard/enforce-style-prop': string;
|
|
10
11
|
'@atlaskit/ui-styling-standard/local-cx-xcss': string;
|
|
11
12
|
'@atlaskit/ui-styling-standard/no-array-arguments': string;
|
|
12
13
|
'@atlaskit/ui-styling-standard/no-classname-prop': string;
|
|
13
14
|
'@atlaskit/ui-styling-standard/no-container-queries': string;
|
|
15
|
+
'@atlaskit/ui-styling-standard/no-dynamic-styles': string;
|
|
14
16
|
'@atlaskit/ui-styling-standard/no-important-styles': string;
|
|
15
17
|
'@atlaskit/ui-styling-standard/no-nested-selectors': string;
|
|
16
18
|
'@atlaskit/design-system/consistent-css-prop-usage': (string | {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
'convert-props-syntax': import("eslint").Rule.RuleModule;
|
|
3
|
+
'enforce-style-prop': import("eslint").Rule.RuleModule;
|
|
3
4
|
'local-cx-xcss': import("eslint").Rule.RuleModule;
|
|
4
5
|
'no-array-arguments': import("eslint").Rule.RuleModule;
|
|
5
6
|
'no-classname-prop': import("eslint").Rule.RuleModule;
|
|
6
7
|
'no-container-queries': import("eslint").Rule.RuleModule;
|
|
8
|
+
'no-dynamic-styles': import("eslint").Rule.RuleModule;
|
|
7
9
|
'no-important-styles': import("eslint").Rule.RuleModule;
|
|
8
10
|
'no-nested-selectors': import("eslint").Rule.RuleModule;
|
|
9
11
|
};
|