@atlaskit/eslint-plugin-platform 2.2.1 → 2.3.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 +9 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/rules/compiled/expand-spacing-shorthand/index.js +18 -17
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/rules/compiled/expand-spacing-shorthand/index.js +16 -15
- package/dist/esm/index.js +1 -1
- package/dist/esm/rules/compiled/expand-spacing-shorthand/index.js +18 -17
- package/dist/types/index.d.ts +8 -8
- package/dist/types-ts4.5/index.d.ts +8 -8
- package/package.json +2 -2
- package/src/index.tsx +1 -1
- package/src/rules/compiled/expand-spacing-shorthand/__tests__/rule.test.ts +22 -20
- package/src/rules/compiled/expand-spacing-shorthand/index.ts +36 -22
- package/src/rules/feature-gating/README.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/eslint-plugin-platform
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#108485](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/108485)
|
|
8
|
+
[`0c642edaebbbb`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0c642edaebbbb) -
|
|
9
|
+
AFB-822 Modifying expand-spacing-shorthand ESLint rule to not throw error for non-token
|
|
10
|
+
expressions in template strings
|
|
11
|
+
|
|
3
12
|
## 2.2.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/cjs/index.js
CHANGED
|
@@ -74,7 +74,7 @@ var commonConfig = {
|
|
|
74
74
|
// Compiled: rules that are not included via `@compiled/recommended
|
|
75
75
|
'@atlaskit/platform/expand-border-shorthand': 'error',
|
|
76
76
|
'@atlaskit/platform/expand-background-shorthand': 'error',
|
|
77
|
-
'@atlaskit/platform/expand-spacing-shorthand': '
|
|
77
|
+
'@atlaskit/platform/expand-spacing-shorthand': 'error',
|
|
78
78
|
'@compiled/jsx-pragma': ['error', {
|
|
79
79
|
importSources: ['@atlaskit/css'],
|
|
80
80
|
onlyRunIfImportingCompiled: true,
|
|
@@ -48,15 +48,23 @@ var parseTemplateLiteral = function parseTemplateLiteral(templateLiteral, contex
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* Checks if the parsed property values are valid
|
|
52
|
-
* 1.
|
|
53
|
-
* 2.
|
|
54
|
-
* 3.
|
|
51
|
+
* Checks if the parsed property values are valid; values that we shouldn't handle with the fixer:
|
|
52
|
+
* 1. At least one expression in TemplateLiteral is not a token expression
|
|
53
|
+
* 2. Do not contain a token
|
|
54
|
+
* 3. Have length that are not in the range [1, 4] for different spacing directions
|
|
55
|
+
* - No more than 4 to exclude additional values such as `!important`
|
|
56
|
+
* 4. Includes `calc(...)`
|
|
55
57
|
* Then, the rule will return with no error
|
|
56
58
|
* @param propertyValues property values parsed as list of strings
|
|
57
59
|
* @returns boolean
|
|
58
60
|
*/
|
|
59
|
-
var isPropertyValueExempted = function isPropertyValueExempted(propertyValues) {
|
|
61
|
+
var isPropertyValueExempted = function isPropertyValueExempted(templateLiteral, propertyValues) {
|
|
62
|
+
var expressions = templateLiteral.expressions;
|
|
63
|
+
if (!expressions.every(function (expr) {
|
|
64
|
+
return expr.type === 'CallExpression' && isTokenCallExpression(expr);
|
|
65
|
+
})) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
60
68
|
if (!propertyValues.some(function (str) {
|
|
61
69
|
return str.includes('token(');
|
|
62
70
|
})) {
|
|
@@ -74,21 +82,14 @@ var isPropertyValueExempted = function isPropertyValueExempted(propertyValues) {
|
|
|
74
82
|
};
|
|
75
83
|
|
|
76
84
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* 2. Property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
|
|
85
|
+
* Checks if the parsed property values are invalid (i.e. rule violation thrown) and autofix required. Cases are when
|
|
86
|
+
* property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
|
|
80
87
|
* The rule will return with error and provide a fix
|
|
81
88
|
* @param templateLiteral TemplateLiteral AST Node
|
|
82
89
|
* @param propertyValues property values parsed as list of strings
|
|
83
90
|
* @returns boolean
|
|
84
91
|
*/
|
|
85
|
-
var isPropertyValuesInvalidFix = function isPropertyValuesInvalidFix(
|
|
86
|
-
var expressions = templateLiteral.expressions;
|
|
87
|
-
if (!expressions.every(function (expr) {
|
|
88
|
-
return expr.type === 'CallExpression' && isTokenCallExpression(expr);
|
|
89
|
-
})) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
+
var isPropertyValuesInvalidFix = function isPropertyValuesInvalidFix(propertyValues) {
|
|
92
93
|
var _iterator = _createForOfIteratorHelper(propertyValues),
|
|
93
94
|
_step;
|
|
94
95
|
try {
|
|
@@ -182,11 +183,11 @@ var executeExpandSpacingRule = function executeExpandSpacingRule(context, node,
|
|
|
182
183
|
}
|
|
183
184
|
if (node.value.type === 'TemplateLiteral') {
|
|
184
185
|
var propertyValues = parseTemplateLiteral(node.value, context);
|
|
185
|
-
if (isPropertyValueExempted(propertyValues)) {
|
|
186
|
+
if (isPropertyValueExempted(node.value, propertyValues)) {
|
|
186
187
|
// Valid, so no error should be thrown
|
|
187
188
|
return;
|
|
188
189
|
}
|
|
189
|
-
if (isPropertyValuesInvalidFix(
|
|
190
|
+
if (isPropertyValuesInvalidFix(propertyValues)) {
|
|
190
191
|
// Invalid, so error should be thrown and fix provided
|
|
191
192
|
context.report({
|
|
192
193
|
node: node,
|
package/dist/es2019/index.js
CHANGED
|
@@ -65,7 +65,7 @@ const commonConfig = {
|
|
|
65
65
|
// Compiled: rules that are not included via `@compiled/recommended
|
|
66
66
|
'@atlaskit/platform/expand-border-shorthand': 'error',
|
|
67
67
|
'@atlaskit/platform/expand-background-shorthand': 'error',
|
|
68
|
-
'@atlaskit/platform/expand-spacing-shorthand': '
|
|
68
|
+
'@atlaskit/platform/expand-spacing-shorthand': 'error',
|
|
69
69
|
'@compiled/jsx-pragma': ['error', {
|
|
70
70
|
importSources: ['@atlaskit/css'],
|
|
71
71
|
onlyRunIfImportingCompiled: true,
|
|
@@ -37,15 +37,21 @@ const parseTemplateLiteral = (templateLiteral, context) => {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* Checks if the parsed property values are valid
|
|
41
|
-
* 1.
|
|
42
|
-
* 2.
|
|
43
|
-
* 3.
|
|
40
|
+
* Checks if the parsed property values are valid; values that we shouldn't handle with the fixer:
|
|
41
|
+
* 1. At least one expression in TemplateLiteral is not a token expression
|
|
42
|
+
* 2. Do not contain a token
|
|
43
|
+
* 3. Have length that are not in the range [1, 4] for different spacing directions
|
|
44
|
+
* - No more than 4 to exclude additional values such as `!important`
|
|
45
|
+
* 4. Includes `calc(...)`
|
|
44
46
|
* Then, the rule will return with no error
|
|
45
47
|
* @param propertyValues property values parsed as list of strings
|
|
46
48
|
* @returns boolean
|
|
47
49
|
*/
|
|
48
|
-
const isPropertyValueExempted = propertyValues => {
|
|
50
|
+
const isPropertyValueExempted = (templateLiteral, propertyValues) => {
|
|
51
|
+
const expressions = templateLiteral.expressions;
|
|
52
|
+
if (!expressions.every(expr => expr.type === 'CallExpression' && isTokenCallExpression(expr))) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
49
55
|
if (!propertyValues.some(str => str.includes('token('))) {
|
|
50
56
|
return true;
|
|
51
57
|
}
|
|
@@ -59,19 +65,14 @@ const isPropertyValueExempted = propertyValues => {
|
|
|
59
65
|
};
|
|
60
66
|
|
|
61
67
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* 2. Property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
|
|
68
|
+
* Checks if the parsed property values are invalid (i.e. rule violation thrown) and autofix required. Cases are when
|
|
69
|
+
* property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
|
|
65
70
|
* The rule will return with error and provide a fix
|
|
66
71
|
* @param templateLiteral TemplateLiteral AST Node
|
|
67
72
|
* @param propertyValues property values parsed as list of strings
|
|
68
73
|
* @returns boolean
|
|
69
74
|
*/
|
|
70
|
-
const isPropertyValuesInvalidFix =
|
|
71
|
-
const expressions = templateLiteral.expressions;
|
|
72
|
-
if (!expressions.every(expr => expr.type === 'CallExpression' && isTokenCallExpression(expr))) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
+
const isPropertyValuesInvalidFix = propertyValues => {
|
|
75
76
|
for (const propValue of propertyValues) {
|
|
76
77
|
if (propValue === '0') {
|
|
77
78
|
continue;
|
|
@@ -139,11 +140,11 @@ const executeExpandSpacingRule = (context, node, propertyShorthand) => {
|
|
|
139
140
|
}
|
|
140
141
|
if (node.value.type === 'TemplateLiteral') {
|
|
141
142
|
const propertyValues = parseTemplateLiteral(node.value, context);
|
|
142
|
-
if (isPropertyValueExempted(propertyValues)) {
|
|
143
|
+
if (isPropertyValueExempted(node.value, propertyValues)) {
|
|
143
144
|
// Valid, so no error should be thrown
|
|
144
145
|
return;
|
|
145
146
|
}
|
|
146
|
-
if (isPropertyValuesInvalidFix(
|
|
147
|
+
if (isPropertyValuesInvalidFix(propertyValues)) {
|
|
147
148
|
// Invalid, so error should be thrown and fix provided
|
|
148
149
|
context.report({
|
|
149
150
|
node,
|
package/dist/esm/index.js
CHANGED
|
@@ -68,7 +68,7 @@ var commonConfig = {
|
|
|
68
68
|
// Compiled: rules that are not included via `@compiled/recommended
|
|
69
69
|
'@atlaskit/platform/expand-border-shorthand': 'error',
|
|
70
70
|
'@atlaskit/platform/expand-background-shorthand': 'error',
|
|
71
|
-
'@atlaskit/platform/expand-spacing-shorthand': '
|
|
71
|
+
'@atlaskit/platform/expand-spacing-shorthand': 'error',
|
|
72
72
|
'@compiled/jsx-pragma': ['error', {
|
|
73
73
|
importSources: ['@atlaskit/css'],
|
|
74
74
|
onlyRunIfImportingCompiled: true,
|
|
@@ -41,15 +41,23 @@ var parseTemplateLiteral = function parseTemplateLiteral(templateLiteral, contex
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Checks if the parsed property values are valid
|
|
45
|
-
* 1.
|
|
46
|
-
* 2.
|
|
47
|
-
* 3.
|
|
44
|
+
* Checks if the parsed property values are valid; values that we shouldn't handle with the fixer:
|
|
45
|
+
* 1. At least one expression in TemplateLiteral is not a token expression
|
|
46
|
+
* 2. Do not contain a token
|
|
47
|
+
* 3. Have length that are not in the range [1, 4] for different spacing directions
|
|
48
|
+
* - No more than 4 to exclude additional values such as `!important`
|
|
49
|
+
* 4. Includes `calc(...)`
|
|
48
50
|
* Then, the rule will return with no error
|
|
49
51
|
* @param propertyValues property values parsed as list of strings
|
|
50
52
|
* @returns boolean
|
|
51
53
|
*/
|
|
52
|
-
var isPropertyValueExempted = function isPropertyValueExempted(propertyValues) {
|
|
54
|
+
var isPropertyValueExempted = function isPropertyValueExempted(templateLiteral, propertyValues) {
|
|
55
|
+
var expressions = templateLiteral.expressions;
|
|
56
|
+
if (!expressions.every(function (expr) {
|
|
57
|
+
return expr.type === 'CallExpression' && isTokenCallExpression(expr);
|
|
58
|
+
})) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
53
61
|
if (!propertyValues.some(function (str) {
|
|
54
62
|
return str.includes('token(');
|
|
55
63
|
})) {
|
|
@@ -67,21 +75,14 @@ var isPropertyValueExempted = function isPropertyValueExempted(propertyValues) {
|
|
|
67
75
|
};
|
|
68
76
|
|
|
69
77
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* 2. Property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
|
|
78
|
+
* Checks if the parsed property values are invalid (i.e. rule violation thrown) and autofix required. Cases are when
|
|
79
|
+
* property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
|
|
73
80
|
* The rule will return with error and provide a fix
|
|
74
81
|
* @param templateLiteral TemplateLiteral AST Node
|
|
75
82
|
* @param propertyValues property values parsed as list of strings
|
|
76
83
|
* @returns boolean
|
|
77
84
|
*/
|
|
78
|
-
var isPropertyValuesInvalidFix = function isPropertyValuesInvalidFix(
|
|
79
|
-
var expressions = templateLiteral.expressions;
|
|
80
|
-
if (!expressions.every(function (expr) {
|
|
81
|
-
return expr.type === 'CallExpression' && isTokenCallExpression(expr);
|
|
82
|
-
})) {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
+
var isPropertyValuesInvalidFix = function isPropertyValuesInvalidFix(propertyValues) {
|
|
85
86
|
var _iterator = _createForOfIteratorHelper(propertyValues),
|
|
86
87
|
_step;
|
|
87
88
|
try {
|
|
@@ -175,11 +176,11 @@ var executeExpandSpacingRule = function executeExpandSpacingRule(context, node,
|
|
|
175
176
|
}
|
|
176
177
|
if (node.value.type === 'TemplateLiteral') {
|
|
177
178
|
var propertyValues = parseTemplateLiteral(node.value, context);
|
|
178
|
-
if (isPropertyValueExempted(propertyValues)) {
|
|
179
|
+
if (isPropertyValueExempted(node.value, propertyValues)) {
|
|
179
180
|
// Valid, so no error should be thrown
|
|
180
181
|
return;
|
|
181
182
|
}
|
|
182
|
-
if (isPropertyValuesInvalidFix(
|
|
183
|
+
if (isPropertyValuesInvalidFix(propertyValues)) {
|
|
183
184
|
// Invalid, so error should be thrown and fix provided
|
|
184
185
|
context.report({
|
|
185
186
|
node: node,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -82,7 +82,7 @@ declare const plugin: {
|
|
|
82
82
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
83
83
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
84
84
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
85
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
85
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
86
86
|
'@compiled/jsx-pragma': ["error", {
|
|
87
87
|
importSources: string[];
|
|
88
88
|
onlyRunIfImportingCompiled: boolean;
|
|
@@ -114,7 +114,7 @@ declare const plugin: {
|
|
|
114
114
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
115
115
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
116
116
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
117
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
117
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
118
118
|
'@compiled/jsx-pragma': ["error", {
|
|
119
119
|
importSources: string[];
|
|
120
120
|
onlyRunIfImportingCompiled: boolean;
|
|
@@ -133,7 +133,7 @@ declare const plugin: {
|
|
|
133
133
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
134
134
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
135
135
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
136
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
136
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
137
137
|
'@compiled/jsx-pragma': ["error", {
|
|
138
138
|
importSources: string[];
|
|
139
139
|
onlyRunIfImportingCompiled: boolean;
|
|
@@ -155,7 +155,7 @@ declare const plugin: {
|
|
|
155
155
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
156
156
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
157
157
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
158
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
158
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
159
159
|
'@compiled/jsx-pragma': ["error", {
|
|
160
160
|
importSources: string[];
|
|
161
161
|
onlyRunIfImportingCompiled: boolean;
|
|
@@ -191,7 +191,7 @@ declare const configs: {
|
|
|
191
191
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
192
192
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
193
193
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
194
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
194
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
195
195
|
'@compiled/jsx-pragma': ["error", {
|
|
196
196
|
importSources: string[];
|
|
197
197
|
onlyRunIfImportingCompiled: boolean;
|
|
@@ -223,7 +223,7 @@ declare const configs: {
|
|
|
223
223
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
224
224
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
225
225
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
226
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
226
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
227
227
|
'@compiled/jsx-pragma': ["error", {
|
|
228
228
|
importSources: string[];
|
|
229
229
|
onlyRunIfImportingCompiled: boolean;
|
|
@@ -242,7 +242,7 @@ declare const configs: {
|
|
|
242
242
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
243
243
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
244
244
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
245
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
245
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
246
246
|
'@compiled/jsx-pragma': ["error", {
|
|
247
247
|
importSources: string[];
|
|
248
248
|
onlyRunIfImportingCompiled: boolean;
|
|
@@ -264,7 +264,7 @@ declare const configs: {
|
|
|
264
264
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
265
265
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
266
266
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
267
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
267
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
268
268
|
'@compiled/jsx-pragma': ["error", {
|
|
269
269
|
importSources: string[];
|
|
270
270
|
onlyRunIfImportingCompiled: boolean;
|
|
@@ -85,7 +85,7 @@ declare const plugin: {
|
|
|
85
85
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
86
86
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
87
87
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
88
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
88
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
89
89
|
'@compiled/jsx-pragma': [
|
|
90
90
|
"error",
|
|
91
91
|
{
|
|
@@ -123,7 +123,7 @@ declare const plugin: {
|
|
|
123
123
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
124
124
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
125
125
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
126
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
126
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
127
127
|
'@compiled/jsx-pragma': [
|
|
128
128
|
"error",
|
|
129
129
|
{
|
|
@@ -145,7 +145,7 @@ declare const plugin: {
|
|
|
145
145
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
146
146
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
147
147
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
148
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
148
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
149
149
|
'@compiled/jsx-pragma': [
|
|
150
150
|
"error",
|
|
151
151
|
{
|
|
@@ -170,7 +170,7 @@ declare const plugin: {
|
|
|
170
170
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
171
171
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
172
172
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
173
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
173
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
174
174
|
'@compiled/jsx-pragma': [
|
|
175
175
|
"error",
|
|
176
176
|
{
|
|
@@ -212,7 +212,7 @@ declare const configs: {
|
|
|
212
212
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
213
213
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
214
214
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
215
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
215
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
216
216
|
'@compiled/jsx-pragma': [
|
|
217
217
|
"error",
|
|
218
218
|
{
|
|
@@ -250,7 +250,7 @@ declare const configs: {
|
|
|
250
250
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
251
251
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
252
252
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
253
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
253
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
254
254
|
'@compiled/jsx-pragma': [
|
|
255
255
|
"error",
|
|
256
256
|
{
|
|
@@ -272,7 +272,7 @@ declare const configs: {
|
|
|
272
272
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
273
273
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
274
274
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
275
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
275
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
276
276
|
'@compiled/jsx-pragma': [
|
|
277
277
|
"error",
|
|
278
278
|
{
|
|
@@ -297,7 +297,7 @@ declare const configs: {
|
|
|
297
297
|
'@atlaskit/platform/no-module-level-eval-nav4': "error";
|
|
298
298
|
'@atlaskit/platform/expand-border-shorthand': "error";
|
|
299
299
|
'@atlaskit/platform/expand-background-shorthand': "error";
|
|
300
|
-
'@atlaskit/platform/expand-spacing-shorthand': "
|
|
300
|
+
'@atlaskit/platform/expand-spacing-shorthand': "error";
|
|
301
301
|
'@compiled/jsx-pragma': [
|
|
302
302
|
"error",
|
|
303
303
|
{
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/eslint-plugin-platform",
|
|
3
3
|
"description": "The essential plugin for use with Atlassian frontend platform tools",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.3.0",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"atlassian": {
|
|
7
7
|
"team": "Build Infra",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
".": "./src/index.tsx"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/eslint-utils": "^1.
|
|
34
|
+
"@atlaskit/eslint-utils": "^1.9.0",
|
|
35
35
|
"@babel/runtime": "^7.0.0",
|
|
36
36
|
"@compiled/eslint-plugin": "^0.18.2",
|
|
37
37
|
"@manypkg/find-root": "^1.1.0",
|
package/src/index.tsx
CHANGED
|
@@ -73,7 +73,7 @@ const commonConfig = {
|
|
|
73
73
|
// Compiled: rules that are not included via `@compiled/recommended
|
|
74
74
|
'@atlaskit/platform/expand-border-shorthand': 'error',
|
|
75
75
|
'@atlaskit/platform/expand-background-shorthand': 'error',
|
|
76
|
-
'@atlaskit/platform/expand-spacing-shorthand': '
|
|
76
|
+
'@atlaskit/platform/expand-spacing-shorthand': 'error',
|
|
77
77
|
'@compiled/jsx-pragma': [
|
|
78
78
|
'error',
|
|
79
79
|
{
|
|
@@ -79,6 +79,28 @@ const validTestCases = (property: string) => {
|
|
|
79
79
|
});
|
|
80
80
|
`,
|
|
81
81
|
},
|
|
82
|
+
// Template literal containing expressions that is not token should only throw error with no autofix
|
|
83
|
+
{
|
|
84
|
+
name: `${property}: property value template string where it contains an expression that is not a token`,
|
|
85
|
+
code: outdent`
|
|
86
|
+
import {css} from '@compiled/react';
|
|
87
|
+
const styles = css({
|
|
88
|
+
${property}: \`\${token('space.100', '8px')} \${gridSize * 2}px\`,
|
|
89
|
+
});
|
|
90
|
+
const styles2 = css({
|
|
91
|
+
padding: \`\${DROPDOWN_HEADER_VERTICAL_PADDING} \${token('space.075','6px')}
|
|
92
|
+
\${DROPDOWN_HEADER_VERTICAL_PADDING} \${token('space.200', '16px')}\`,
|
|
93
|
+
});
|
|
94
|
+
const styles3 = css({
|
|
95
|
+
${property}: \`\${token('space.050', '4px')} \${token('space.150', '12px')} \${token('space.150', '12px')}
|
|
96
|
+
\${({ isSummaryView }: EditFormContentWrapperProps) =>
|
|
97
|
+
isSummaryView ? token('space.0', '0') : token('space.150', '12px')}\`,
|
|
98
|
+
});
|
|
99
|
+
const styles4 = css({
|
|
100
|
+
${property}: \`\${token('space.100', '8px')} -\${gridSize}px 0\`,
|
|
101
|
+
});
|
|
102
|
+
`,
|
|
103
|
+
},
|
|
82
104
|
];
|
|
83
105
|
};
|
|
84
106
|
|
|
@@ -252,26 +274,6 @@ const invalidTestCases = (property: string) => {
|
|
|
252
274
|
`,
|
|
253
275
|
errors: [{ messageId: 'expandSpacingShorthand' }],
|
|
254
276
|
},
|
|
255
|
-
// Template literal containing expressions that is not token should only throw error with no autofix
|
|
256
|
-
{
|
|
257
|
-
name: `${property}: property value template string where it contains an expression that is not a token`,
|
|
258
|
-
code: outdent`
|
|
259
|
-
import {css} from '@compiled/react';
|
|
260
|
-
const styles = css({
|
|
261
|
-
${property}: \`\${token('space.100', '8px')} \${gridSize * 2}px\`,
|
|
262
|
-
});
|
|
263
|
-
const styles2 = css({
|
|
264
|
-
padding: \`\${DROPDOWN_HEADER_VERTICAL_PADDING} \${token('space.075','6px')}
|
|
265
|
-
\${DROPDOWN_HEADER_VERTICAL_PADDING} \${token('space.200', '16px')}\`,
|
|
266
|
-
});
|
|
267
|
-
const styles3 = css({
|
|
268
|
-
${property}: \`\${token('space.050', '4px')} \${token('space.150', '12px')} \${token('space.150', '12px')}
|
|
269
|
-
\${({ isSummaryView }: EditFormContentWrapperProps) =>
|
|
270
|
-
isSummaryView ? token('space.0', '0') : token('space.150', '12px')}\`,
|
|
271
|
-
});
|
|
272
|
-
`,
|
|
273
|
-
errors: Array.from(Array(3), () => ({ messageId: 'expandSpacingShorthand' })),
|
|
274
|
-
},
|
|
275
277
|
// Strings that are not valid property values should not be autofixed (e.g. !important)
|
|
276
278
|
{
|
|
277
279
|
name: `${property}: Don't autofix if not able to handle all the string values, e.g !important`,
|
|
@@ -50,15 +50,21 @@ const parseTemplateLiteral = (templateLiteral: TemplateLiteral, context: Rule.Ru
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Checks if the parsed property values are valid
|
|
54
|
-
* 1.
|
|
55
|
-
* 2.
|
|
56
|
-
* 3.
|
|
53
|
+
* Checks if the parsed property values are valid; values that we shouldn't handle with the fixer:
|
|
54
|
+
* 1. At least one expression in TemplateLiteral is not a token expression
|
|
55
|
+
* 2. Do not contain a token
|
|
56
|
+
* 3. Have length that are not in the range [1, 4] for different spacing directions
|
|
57
|
+
* - No more than 4 to exclude additional values such as `!important`
|
|
58
|
+
* 4. Includes `calc(...)`
|
|
57
59
|
* Then, the rule will return with no error
|
|
58
60
|
* @param propertyValues property values parsed as list of strings
|
|
59
61
|
* @returns boolean
|
|
60
62
|
*/
|
|
61
|
-
const isPropertyValueExempted = (propertyValues: string[]) => {
|
|
63
|
+
const isPropertyValueExempted = (templateLiteral: TemplateLiteral, propertyValues: string[]) => {
|
|
64
|
+
const expressions = templateLiteral.expressions;
|
|
65
|
+
if (!expressions.every((expr) => expr.type === 'CallExpression' && isTokenCallExpression(expr))) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
62
68
|
if (!propertyValues.some((str) => str.includes('token('))) {
|
|
63
69
|
return true;
|
|
64
70
|
}
|
|
@@ -72,29 +78,31 @@ const isPropertyValueExempted = (propertyValues: string[]) => {
|
|
|
72
78
|
};
|
|
73
79
|
|
|
74
80
|
/**
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* 2. Property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
|
|
81
|
+
* Checks if the parsed property values are invalid (i.e. rule violation thrown) and autofix required. Cases are when
|
|
82
|
+
* property values must have a format which includes -> e.g. 2, '2(rem|em|px)', auto, initial, inherit, token(...)
|
|
78
83
|
* The rule will return with error and provide a fix
|
|
79
84
|
* @param templateLiteral TemplateLiteral AST Node
|
|
80
85
|
* @param propertyValues property values parsed as list of strings
|
|
81
86
|
* @returns boolean
|
|
82
87
|
*/
|
|
83
|
-
const isPropertyValuesInvalidFix = (
|
|
84
|
-
const expressions = templateLiteral.expressions;
|
|
85
|
-
if (!expressions.every((expr) => expr.type === 'CallExpression' && isTokenCallExpression(expr))) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
|
|
88
|
+
const isPropertyValuesInvalidFix = (propertyValues: string[]) => {
|
|
89
89
|
for (const propValue of propertyValues) {
|
|
90
|
-
if (propValue === '0') {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
90
|
+
if (propValue === '0') {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
if (['auto', 'initial', 'inherit'].includes(propValue.slice(1, -1))) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (/^token\(.*\)$/.test(propValue)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (/^['"]\d+(\.\d+)?((rem)|(em)|(px))['"]$/.test(propValue)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
94
102
|
return false;
|
|
95
103
|
}
|
|
96
104
|
return true;
|
|
97
|
-
}
|
|
105
|
+
};
|
|
98
106
|
|
|
99
107
|
// To fix spacing shorthands, given a list of spacing property values, expands the spacing property and adds autofix fixes
|
|
100
108
|
const expandSpacingProperties = ({
|
|
@@ -157,11 +165,11 @@ const executeExpandSpacingRule = (
|
|
|
157
165
|
}
|
|
158
166
|
if (node.value.type === 'TemplateLiteral') {
|
|
159
167
|
const propertyValues = parseTemplateLiteral(node.value, context);
|
|
160
|
-
if (isPropertyValueExempted(propertyValues)) {
|
|
168
|
+
if (isPropertyValueExempted(node.value, propertyValues)) {
|
|
161
169
|
// Valid, so no error should be thrown
|
|
162
170
|
return;
|
|
163
171
|
}
|
|
164
|
-
if (isPropertyValuesInvalidFix(
|
|
172
|
+
if (isPropertyValuesInvalidFix(propertyValues)) {
|
|
165
173
|
// Invalid, so error should be thrown and fix provided
|
|
166
174
|
context.report({
|
|
167
175
|
node,
|
|
@@ -170,7 +178,13 @@ const executeExpandSpacingRule = (
|
|
|
170
178
|
property: propertyShorthand,
|
|
171
179
|
},
|
|
172
180
|
fix(fixer) {
|
|
173
|
-
return expandSpacingProperties({
|
|
181
|
+
return expandSpacingProperties({
|
|
182
|
+
context,
|
|
183
|
+
node,
|
|
184
|
+
propertyValues,
|
|
185
|
+
fixer,
|
|
186
|
+
propertyShorthand,
|
|
187
|
+
});
|
|
174
188
|
},
|
|
175
189
|
});
|
|
176
190
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
### Notes
|
|
2
2
|
|
|
3
3
|
- feature-gating/\* rules are copied from
|
|
4
|
-
[eslint-plugin-jira/rules/ff](https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/jira/
|
|
4
|
+
[eslint-plugin-jira/rules/ff](https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/browse/jira/dev-tooling/packages/eslint-plugin-jira/rules/ff)
|
|
5
5
|
with small variations as mentioned in this
|
|
6
6
|
[PR](https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/115546/overview)
|
|
7
7
|
- these rules could be a WIP since they are still targeting JFE libraries- see
|