@atlaskit/eslint-plugin-ui-styling-standard 0.8.4 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +2 -0
  3. package/constellation/enforce-style-prop/usage.mdx +38 -0
  4. package/constellation/index/overview.mdx +2 -0
  5. package/constellation/no-array-arguments/usage.mdx +45 -0
  6. package/dist/cjs/presets/all.codegen.js +3 -1
  7. package/dist/cjs/presets/recommended.codegen.js +3 -1
  8. package/dist/cjs/rules/enforce-style-prop/index.js +141 -0
  9. package/dist/cjs/rules/index.codegen.js +5 -1
  10. package/dist/cjs/rules/no-array-arguments/index.js +92 -0
  11. package/dist/es2019/presets/all.codegen.js +3 -1
  12. package/dist/es2019/presets/recommended.codegen.js +3 -1
  13. package/dist/es2019/rules/enforce-style-prop/index.js +133 -0
  14. package/dist/es2019/rules/index.codegen.js +5 -1
  15. package/dist/es2019/rules/no-array-arguments/index.js +68 -0
  16. package/dist/esm/presets/all.codegen.js +3 -1
  17. package/dist/esm/presets/recommended.codegen.js +3 -1
  18. package/dist/esm/rules/enforce-style-prop/index.js +135 -0
  19. package/dist/esm/rules/index.codegen.js +5 -1
  20. package/dist/esm/rules/no-array-arguments/index.js +86 -0
  21. package/dist/types/index.codegen.d.ts +4 -0
  22. package/dist/types/presets/all.codegen.d.ts +3 -1
  23. package/dist/types/presets/recommended.codegen.d.ts +3 -1
  24. package/dist/types/rules/enforce-style-prop/index.d.ts +3 -0
  25. package/dist/types/rules/index.codegen.d.ts +2 -0
  26. package/dist/types/rules/no-array-arguments/index.d.ts +2 -0
  27. package/dist/types-ts4.5/index.codegen.d.ts +4 -0
  28. package/dist/types-ts4.5/presets/all.codegen.d.ts +3 -1
  29. package/dist/types-ts4.5/presets/recommended.codegen.d.ts +3 -1
  30. package/dist/types-ts4.5/rules/enforce-style-prop/index.d.ts +3 -0
  31. package/dist/types-ts4.5/rules/index.codegen.d.ts +2 -0
  32. package/dist/types-ts4.5/rules/no-array-arguments/index.d.ts +2 -0
  33. package/package.json +4 -4
  34. package/src/presets/all.codegen.tsx +3 -1
  35. package/src/presets/recommended.codegen.tsx +3 -1
  36. package/src/rules/enforce-style-prop/README.md +36 -0
  37. package/src/rules/enforce-style-prop/__tests__/rule.test.tsx +231 -0
  38. package/src/rules/enforce-style-prop/index.tsx +169 -0
  39. package/src/rules/index.codegen.tsx +5 -1
  40. package/src/rules/no-array-arguments/README.md +43 -0
  41. package/src/rules/no-array-arguments/__tests__/rule.test.tsx +116 -0
  42. package/src/rules/no-array-arguments/index.tsx +87 -0
@@ -0,0 +1,68 @@
1
+ import { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
2
+ import { createLintRule } from '../utils/create-rule';
3
+ const schema = [{
4
+ type: 'object',
5
+ properties: {
6
+ importSources: {
7
+ type: 'array',
8
+ items: {
9
+ type: 'string'
10
+ },
11
+ uniqueItems: true
12
+ }
13
+ }
14
+ }];
15
+ export const rule = createLintRule({
16
+ meta: {
17
+ name: 'no-array-arguments',
18
+ docs: {
19
+ description: 'Prevents usage of array arguments to style declaration functions',
20
+ recommended: true,
21
+ severity: 'warn'
22
+ },
23
+ messages: {
24
+ 'no-array-arguments': "Don't pass multiple value in an array. Pass them as multiple arguments instead."
25
+ },
26
+ type: 'problem',
27
+ fixable: 'code',
28
+ schema
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
+ for (const argument of node.arguments) {
41
+ if (argument.type === 'ArrayExpression') {
42
+ context.report({
43
+ node: argument,
44
+ messageId: 'no-array-arguments',
45
+ fix(fixer) {
46
+ if (argument.elements.length === 0) {
47
+ /**
48
+ * Don't autofix if it's an empty array.
49
+ *
50
+ * I couldn't figure out how to get rid of the comma afterwards,
51
+ * so the autofix was producing syntax problems.
52
+ *
53
+ * This is an edge case that shouldn't actually be happening,
54
+ * but if it does it's not hard to just delete the empty array...
55
+ */
56
+ return null;
57
+ }
58
+ const items = argument.elements.filter(value => value !== null).map(element => context.sourceCode.getText(element));
59
+ return fixer.replaceText(argument, items.join(', '));
60
+ }
61
+ });
62
+ }
63
+ }
64
+ }
65
+ };
66
+ }
67
+ });
68
+ export default rule;
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::f2d8f76f2f41101bd777223bb368ede0>>
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',
12
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
11
13
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
14
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
15
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::f2d8f76f2f41101bd777223bb368ede0>>
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',
12
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
11
13
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
12
14
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
13
15
  '@atlaskit/ui-styling-standard/no-important-styles': '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,17 +1,21 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::c50c5112f3633542ef17c291cd9d88a8>>
3
+ * @codegen <<SignedSource::0611efa9bbe46ece121a804fa5891dd6>>
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';
9
+ import noArrayArguments from './no-array-arguments';
8
10
  import noClassnameProp from './no-classname-prop';
9
11
  import noContainerQueries from './no-container-queries';
10
12
  import noImportantStyles from './no-important-styles';
11
13
  import noNestedSelectors from './no-nested-selectors';
12
14
  export default {
13
15
  'convert-props-syntax': convertPropsSyntax,
16
+ 'enforce-style-prop': enforceStyleProp,
14
17
  'local-cx-xcss': localCxXcss,
18
+ 'no-array-arguments': noArrayArguments,
15
19
  'no-classname-prop': noClassnameProp,
16
20
  'no-container-queries': noContainerQueries,
17
21
  'no-important-styles': noImportantStyles,
@@ -0,0 +1,86 @@
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 { getImportSources, hasStyleObjectArguments } from '@atlaskit/eslint-utils/is-supported-import';
5
+ import { createLintRule } from '../utils/create-rule';
6
+ var schema = [{
7
+ type: 'object',
8
+ properties: {
9
+ importSources: {
10
+ type: 'array',
11
+ items: {
12
+ type: 'string'
13
+ },
14
+ uniqueItems: true
15
+ }
16
+ }
17
+ }];
18
+ export var rule = createLintRule({
19
+ meta: {
20
+ name: 'no-array-arguments',
21
+ docs: {
22
+ description: 'Prevents usage of array arguments to style declaration functions',
23
+ recommended: true,
24
+ severity: 'warn'
25
+ },
26
+ messages: {
27
+ 'no-array-arguments': "Don't pass multiple value in an array. Pass them as multiple arguments instead."
28
+ },
29
+ type: 'problem',
30
+ fixable: 'code',
31
+ schema: schema
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 _iterator = _createForOfIteratorHelper(node.arguments),
43
+ _step;
44
+ try {
45
+ var _loop = function _loop() {
46
+ var argument = _step.value;
47
+ if (argument.type === 'ArrayExpression') {
48
+ context.report({
49
+ node: argument,
50
+ messageId: 'no-array-arguments',
51
+ fix: function fix(fixer) {
52
+ if (argument.elements.length === 0) {
53
+ /**
54
+ * Don't autofix if it's an empty array.
55
+ *
56
+ * I couldn't figure out how to get rid of the comma afterwards,
57
+ * so the autofix was producing syntax problems.
58
+ *
59
+ * This is an edge case that shouldn't actually be happening,
60
+ * but if it does it's not hard to just delete the empty array...
61
+ */
62
+ return null;
63
+ }
64
+ var items = argument.elements.filter(function (value) {
65
+ return value !== null;
66
+ }).map(function (element) {
67
+ return context.sourceCode.getText(element);
68
+ });
69
+ return fixer.replaceText(argument, items.join(', '));
70
+ }
71
+ });
72
+ }
73
+ };
74
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
75
+ _loop();
76
+ }
77
+ } catch (err) {
78
+ _iterator.e(err);
79
+ } finally {
80
+ _iterator.f();
81
+ }
82
+ }
83
+ };
84
+ }
85
+ });
86
+ export default rule;
@@ -4,7 +4,9 @@ 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;
9
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
8
10
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
9
11
  '@atlaskit/ui-styling-standard/no-container-queries': string;
10
12
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -35,7 +37,9 @@ export declare const configs: {
35
37
  plugins: string[];
36
38
  rules: {
37
39
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
40
+ '@atlaskit/ui-styling-standard/enforce-style-prop': string;
38
41
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
42
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
39
43
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
40
44
  '@atlaskit/ui-styling-standard/no-container-queries': string;
41
45
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::f2d8f76f2f41101bd777223bb368ede0>>
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;
12
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
11
13
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
14
  '@atlaskit/ui-styling-standard/no-container-queries': string;
13
15
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::f2d8f76f2f41101bd777223bb368ede0>>
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;
12
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
11
13
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
14
  '@atlaskit/ui-styling-standard/no-container-queries': string;
13
15
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -1,6 +1,8 @@
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;
5
+ 'no-array-arguments': import("eslint").Rule.RuleModule;
4
6
  'no-classname-prop': import("eslint").Rule.RuleModule;
5
7
  'no-container-queries': import("eslint").Rule.RuleModule;
6
8
  'no-important-styles': import("eslint").Rule.RuleModule;
@@ -0,0 +1,2 @@
1
+ export declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
@@ -4,7 +4,9 @@ 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;
9
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
8
10
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
9
11
  '@atlaskit/ui-styling-standard/no-container-queries': string;
10
12
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -35,7 +37,9 @@ export declare const configs: {
35
37
  plugins: string[];
36
38
  rules: {
37
39
  '@atlaskit/ui-styling-standard/convert-props-syntax': string;
40
+ '@atlaskit/ui-styling-standard/enforce-style-prop': string;
38
41
  '@atlaskit/ui-styling-standard/local-cx-xcss': string;
42
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
39
43
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
40
44
  '@atlaskit/ui-styling-standard/no-container-queries': string;
41
45
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::f2d8f76f2f41101bd777223bb368ede0>>
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;
12
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
11
13
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
14
  '@atlaskit/ui-styling-standard/no-container-queries': string;
13
15
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::f2d8f76f2f41101bd777223bb368ede0>>
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;
12
+ '@atlaskit/ui-styling-standard/no-array-arguments': string;
11
13
  '@atlaskit/ui-styling-standard/no-classname-prop': string;
12
14
  '@atlaskit/ui-styling-standard/no-container-queries': string;
13
15
  '@atlaskit/ui-styling-standard/no-important-styles': string;
@@ -0,0 +1,3 @@
1
+ import type { Rule } from 'eslint';
2
+ export declare const rule: Rule.RuleModule;
3
+ export default rule;
@@ -1,6 +1,8 @@
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;
5
+ 'no-array-arguments': import("eslint").Rule.RuleModule;
4
6
  'no-classname-prop': import("eslint").Rule.RuleModule;
5
7
  'no-container-queries': import("eslint").Rule.RuleModule;
6
8
  'no-important-styles': import("eslint").Rule.RuleModule;
@@ -0,0 +1,2 @@
1
+ export declare const rule: import("eslint").Rule.RuleModule;
2
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/eslint-plugin-ui-styling-standard",
3
- "version": "0.8.4",
3
+ "version": "0.9.1",
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",
@@ -39,7 +39,7 @@
39
39
  ".": "./src/index.tsx"
40
40
  },
41
41
  "dependencies": {
42
- "@atlaskit/eslint-utils": "^1.1.0",
42
+ "@atlaskit/eslint-utils": "^1.2.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "@typescript-eslint/utils": "^5.48.1",
45
45
  "eslint-codemod-utils": "^1.8.6",
@@ -47,8 +47,8 @@
47
47
  "estraverse": "^5.3.0"
48
48
  },
49
49
  "devDependencies": {
50
- "@atlaskit/ds-lib": "^2.2.0",
51
- "@atlaskit/eslint-plugin-design-system": "^9.4.0",
50
+ "@atlaskit/ds-lib": "^2.3.0",
51
+ "@atlaskit/eslint-plugin-design-system": "^9.5.0",
52
52
  "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
53
53
  "@atlassian/codegen": "*",
54
54
  "@compiled/eslint-plugin": "^0.13.6",
@@ -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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::f2d8f76f2f41101bd777223bb368ede0>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -11,7 +11,9 @@ export default {
11
11
  ],
12
12
  rules: {
13
13
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
14
+ '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
14
15
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
16
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
15
17
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
16
18
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
17
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
@@ -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::7d08e77b09892b3650a472341ec77df3>>
3
+ * @codegen <<SignedSource::f2d8f76f2f41101bd777223bb368ede0>>
4
4
  * @codegenCommand yarn workspace @atlaskit/eslint-plugin-ui-styling-standard codegen
5
5
  */
6
6
  export default {
@@ -11,7 +11,9 @@ export default {
11
11
  ],
12
12
  rules: {
13
13
  '@atlaskit/ui-styling-standard/convert-props-syntax': 'error',
14
+ '@atlaskit/ui-styling-standard/enforce-style-prop': 'warn',
14
15
  '@atlaskit/ui-styling-standard/local-cx-xcss': 'warn',
16
+ '@atlaskit/ui-styling-standard/no-array-arguments': 'warn',
15
17
  '@atlaskit/ui-styling-standard/no-classname-prop': 'warn',
16
18
  '@atlaskit/ui-styling-standard/no-container-queries': 'warn',
17
19
  '@atlaskit/ui-styling-standard/no-important-styles': 'warn',
@@ -0,0 +1,36 @@
1
+ This rule enforces passing dynamic CSS values to the `style` prop in JSX components.
2
+
3
+ We only want `props.style` to be used for dynamic values that cannot be easily determined at build time, e.g. `<div style={{ width: props.width }}>`. No statics values such as numbers, strings or any other statically analysable values should be passed to the `style` attribute. Instead, static CSS values should be passed into the `css` prop in JSX components.
4
+
5
+ ## Examples
6
+
7
+ ### Incorrect
8
+
9
+ ```tsx
10
+ function Component() {
11
+ return (
12
+ <div
13
+ style={{
14
+ margin: 0,
15
+ color: 'red',
16
+ }}
17
+ />
18
+ );
19
+ }
20
+ ```
21
+
22
+ ### Correct
23
+
24
+ ```tsx
25
+ function Component(props) {
26
+ return (
27
+ <div
28
+ style={{
29
+ width: props.width,
30
+ '--my-nested-width': props.width,
31
+ }}
32
+ css={css({ margin: 0, color: 'red' })}
33
+ />
34
+ );
35
+ }
36
+ ```