IanVS / prettier-plugin-sort-imports

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

Add support for import attributes #174

Closed IanVS closed 3 weeks ago

IanVS commented 3 weeks ago

There are three styles of import assertions/attributes that have been proposed over the years and made it to various stages of TC-39. Here's a bit of history:

1) import x from 'x' with type: "json" - original proposal, made it to stage 2 2) import x from 'x' assert { type: 'json' }; - import "assertion", got to stage 3, then found problems 3) import x from 'x' with { type: 'json' }; - import "attribute", current proposal, stage 3

Babel only supports these with the use of a parser plugin, either importAttributes or importAssertions. Also, babel/generator has to be told which style to generate. Upstream has a PR, https://github.com/trivago/prettier-plugin-sort-imports/pull/273/files, which adds another user-level option to control this. Instead, I've taken the stance here that we should only generate the latest "import attribute" style code. So, not only does this PR add support for import attributes/assertions, this has the side-effect of converting deprecated import assertions to import attributes. Maybe there's some reason someone would want to stick with the old style, but I can't think of one, and I personally would appreciate getting updated to the latest format.

IanVS commented 3 weeks ago

Yeah I don't have experience or opinions on them myself, but wanted to get ahead of any issue reports since it's already something that has come up in the upstream package.