IanVS / prettier-plugin-sort-imports

An opinionated but flexible prettier plugin to sort import statements
Apache License 2.0
1.02k stars 25 forks source link

Fix importOrderCombineTypeAndValueImports for Flow #57

Closed IanVS closed 1 year ago

IanVS commented 1 year ago

Fixes https://github.com/IanVS/prettier-plugin-sort-imports/issues/56

I needed to loosen the assertion a bit, because Flow's AST does not apparently use an importKind of "value" for specifiers, instead it is null.

I also added an e2e test here, for both Flow and TypeScript.

IanVS commented 1 year ago

@andidev, if you'd like to test this out in your project, you can find this package in your node_modules and update convertImportSpecifierToType in lib/src/utils/merge-nodes-with-matching-flavors.js to:

function convertImportSpecifierToType(node) {
    (0, assert_1.default)(node.importKind === 'value' ||
        node.importKind === 'type' ||
        // importKind can be null when using Flow
        node.importKind === null);
    node.importKind = 'type';
}
IanVS commented 1 year ago

Thanks @fbartho. I'll give @andidev, a bit longer to hopefully test this out, because I have a feeling there could be other issues with Flow, and it would be good to confirm whether that's the case or not.

andidev commented 1 year ago

We have a large code base and it seems to work well except this setting. But maybe there is more specific cases related to this setting. But to be honest ai don't think so.