question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Formatting of *.ts files?

See original GitHub issue
  • I have searched through existing issues

Feature Request

Hi, sorry for perhaps a silly mistake on my end, but unless I’m understanding something wrong, formatting of plain .ts files is not supported at the moment (model / service .ts files)? The only way I’ve managed to make it work was to install the prettier vscode plugin, but that would then mess up the html formatting in .vue files. TS code inside .vue files which is inside <script lang="ts"> tag does get formatted without any issues.

Here’s my .vscode/settings.json

{
  "editor.insertSpaces": true,
  "editor.formatOnSave": true,
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatter.ts": "prettier",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-aligned",
      "wrap_line_length": 120,
      "indent_handlebars": true
    },
    "cSpell.words": [
      "validatable"
    ],
    "editor.tabSize": 2
  },
  "search.exclude": {
    "package-lock.json": true
  }
}

.prettierrc

{
  "trailingComma": "all",
  "jsxBracketSameLine": true,
  "printWidth": 120,
  "arrowParens": "avoid"
}

.prettierignore

.vscode/*
settings.json
tsconfig.*
tslint.json
.eslintrc.json

.editorconfig

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.ts]
quote_type = double

[*.md]
max_line_length = off
trim_trailing_whitespace = false

tslint.json

{
  "defaultSeverity": "warning",
  "extends": [
    "tslint:recommended"
  ],
  "linterOptions": {
    "exclude": [
      "node_modules/**",
      ".vscode/**"
    ]
  },
  "rules": {
    "no-empty": false,
    "quotemark": [
      true,
      "double"
    ],
    "indent": [
      true,
      "spaces",
      2
    ],
    "interface-name": false,
    "ordered-imports": false,
    "object-literal-sort-keys": false,
    "no-consecutive-blank-lines": true,
    "eofline": false,
    "member-access": [
      true,
      "no-public"
    ],
    "max-classes-per-file": false,
    "arrow-parens": [
      true,
      "ban-single-arg-parens"
    ]
  }
}

Thank you!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
octrefcommented, Aug 26, 2020

I don’t know how to turn it off for html inside .vue files.

F1, run this command to open settings.json:

image

{
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  },
  "vetur.format.defaultFormatter.html": "<YOUR_CHOICE>",
  "vetur.format.defaultFormatter.css": "prettier",
  "vetur.format.defaultFormatter.js": "prettier"
}

Open settings UI, then

1reaction
tihomir-kitcommented, Aug 26, 2020

That’s it! Perfect, thanks a lot!

This bit did it, I didn’t think of solving it that way:

"[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript Formatter online to format TS code. - Code Beautify
TypeScript Formatter is easy to use tool to beautify TS code. Copy, Paste, and Format. What can you do with TS Code Formatter?...
Read more >
TS File (What It Is & How to Open One) - Lifewire
A file with the .TS file extension is a Video Transport Stream file used to store MPEG-2-compressed video data. They're often seen on...
Read more >
Code Style. TypeScript | WebStorm Documentation - JetBrains
Use this page to configure formatting options for TypeScript files. When you change these settings, the Preview pane shows how this will ...
Read more >
TypeScript Programming with Visual Studio Code
Formatting. VS Code includes a TypeScript formatter that provides basic code formatting with reasonable defaults. Use the typescript.format.
Read more >
Why is Prettier not formating one of the .ts files? - Stack Overflow
Timeout in milliseconds after which the formatting that is run on file save is cancelled. That wasn't enough time for Prettier to format...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found