IanVS / prettier-plugin-sort-imports

An opinionated but flexible prettier plugin to sort import statements
Apache License 2.0
951 stars 21 forks source link

v4 breaks prettier blob formatting #103

Closed sitch closed 1 year ago

sitch commented 1 year ago

When using prettier to directly format a string, i.e.:

import prettier from "prettier"

prettier.format(content, options)

This raises an error because filePath isn't always available for the check:

https://github.com/IanVS/prettier-plugin-sort-imports/blob/e20a9fd14a2d261d6c8602675ff0183010098b26/src/utils/normalize-plugin-options.ts#L91

Should be able to just use an option chain on that value filepath?.endsWith(".ts")

IanVS commented 1 year ago

Yeah that sounds reasonable, would you like to submit a PR?

thebuilder commented 1 year ago

Also ran into this. Came around it by removing the plugins from options for now. (Which also disables this plugin).

Was also thinking the optional chain is the right fix. 👍

sitch commented 1 year ago

@IanVS happy to send a PR.