Force multiline typescript constructor in VS Code
Asked Answered
H

2

8

I'm setting up some tslint rules, in order for my team and I to better adhere to our code contract. Is there any weay to use tslint, or vs code in general, to force the use of multiline contructors

eg

this

  constructor(
    private coreWebServices: CoreWebServices,
    private deviceDiscoveryService: DeviceDiscoveryService,
    private eventsService: EventsService,
    private log: LogService,
    private newsService: NewsService,
    private route: ActivatedRoute,
    private router: Router,
    private runtimeService: RunTimeService
  ) {  }

in stead of this

constructor(private coreWebServices: CoreWebServices, private deviceDiscoveryService: DeviceDiscoveryService, private eventsService: EventsService, private log: LogService, private newsService: NewsService, private route: ActivatedRoute, private router: Router, private runtimeService: RunTimeService)
   { }
Halfpint answered 11/1, 2018 at 7:1 Comment(1)
Use Intellij Webstorm. Muche more configurable and powerful.Episcopal
U
0

Unfortunately, neither TSLint nor ESLint seem to have a rule you're looking for.

The closest one is align + "parameters", but I don't see a way to configure it working with constructors only.

Unsupportable answered 11/1, 2018 at 23:32 Comment(1)
align: "parameters" doesn't break single line into multiple lines. It only aligns existing multiple lines with indentation so that all of them are on the same "column" (have same indent (spaces/tabs) from the left).Murrumbidgee
S
-1

Apparently there's a hack, if you add a comment after the line.

Source: My colleague and https://github.com/prettier/prettier-vscode/issues/352

Struggle answered 15/1, 2020 at 15:36 Comment(1)
You need to clarify that this requires the Prettier extension, and that the link only applies to arrays.Murrumbidgee

© 2022 - 2024 — McMap. All rights reserved.