azz / prettier-tslint

Code ➡️ prettier ➡️ tslint --fix ➡️ Formatted Code ✨
https://npm.im/prettier-tslint
MIT License
225 stars 13 forks source link

prettier-tslint mangles imports when reordering #19

Closed kbd closed 5 years ago

kbd commented 6 years ago

Environment:

Steps taken:

Created testing.ts with the following in it:

import crypto from 'crypto'
import path from 'path'
import fs from 'fs'

Upon calling "Format Document" in VS Code, it gets mangled to:

import crypto from 'crypto'
import fs from "f'path'ort path from "p'fs'

Correct is:

import crypto from 'crypto'
import fs from 'fs'
import path from 'path'

The vscode-tslint extension with tslint.autoFixOnSave set to true doesn't have this bug and correctly reorders imports on save.

sveyret commented 6 years ago

Same here. Even if it can be avoided by manually ordering imports, it is a quite a problematic issue, especially if you save your file without noticing the mess…

jeremytondo commented 6 years ago

I played around with this a bit and it seems like the issue is a combination of ordered-imports and quotemark in tslint.json. Specifically it seems like if you are trying to use ordered-imports and have quotemark set to single it mangles things. If you remove quotemark completely or if you set it to double that seemed to fix the problem for me. That said, once I removed quotemark from tslint.json I couldn't find a way to enforce this rule using prettier. No matter what that is set to, I still always get double quotes.

Long story short, I haven't really completely solved the issue, but hoping this may help troubleshoot the problem.

aleclarson commented 5 years ago

This is probably a tslint issue, not prettier-tslint. Since prettier does not re-order imports.

aleclarson commented 5 years ago

Let me know if you can reproduce this issue still. Fork this repository to start with.

aleclarson commented 5 years ago

Looks like many errors were being caused by an undefined parent property on AST nodes, which has now been fixed by e06519376f9acb30d6e05e02be49a4505d0b7dd2 (which will be released soon).