I'm writing web app using Koa and Typescript. In vscode i faced with unwanted code formatting: when i declare variables using object desctructing approach vscode autoformat it in multilines:
deleteUser: async (ctx: Context) => {
const {
body: { userId }
} = ctx;
await userService.deleteUser(userId);
}
And i want it in this case remain in a single line:
deleteUser: async (ctx: Context) => {
const { body: { userId } } = ctx;
await userService.deleteUser(userId);
}
I like how vscode handles my code formatting, so i don't want to disable it. But i want to find a workaround to disable object destructuring formatting if line length less than 80 chars.
What rule should i use to fix this ? Should i change vscode rules or tslint rules ?
Here's my .tslint file:
{
"rules": {
"class-name": true,
"comment-format": [true, "check-space"],
"indent": ["tabs"],
"one-line": [true, "check-open-brace", "check-whitespace"],
"no-var-keyword": true,
"quotemark": [true, "double", "avoid-escape"],
"semicolon": [true, "always", "ignore-bound-class-methods"],
"max-line-length": [true, 120],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-module",
"check-separator",
"check-type",
"check-preblock"
],
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
},
{
"call-signature": "onespace",
"index-signature": "onespace",
"parameter": "onespace",
"property-declaration": "onespace",
"variable-declaration": "onespace"
}
],
"no-internal-module": true,
"no-trailing-whitespace": true,
"no-null-keyword": true,
"prefer-const": true,
"jsdoc-format": true
}
}
You can install beautify plugin and add following config in vscode's settings.json.