@backstage/eslint-plugin 0.1.7 → 0.1.8

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,11 @@
1
1
  # @backstage/eslint-plugin
2
2
 
3
+ ## 0.1.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 65ec043: add some `pickers` fixes
8
+
3
9
  ## 0.1.7
4
10
 
5
11
  ### Patch Changes
@@ -41,3 +41,50 @@ import {
41
41
  import Typography from '@material-ui/core/Typography';
42
42
  import Box from '@material-ui/core/Box';
43
43
  ```
44
+
45
+ ## --fix known issues
46
+
47
+ This rule provides automatic fixes for the imports, but it has some known issues:
48
+
49
+ ### Non Props types import
50
+
51
+ The fix will handle correctly 3 groups of imports:
52
+
53
+ - Any import from related to styles (i.e `makeStyles`, `styled`, `WithStyles`) will be auto fixed to the `@material-ui/core/styles` import.
54
+ - Any import with `Props` suffix will be auto fixed to actual component for example `DialogProps` will be imported from `@material-ui/core/Dialog`.
55
+ - Any other import will be considered as a component import and will be auto fixed to the actual component import.
56
+
57
+ This means that some types of imports without `Props` suffix will be wrongly auto fixed to the component import, for example this fix will be wrong:
58
+
59
+ ```diff
60
+ - import { Alert, Color } from '@material-ui/lab';
61
+ + import Alert from '@material-ui/lab/Alert';
62
+ + import Color from '@material-ui/lab/Color'; // this import is wrong
63
+ ```
64
+
65
+ The correct import should look like this:
66
+
67
+ ```diff
68
+ - import { Alert, Color } from '@material-ui/lab';
69
+ + import Alert, {Color} from '@material-ui/lab/Alert';
70
+ ```
71
+
72
+ Because `Color` is a type coming from the Alert component.
73
+
74
+ ### No default export available
75
+
76
+ Some components do not have a default export, for example `@material-ui/pickers/DateTimePicker` does not have a default export, so the fix will not work for these cases.
77
+
78
+ The fix will be wrong for this import:
79
+
80
+ ```diff
81
+ - import { DateTimePicker } from '@material-ui/pickers';
82
+ + import DateTimePicker from '@material-ui/pickers/DateTimePicker'; // this default import does not exist
83
+ ```
84
+
85
+ The correct import should look like this:
86
+
87
+ ```diff
88
+ - import { DateTimePicker } from '@material-ui/pickers';
89
+ + import { DateTimePicker } from '@material-ui/pickers/DateTimePicker'; // this is the correct import
90
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/eslint-plugin",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Backstage ESLint plugin",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -22,7 +22,7 @@
22
22
  "minimatch": "^9.0.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@backstage/cli": "^0.26.3",
25
+ "@backstage/cli": "^0.26.5",
26
26
  "@types/estree": "^1.0.5",
27
27
  "eslint": "^8.33.0"
28
28
  }
@@ -27,7 +27,23 @@
27
27
  */
28
28
 
29
29
  const KNOWN_STYLES = [
30
- // TODO: add exports from colorManipulator and transitions
30
+ // colorManipulator
31
+ 'hexToRgb',
32
+ 'rgbToHex',
33
+ 'hslToRgb',
34
+ 'decomposeColor',
35
+ 'recomposeColor',
36
+ 'getContrastRatio',
37
+ 'getLuminance',
38
+ 'emphasize',
39
+ 'fade',
40
+ 'alpha',
41
+ 'darken',
42
+ 'lighten',
43
+ // transitions
44
+ 'easing',
45
+ 'duration',
46
+ // styles
31
47
  'createTheme',
32
48
  'unstable_createMuiStrictModeTheme',
33
49
  'createMuiTheme',
@@ -139,7 +155,11 @@ module.exports = {
139
155
  const value = s.imported.name;
140
156
  const alias = s.local.name === value ? undefined : s.local.name;
141
157
 
142
- const propsMatch = /^([A-Z]\w+)Props$/.exec(value);
158
+ const propsMatch =
159
+ /^([A-Z]\w+)Props$/.exec(value) ??
160
+ (node.source.value === '@material-ui/pickers'
161
+ ? /^Keyboard([A-Z]\w+Picker)$/.exec(value)
162
+ : null);
143
163
 
144
164
  const emitProp = propsMatch !== null;
145
165
  const emitComponent = !emitProp;
@@ -188,7 +208,7 @@ module.exports = {
188
208
  if (specifier.emitProp && !specifier.emitComponent) {
189
209
  const replacement = `import { ${getNamedImportValue(
190
210
  specifier,
191
- )} } from '@material-ui/core/${specifier.componentValue}';`;
211
+ )} } from '${node.source.value}/${specifier.componentValue}';`;
192
212
  replacements.push(replacement);
193
213
  }
194
214
 
@@ -197,9 +217,9 @@ module.exports = {
197
217
  replacements.push(
198
218
  `import ${
199
219
  specifier.componentAlias ?? specifier.componentValue
200
- }, { ${getNamedImportValue(
201
- specifier,
202
- )} } from '@material-ui/core/${specifier.componentValue}';`,
220
+ }, { ${getNamedImportValue(specifier)} } from '${
221
+ node.source.value
222
+ }/${specifier.componentValue}';`,
203
223
  );
204
224
  }
205
225
  }
@@ -93,6 +93,8 @@ import SvgIcon, { SvgIconProps } from '@material-ui/core/SvgIcon';`,
93
93
  ThemeProvider,
94
94
  WithStyles,
95
95
  Tooltip as MaterialTooltip,
96
+ alpha,
97
+ easing
96
98
  } from '@material-ui/core';`,
97
99
  errors: [{ messageId: 'topLevelImport' }],
98
100
  output: `import Box from '@material-ui/core/Box';
@@ -101,7 +103,7 @@ import DialogContent from '@material-ui/core/DialogContent';
101
103
  import DialogTitle from '@material-ui/core/DialogTitle';
102
104
  import Grid from '@material-ui/core/Grid';
103
105
  import MaterialTooltip from '@material-ui/core/Tooltip';
104
- import { makeStyles, ThemeProvider, WithStyles } from '@material-ui/core/styles';`,
106
+ import { makeStyles, ThemeProvider, WithStyles, alpha, easing } from '@material-ui/core/styles';`,
105
107
  },
106
108
  {
107
109
  code: `import { Box, Button, makeStyles } from '@material-ui/core';`,
@@ -111,11 +113,11 @@ import Button from '@material-ui/core/Button';
111
113
  import { makeStyles } from '@material-ui/core/styles';`,
112
114
  },
113
115
  {
114
- code: `import { Paper, Typography, styled, withStyles } from '@material-ui/core';`,
116
+ code: `import { Paper, Typography, styled, withStyles, alpha, duration} from '@material-ui/core';`,
115
117
  errors: [{ messageId: 'topLevelImport' }],
116
118
  output: `import Paper from '@material-ui/core/Paper';
117
119
  import Typography from '@material-ui/core/Typography';
118
- import { styled, withStyles } from '@material-ui/core/styles';`,
120
+ import { styled, withStyles, alpha, duration } from '@material-ui/core/styles';`,
119
121
  },
120
122
  {
121
123
  code: `import { styled } from '@material-ui/core';`,
@@ -152,5 +154,17 @@ import { styled, withStyles } from '@material-ui/core/styles';`,
152
154
  errors: [{ messageId: 'topLevelImport' }],
153
155
  output: `import { styled as s } from '@material-ui/core/styles';`,
154
156
  },
157
+ {
158
+ code: `import { TreeItem, TreeItemProps, TreeView, AlertProps } from '@material-ui/lab';`,
159
+ errors: [{ messageId: 'topLevelImport' }],
160
+ output: `import TreeItem, { TreeItemProps } from '@material-ui/lab/TreeItem';
161
+ import TreeView from '@material-ui/lab/TreeView';
162
+ import { AlertProps } from '@material-ui/lab/Alert';`,
163
+ },
164
+ {
165
+ code: `import { KeyboardDatePicker } from '@material-ui/pickers';`,
166
+ errors: [{ messageId: 'topLevelImport' }],
167
+ output: `import { KeyboardDatePicker } from '@material-ui/pickers/DatePicker';`,
168
+ },
155
169
  ],
156
170
  });