|
| 1 | +[DSpace ESLint plugins](../../../../lint/README.md) > [TypeScript rules](../index.md) > `dspace-angular-ts/sort-standalone-imports` |
| 2 | +_______ |
| 3 | + |
| 4 | +Sorts the standalone `@Component` imports alphabetically |
| 5 | + |
| 6 | +_______ |
| 7 | + |
| 8 | +[Source code](../../../../lint/src/rules/ts/sort-standalone-imports.ts) |
| 9 | + |
| 10 | + |
| 11 | +### Options |
| 12 | + |
| 13 | +#### `locale` |
| 14 | + |
| 15 | +The locale used to sort the imports., |
| 16 | +#### `maxItems` |
| 17 | + |
| 18 | +The maximum number of imports that should be displayed before each import is separated onto its own line., |
| 19 | +#### `indent` |
| 20 | + |
| 21 | +The indent used for the project., |
| 22 | +#### `trailingComma` |
| 23 | + |
| 24 | +Whether the last import should have a trailing comma (only applicable for multiline imports). |
| 25 | + |
| 26 | + |
| 27 | +### Examples |
| 28 | + |
| 29 | + |
| 30 | +#### Valid code |
| 31 | + |
| 32 | +##### should sort multiple imports on separate lines |
| 33 | + |
| 34 | +```typescript |
| 35 | +@Component({ |
| 36 | + selector: 'ds-app', |
| 37 | + templateUrl: './app.component.html', |
| 38 | + styleUrls: ['./app.component.scss'], |
| 39 | + standalone: true, |
| 40 | + imports: [ |
| 41 | + AsyncPipe, |
| 42 | + RootComponent, |
| 43 | + ], |
| 44 | +}) |
| 45 | +export class AppComponent {} |
| 46 | +``` |
| 47 | + |
| 48 | +##### should not inlines singular imports when maxItems is 0 |
| 49 | + |
| 50 | +```typescript |
| 51 | +@Component({ |
| 52 | + selector: 'ds-app', |
| 53 | + templateUrl: './app.component.html', |
| 54 | + styleUrls: ['./app.component.scss'], |
| 55 | + standalone: true, |
| 56 | + imports: [ |
| 57 | + RootComponent, |
| 58 | + ], |
| 59 | +}) |
| 60 | +export class AppComponent {} |
| 61 | +``` |
| 62 | + |
| 63 | +##### should inline singular imports when maxItems is 1 |
| 64 | + |
| 65 | +```typescript |
| 66 | +@Component({ |
| 67 | + selector: 'ds-app', |
| 68 | + templateUrl: './app.component.html', |
| 69 | + styleUrls: ['./app.component.scss'], |
| 70 | + standalone: true, |
| 71 | + imports: [RootComponent], |
| 72 | +}) |
| 73 | +export class AppComponent {} |
| 74 | +``` |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +#### Invalid code & automatic fixes |
| 80 | + |
| 81 | +##### should sort multiple imports alphabetically |
| 82 | + |
| 83 | +```typescript |
| 84 | +@Component({ |
| 85 | + selector: 'ds-app', |
| 86 | + templateUrl: './app.component.html', |
| 87 | + styleUrls: ['./app.component.scss'], |
| 88 | + standalone: true, |
| 89 | + imports: [ |
| 90 | + RootComponent, |
| 91 | + AsyncPipe, |
| 92 | + ], |
| 93 | +}) |
| 94 | +export class AppComponent {} |
| 95 | +``` |
| 96 | +Will produce the following error(s): |
| 97 | +``` |
| 98 | +Standalone imports should be sorted alphabetically |
| 99 | +``` |
| 100 | + |
| 101 | +Result of `yarn lint --fix`: |
| 102 | +```typescript |
| 103 | +@Component({ |
| 104 | + selector: 'ds-app', |
| 105 | + templateUrl: './app.component.html', |
| 106 | + styleUrls: ['./app.component.scss'], |
| 107 | + standalone: true, |
| 108 | + imports: [ |
| 109 | + AsyncPipe, |
| 110 | + RootComponent, |
| 111 | + ], |
| 112 | +}) |
| 113 | +export class AppComponent {} |
| 114 | +``` |
| 115 | + |
| 116 | + |
| 117 | +##### should not put singular imports on one line when maxItems is 0 |
| 118 | + |
| 119 | +```typescript |
| 120 | +@Component({ |
| 121 | + selector: 'ds-app', |
| 122 | + templateUrl: './app.component.html', |
| 123 | + styleUrls: ['./app.component.scss'], |
| 124 | + standalone: true, |
| 125 | + imports: [RootComponent], |
| 126 | +}) |
| 127 | +export class AppComponent {} |
| 128 | +``` |
| 129 | +Will produce the following error(s): |
| 130 | +``` |
| 131 | +Standalone imports should be sorted alphabetically |
| 132 | +``` |
| 133 | + |
| 134 | +Result of `yarn lint --fix`: |
| 135 | +```typescript |
| 136 | +@Component({ |
| 137 | + selector: 'ds-app', |
| 138 | + templateUrl: './app.component.html', |
| 139 | + styleUrls: ['./app.component.scss'], |
| 140 | + standalone: true, |
| 141 | + imports: [ |
| 142 | + RootComponent, |
| 143 | + ], |
| 144 | +}) |
| 145 | +export class AppComponent {} |
| 146 | +``` |
| 147 | + |
| 148 | + |
| 149 | +##### should not put singular imports on a separate line when maxItems is 1 |
| 150 | + |
| 151 | +```typescript |
| 152 | +@Component({ |
| 153 | + selector: 'ds-app', |
| 154 | + templateUrl: './app.component.html', |
| 155 | + styleUrls: ['./app.component.scss'], |
| 156 | + standalone: true, |
| 157 | + imports: [ |
| 158 | + RootComponent, |
| 159 | + ], |
| 160 | +}) |
| 161 | +export class AppComponent {} |
| 162 | +``` |
| 163 | +Will produce the following error(s): |
| 164 | +``` |
| 165 | +Standalone imports should be sorted alphabetically |
| 166 | +``` |
| 167 | + |
| 168 | +Result of `yarn lint --fix`: |
| 169 | +```typescript |
| 170 | +@Component({ |
| 171 | + selector: 'ds-app', |
| 172 | + templateUrl: './app.component.html', |
| 173 | + styleUrls: ['./app.component.scss'], |
| 174 | + standalone: true, |
| 175 | + imports: [RootComponent], |
| 176 | +}) |
| 177 | +export class AppComponent {} |
| 178 | +``` |
| 179 | + |
| 180 | + |
| 181 | +##### should not display multiple imports on the same line |
| 182 | + |
| 183 | +```typescript |
| 184 | +@Component({ |
| 185 | + selector: 'ds-app', |
| 186 | + templateUrl: './app.component.html', |
| 187 | + styleUrls: ['./app.component.scss'], |
| 188 | + standalone: true, |
| 189 | + imports: [AsyncPipe, RootComponent], |
| 190 | +}) |
| 191 | +export class AppComponent {} |
| 192 | +``` |
| 193 | +Will produce the following error(s): |
| 194 | +``` |
| 195 | +Standalone imports should be sorted alphabetically |
| 196 | +``` |
| 197 | + |
| 198 | +Result of `yarn lint --fix`: |
| 199 | +```typescript |
| 200 | +@Component({ |
| 201 | + selector: 'ds-app', |
| 202 | + templateUrl: './app.component.html', |
| 203 | + styleUrls: ['./app.component.scss'], |
| 204 | + standalone: true, |
| 205 | + imports: [ |
| 206 | + AsyncPipe, |
| 207 | + RootComponent, |
| 208 | + ], |
| 209 | +}) |
| 210 | +export class AppComponent {} |
| 211 | +``` |
| 212 | + |
| 213 | + |
| 214 | + |
0 commit comments