@atlaskit/eslint-plugin-platform 0.14.0 → 1.0.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/eslint-plugin-platform
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#168864](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/168864)
8
+ [`49e4510bd86d3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/49e4510bd86d3) -
9
+ update eslint rule 'expand-border-properties' from warn to error
10
+
3
11
  ## 0.14.0
4
12
 
5
13
  ### Minor Changes
package/dist/cjs/index.js CHANGED
@@ -68,7 +68,7 @@ var commonConfig = {
68
68
  '@atlaskit/platform/ensure-atlassian-team': 'error',
69
69
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
70
70
  // Compiled: rules that are not included via `@compiled/recommended
71
- '@atlaskit/platform/expand-border-shorthand': 'warn',
71
+ '@atlaskit/platform/expand-border-shorthand': 'error',
72
72
  '@atlaskit/platform/expand-background-shorthand': 'warn',
73
73
  '@compiled/jsx-pragma': ['error', {
74
74
  importSources: ['@atlaskit/css'],
@@ -19,6 +19,9 @@ var separateBorderProperties = function separateBorderProperties(borderString, p
19
19
  if (EXCLUDED_VALUES.includes(borderString)) {
20
20
  return;
21
21
  }
22
+ if (borderString.includes('var(--')) {
23
+ return;
24
+ }
22
25
  context.report({
23
26
  node: property,
24
27
  messageId: 'expandBorderShorthand'
@@ -39,7 +42,7 @@ var isCompiledAPI = function isCompiledAPI(importDeclaration, callExpression) {
39
42
  return;
40
43
  }
41
44
  return importDeclaration.specifiers.some(function (specifier) {
42
- return specifier.type === 'ImportSpecifier' && specifier.imported.name === functionName;
45
+ return specifier.type === 'ImportSpecifier' && specifier.local.name === functionName;
43
46
  });
44
47
  };
45
48
  var expandBorderShorthand = exports.expandBorderShorthand = {
@@ -66,21 +69,11 @@ var expandBorderShorthand = exports.expandBorderShorthand = {
66
69
  if (importDeclaration) {
67
70
  if (isCompiledAPI(importDeclaration, callExpression)) {
68
71
  if (node.value.type === 'Literal' && node.value.value !== null) {
69
- if (typeof node.value.value === 'string') {
70
- var borderString = node.value.value;
72
+ var borderString = typeof node.value.value === 'string' ? node.value.value : node.value.raw;
73
+ if (borderString) {
71
74
  separateBorderProperties(borderString, node, context);
72
- } else if (node.value.raw) {
73
- var _borderString = node.value.raw;
74
- separateBorderProperties(_borderString, node, context);
75
75
  }
76
76
  } else if (node.value.type === 'TemplateLiteral') {
77
- if (node.value.quasis.length > 1 || node.value.expressions.length > 0) {
78
- context.report({
79
- node: node,
80
- messageId: 'expandBorderShorthand'
81
- });
82
- return;
83
- }
84
77
  if (node.value.quasis.length === 1 && node.value.quasis[0].value.cooked) {
85
78
  var borderQuasis = node.value.quasis[0].value.cooked;
86
79
  separateBorderProperties(borderQuasis, node, context);
@@ -60,7 +60,7 @@ const commonConfig = {
60
60
  '@atlaskit/platform/ensure-atlassian-team': 'error',
61
61
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
62
62
  // Compiled: rules that are not included via `@compiled/recommended
63
- '@atlaskit/platform/expand-border-shorthand': 'warn',
63
+ '@atlaskit/platform/expand-border-shorthand': 'error',
64
64
  '@atlaskit/platform/expand-background-shorthand': 'warn',
65
65
  '@compiled/jsx-pragma': ['error', {
66
66
  importSources: ['@atlaskit/css'],
@@ -13,6 +13,9 @@ const separateBorderProperties = (borderString, property, context) => {
13
13
  if (EXCLUDED_VALUES.includes(borderString)) {
14
14
  return;
15
15
  }
16
+ if (borderString.includes('var(--')) {
17
+ return;
18
+ }
16
19
  context.report({
17
20
  node: property,
18
21
  messageId: 'expandBorderShorthand'
@@ -32,7 +35,7 @@ const isCompiledAPI = (importDeclaration, callExpression) => {
32
35
  if (!functionName) {
33
36
  return;
34
37
  }
35
- return importDeclaration.specifiers.some(specifier => specifier.type === 'ImportSpecifier' && specifier.imported.name === functionName);
38
+ return importDeclaration.specifiers.some(specifier => specifier.type === 'ImportSpecifier' && specifier.local.name === functionName);
36
39
  };
37
40
  export const expandBorderShorthand = {
38
41
  meta: {
@@ -58,21 +61,11 @@ export const expandBorderShorthand = {
58
61
  if (importDeclaration) {
59
62
  if (isCompiledAPI(importDeclaration, callExpression)) {
60
63
  if (node.value.type === 'Literal' && node.value.value !== null) {
61
- if (typeof node.value.value === 'string') {
62
- const borderString = node.value.value;
63
- separateBorderProperties(borderString, node, context);
64
- } else if (node.value.raw) {
65
- const borderString = node.value.raw;
64
+ const borderString = typeof node.value.value === 'string' ? node.value.value : node.value.raw;
65
+ if (borderString) {
66
66
  separateBorderProperties(borderString, node, context);
67
67
  }
68
68
  } else if (node.value.type === 'TemplateLiteral') {
69
- if (node.value.quasis.length > 1 || node.value.expressions.length > 0) {
70
- context.report({
71
- node,
72
- messageId: 'expandBorderShorthand'
73
- });
74
- return;
75
- }
76
69
  if (node.value.quasis.length === 1 && node.value.quasis[0].value.cooked) {
77
70
  const borderQuasis = node.value.quasis[0].value.cooked;
78
71
  separateBorderProperties(borderQuasis, node, context);
package/dist/esm/index.js CHANGED
@@ -63,7 +63,7 @@ var commonConfig = {
63
63
  '@atlaskit/platform/ensure-atlassian-team': 'error',
64
64
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
65
65
  // Compiled: rules that are not included via `@compiled/recommended
66
- '@atlaskit/platform/expand-border-shorthand': 'warn',
66
+ '@atlaskit/platform/expand-border-shorthand': 'error',
67
67
  '@atlaskit/platform/expand-background-shorthand': 'warn',
68
68
  '@compiled/jsx-pragma': ['error', {
69
69
  importSources: ['@atlaskit/css'],
@@ -13,6 +13,9 @@ var separateBorderProperties = function separateBorderProperties(borderString, p
13
13
  if (EXCLUDED_VALUES.includes(borderString)) {
14
14
  return;
15
15
  }
16
+ if (borderString.includes('var(--')) {
17
+ return;
18
+ }
16
19
  context.report({
17
20
  node: property,
18
21
  messageId: 'expandBorderShorthand'
@@ -33,7 +36,7 @@ var isCompiledAPI = function isCompiledAPI(importDeclaration, callExpression) {
33
36
  return;
34
37
  }
35
38
  return importDeclaration.specifiers.some(function (specifier) {
36
- return specifier.type === 'ImportSpecifier' && specifier.imported.name === functionName;
39
+ return specifier.type === 'ImportSpecifier' && specifier.local.name === functionName;
37
40
  });
38
41
  };
39
42
  export var expandBorderShorthand = {
@@ -60,21 +63,11 @@ export var expandBorderShorthand = {
60
63
  if (importDeclaration) {
61
64
  if (isCompiledAPI(importDeclaration, callExpression)) {
62
65
  if (node.value.type === 'Literal' && node.value.value !== null) {
63
- if (typeof node.value.value === 'string') {
64
- var borderString = node.value.value;
66
+ var borderString = typeof node.value.value === 'string' ? node.value.value : node.value.raw;
67
+ if (borderString) {
65
68
  separateBorderProperties(borderString, node, context);
66
- } else if (node.value.raw) {
67
- var _borderString = node.value.raw;
68
- separateBorderProperties(_borderString, node, context);
69
69
  }
70
70
  } else if (node.value.type === 'TemplateLiteral') {
71
- if (node.value.quasis.length > 1 || node.value.expressions.length > 0) {
72
- context.report({
73
- node: node,
74
- messageId: 'expandBorderShorthand'
75
- });
76
- return;
77
- }
78
71
  if (node.value.quasis.length === 1 && node.value.quasis[0].value.cooked) {
79
72
  var borderQuasis = node.value.quasis[0].value.cooked;
80
73
  separateBorderProperties(borderQuasis, node, context);
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": "0.14.0",
4
+ "version": "1.0.0",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "atlassian": {
7
7
  "team": "Build Infra",
package/src/index.tsx CHANGED
@@ -62,7 +62,7 @@ const commonConfig = {
62
62
  '@atlaskit/platform/ensure-atlassian-team': 'error',
63
63
  '@atlaskit/platform/no-module-level-eval-nav4': 'error',
64
64
  // Compiled: rules that are not included via `@compiled/recommended
65
- '@atlaskit/platform/expand-border-shorthand': 'warn',
65
+ '@atlaskit/platform/expand-border-shorthand': 'error',
66
66
  '@atlaskit/platform/expand-background-shorthand': 'warn',
67
67
  '@compiled/jsx-pragma': [
68
68
  'error',
@@ -1,6 +1,6 @@
1
1
  # `shorthand-property-sorting`
2
2
 
3
- This ESLint rule enforces the expansion of CSS `border` shorthand property, into it's longhand
3
+ This ESLint rule enforces the expansion of CSS `border` shorthand property, into its longhand
4
4
  equivalents `borderStyle`, `borderWidth`, `borderColor`, for packages that originates from
5
5
  `@compiled/react`, and `@atlaskit/css`.
6
6
 
@@ -3,15 +3,13 @@ import { outdent } from 'outdent';
3
3
  import { tester } from '../../../../__tests__/utils/_tester';
4
4
  import { expandBorderShorthand } from '../index';
5
5
 
6
- const valid_packages_calls_and_imports = [
6
+ const included_packages_calls_and_imports = [
7
7
  ['css', 'css', '@atlaskit/css'],
8
8
  ['css', 'css', '@compiled/react'],
9
9
  ['styled', 'styled.div', '@compiled/react'],
10
- ['cssMap', 'cssMap', '@atlaskit/css'],
11
- ['cssMap', 'cssMap', '@compiled/react'],
12
10
  ];
13
11
 
14
- const invalid_packages_calls_and_imports = [
12
+ const exempt_packages_calls_and_imports = [
15
13
  ['css', '@atlaskit/primitives'],
16
14
  ['css', '@emotion'],
17
15
  ['css', 'styled-components'],
@@ -19,8 +17,8 @@ const invalid_packages_calls_and_imports = [
19
17
 
20
18
  tester.run('expand-border-shorthand', expandBorderShorthand, {
21
19
  valid: [
22
- ...invalid_packages_calls_and_imports.map(([pkg, imp]) => ({
23
- name: `incorrect packages (${pkg}, ${imp})`,
20
+ ...exempt_packages_calls_and_imports.map(([pkg, imp]) => ({
21
+ name: `handle only Compiled APIs (${pkg}, ${imp})`,
24
22
  code: outdent`
25
23
  import {${pkg}} from '${imp}';
26
24
 
@@ -30,13 +28,18 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
30
28
  `,
31
29
  })),
32
30
  {
33
- name: 'references correct package',
31
+ name: 'CallExpression matches with imported API',
34
32
  code: outdent`
35
- import {css} from '@compiled/react';
33
+ import { styled } from 'styled-components';
34
+ import { styled as styled2, css as compiledCSS, jsx } from '@compiled/react';
36
35
 
37
36
  const styles = xcss({
38
37
  border: '1px solid red',
39
38
  });
39
+
40
+ const styles2 = styled.div({
41
+ border: '1px solid red',
42
+ });
40
43
  `,
41
44
  },
42
45
  {
@@ -71,6 +74,17 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
71
74
  const styles9 = css({
72
75
  border: 0,
73
76
  });
77
+ const styles10 = css({
78
+ border: 'var(--icon-border)',
79
+ });
80
+ const styles11 = css({
81
+ border: \`\${(props: { border?: boolean }) =>
82
+ props.border ? \`1px solid \${token('color.border.disabled', colors.N30)}\` : 'none'}\`,
83
+ });
84
+ const styles12 = css({
85
+ border: (props: { border?: boolean }) =>
86
+ props.border ? token('color.border.disabled', colors.N30) : 'none',
87
+ });
74
88
  `,
75
89
  },
76
90
  {
@@ -91,9 +105,20 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
91
105
  });
92
106
  `,
93
107
  },
108
+ {
109
+ name: 'cssMap case where border is assigned an ObjectExpression',
110
+ code: outdent`
111
+ import { cssMap } from '@compiled/react';
112
+
113
+ const borderStyleMap = cssMap({
114
+ none: { borderStyle: 'none' },
115
+ border: { borderStyle: 'solid' },
116
+ });
117
+ `,
118
+ },
94
119
  ],
95
120
  invalid: [
96
- ...valid_packages_calls_and_imports.map(([pkg, call, imp]) => ({
121
+ ...included_packages_calls_and_imports.map(([pkg, call, imp]) => ({
97
122
  name: `simple case (${call}, ${imp})`,
98
123
  code: outdent`
99
124
  import {${pkg}} from '${imp}';
@@ -147,14 +172,6 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
147
172
  border: \`1px solid red\`,
148
173
  })
149
174
 
150
- const styles2 = css({
151
- border: \`1px solid \${token('red')}\`,
152
- })
153
-
154
- const styles3 = css({
155
- border: \`1px \${solid} red\`,
156
- })
157
-
158
175
  const styles4 = css({
159
176
  border: \`1px red\`,
160
177
  })
@@ -162,12 +179,8 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
162
179
  const styles5 = css({
163
180
  border: \`1px\`,
164
181
  })
165
-
166
- const styles6 = css({
167
- border: \` \${token('red')}\`,
168
- })
169
182
  `,
170
- errors: Array.from(Array(6), () => ({ messageId: 'expandBorderShorthand' })),
183
+ errors: Array.from(Array(3), () => ({ messageId: 'expandBorderShorthand' })),
171
184
  },
172
185
  {
173
186
  name: 'tokens',
@@ -182,5 +195,17 @@ tester.run('expand-border-shorthand', expandBorderShorthand, {
182
195
  `,
183
196
  errors: Array.from(Array(2), () => ({ messageId: 'expandBorderShorthand' })),
184
197
  },
198
+ {
199
+ name: 'cssMap case where border is assigned an a Literal',
200
+ code: outdent`
201
+ import { cssMap } from '@compiled/react';
202
+
203
+ const borderStyleMap = cssMap({
204
+ none: { border: 'none' },
205
+ solid: { border: '1px solid blue' },
206
+ });
207
+ `,
208
+ errors: [{ messageId: 'expandBorderShorthand' }],
209
+ },
185
210
  ],
186
211
  });
@@ -22,6 +22,9 @@ const separateBorderProperties = (
22
22
  if (EXCLUDED_VALUES.includes(borderString)) {
23
23
  return;
24
24
  }
25
+ if (borderString.includes('var(--')) {
26
+ return;
27
+ }
25
28
 
26
29
  context.report({
27
30
  node: property,
@@ -44,7 +47,7 @@ const isCompiledAPI = (importDeclaration: ImportDeclaration, callExpression: Cal
44
47
  }
45
48
 
46
49
  return importDeclaration.specifiers.some(
47
- (specifier) => specifier.type === 'ImportSpecifier' && specifier.imported.name === functionName,
50
+ (specifier) => specifier.type === 'ImportSpecifier' && specifier.local.name === functionName,
48
51
  );
49
52
  };
50
53
 
@@ -74,21 +77,12 @@ export const expandBorderShorthand: Rule.RuleModule = {
74
77
  if (importDeclaration) {
75
78
  if (isCompiledAPI(importDeclaration, callExpression)) {
76
79
  if (node.value.type === 'Literal' && node.value.value !== null) {
77
- if (typeof node.value.value === 'string') {
78
- const borderString = node.value.value;
79
- separateBorderProperties(borderString, node, context);
80
- } else if (node.value.raw) {
81
- const borderString = node.value.raw;
80
+ const borderString =
81
+ typeof node.value.value === 'string' ? node.value.value : node.value.raw;
82
+ if (borderString) {
82
83
  separateBorderProperties(borderString, node, context);
83
84
  }
84
85
  } else if (node.value.type === 'TemplateLiteral') {
85
- if (node.value.quasis.length > 1 || node.value.expressions.length > 0) {
86
- context.report({
87
- node,
88
- messageId: 'expandBorderShorthand',
89
- });
90
- return;
91
- }
92
86
  if (node.value.quasis.length === 1 && node.value.quasis[0].value.cooked) {
93
87
  const borderQuasis: string = node.value.quasis[0].value.cooked;
94
88
  separateBorderProperties(borderQuasis, node, context);