This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
noConstructorReturn
doesn't make sense in ES6
#4472
GeorgeTailor
started this conversation in
Suggestions
Replies: 1 comment 4 replies
-
Have you more pointers talking about this pattern? Singletons are often implemented using a factory method: export class NotePositionService {
private static instance: NotePositionService | null = null;
static getInstance(): NotePositionService {
if (NotePositionService.instance) {
NotePositionService.instance = new NotePositionService();
}
return NotePositionService.instance;
}
private constructor() {
// some heavy initiazer logic
}
} Or making the constructor inaccessible: class NotePositionService {
static instance: NotePositionService;
constructor() {
// some heavy initiazer logic
}
}
export function instance(): NotePositionService {
if (NotePositionService.instance) {
NotePositionService.instance = new NotePositionService();
}
return NotePositionService.instance;
}
export type { NotePositionService } |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Environment information
What happened?
The default rome lint rule https://docs.rome.tools/lint/rules/noconstructorreturn/
does not make sense in ES6, which is marking creation of OOP-style singletons as incorrect. Blindly copy-pasting rules from eslint, imo, is not a good idea.
Consider the following code:
Sadly, #4005 turned into a noop.
Expected result
https://docs.rome.tools/lint/rules/noconstructorreturn/
should not be the default.
Beta Was this translation helpful? Give feedback.
All reactions