Description
In light of the number of issues reported with this rule I wanted to bring them together in one place in order to inform a greatly improved implementation of sorting imports
metadata.
-
Now that standalone components are stable, the rule should allow for sorting imports in
Component
metadata as well asNgModule
s- This is an important point and almost certainly means that a new rule should be created to replace
sort-ngmodule-metadata-arrays
which should be deprecated in favour of it*
(Originally reported here: [sort-ngmodule-metadata-arrays] support standalone component #1133)
- This is an important point and almost certainly means that a new rule should be created to replace
-
Sorting of
imports
does not work when some have.forRoot()
(Originally reported here: @angular-eslint/sort-ngmodule-metadata-arrays : doesn't order module with .forRoot() #927) -
The rule implementation needs to be completely refactored in order to allow for reliable auto-fixing. I won't cover this in detail as this is done on [sort-ngmodule-metadata-arrays]
--fix
not able to correct all the reports once #675 but essentially the way ESLint auto-fixing works means we cannot do what we do for other rules and simply apply a fix to an item we detect as being in the wrong place. There could easily be more than 10 items in the wrong place, but ESLint would give up at this point.
(Originally reported here: [sort-ngmodule-metadata-arrays]--fix
not able to correct all the reports once #675)
In light of this last point, the new rule instead needs to focus on extracting the relevant chunks of a file manually (not using granular AST selectors) and fixing the final form in one action.
This is the approach taken by this import sorting plugin for example: https://github.com/lydell/eslint-plugin-simple-import-sort/blob/main/src/imports.js
*The new rule will be called @angular-eslint/sort-imports-metadata