trivago / prettier-plugin-sort-imports

A prettier plugin to sort imports in typescript and javascript files by the provided RegEx order.
Apache License 2.0
3.37k stars 133 forks source link

Typescript typecasting generic function reports missing semicolon #267

Open puzzler7 opened 1 year ago

puzzler7 commented 1 year ago

Your Environment

Describe the bug

When formatting Typescript, prettier reports there is a missing semicolon in the middle of typecasting a generic function. Specifically, it reports that there should be a semicolon before the as in this code:

function func<T>() {};
const x = func<number> as any;

This error does not happen if the @trivago/prettier-plugin-sort-imports plugin is not included.

To Reproduce Run prettier on the above code snippet with @trivago/prettier-plugin-sort-imports installed.

Expected behavior

Prettier should output no errors.

Screenshots, code sample, etc

Minimal repro - repro.ts:

function func<T>() {};
const x = func<number> as any;

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

$ cat .prettierrc.yaml 
printWidth: 100
proseWrap: always
plugins: ["@trivago/prettier-plugin-sort-imports"]
importOrder:
  ["^reflect-metadata$", "(firebase-auth-mock|logrocket-mock)$", "<THIRD_PARTY_MODULES>", "^[./]"]
importOrderCaseInsensitive: true
importOrderParserPlugins: ["typescript", "jsx", "decorators-legacy"]
importOrderSeparation: true
importOrderSortSpecifiers: true

Error log

$ prettier -c repro.ts
Checking formatting...
repro.ts
[error] repro.ts: SyntaxError: Missing semicolon. (2:25)
All matched files use Prettier code style!

Contribute to @trivago/prettier-plugin-sort-imports