Closed imranbarbhuiya closed 1 year ago
do you also use prettier? you can use @trivago/prettier-plugin-sort-imports . It's quite configurable. See https://github.com/documenso/documenso/blob/main/prettier.config.js as an example
yes but it's diff than what I want. I'm talking about these imports
, exports
,
@Module({
imports: [ServersModule, MongoStatsModule],
controllers: [ServersController],
providers: [ServersService, MongoStatsService],
})
export class ServersModule {}
ahh right. gotcha
I added this. it's in the latest version. i ran it on one of my projects and it seems to work as expected.
It's not in default config, you'll have to turn it on.
Docs are here: https://github.com/darraghoriordan/eslint-plugin-nestjs-typed/blob/main/src/docs/rules/sort-module-metadata-arrays.md
Thanks ❤️. I'll test and will let uk
Hi @darraghoriordan, Array sorting works for most of the files but sometimes it needs multiple runs to sort. It sorts one by one ig. Example of such Module
@Module({
imports: [
ServeStaticModule.forRoot({
rootPath: join(__dirname, '..', 'public'),
serveStaticOptions: {
index: false,
fallthrough: false,
},
}),
ConfigModule.forRoot({
isGlobal: true,
envFilePath: '.env',
}),
MongooseModule.forRoot(process.env.DB_URI, {
connectionName: 'sofi',
connectionFactory: (connection: Connection) => {
connection.on('connected', () => {
logger.log('Sofi DB connected');
});
connection.on('disconnected', () => {
logger.log('Sofi DB disconnected');
});
connection.on('error', (error) => {
logger.log(`Sofi DB connection failed! Error: ${error}`);
});
logger.log(`Sofi DB ${STATES[connection.readyState]}`);
return connection;
},
}),
MongooseModule.forRoot(process.env.PROFILE_DB_URI, {
connectionName: 'profile',
connectionFactory: (connection: Connection) => {
connection.on('connected', () => {
logger.log('Profile DB connected');
});
connection.on('disconnected', () => {
logger.log('Profile DB disconnected');
});
connection.on('error', (error) => {
logger.log(`Profile DB connection failed! Error: ${error}`);
});
logger.log(`Profile DB ${STATES[connection.readyState]}`);
return connection;
},
}),
AlbumModule,
ArtModule,
AuthModule,
BackgroundModule,
CharacterModule,
CommentModule,
EventModule,
FrameModule,
GlowModule,
ItemModule,
LikesModule,
MemberModule,
PostModule,
PriceModule,
ProfileModule,
ServersModule,
SpawnModule,
SusModule,
UserModule,
],
controllers: [],
providers: [],
})
export class AppModule {
also, the error message only says
Module
metadata arrays should be sorted in ASC alphabetical order
but it doesn't say about which prop
hey, thanks for testing it out. Yea I mentioned the issue with only fixing one item at a time in the docs. I agree its a bit annoying the first time you turn on the rule, but after that most additions to the list would be one-by-one.
Assuming someone lints in their IDE it should be ok.
I don't have any more time to spend on this but will happily accept PRs for those improvements. They would be awesome additions for all users of the plugin 👍
ref: https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/sort-ngmodule-metadata-arrays.md