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

Update our Default Sort Order builtins, (thirdparty & absolute paths), relative paths #83

Closed fbartho closed 1 year ago

fbartho commented 1 year ago

Fixes #76

[
            // built-ins are implicitly first
    '<THIRD_PARTY_MODULES>', // Actually means "all things that aren't otherwise matched" aka THIRD_PARTY_IMPORTS & Absolute Path Imports
    '^[.]', // relative imports
],
IanVS commented 1 year ago

There's no way to separate THIRD_PARTY_MODULES and absolute-imports currently

When you say "absolute-imports", do you mean imports using an absolute file path, like /users/foo/module? Or, do you mean internal (non-third-party) imports that are aliased and thus are non-relative like @src/helpers/module (ref https://github.com/trivago/prettier-plugin-sort-imports/issues/162)?

fbartho commented 1 year ago

I mean libs/path/to/thing.ts as opposed to (../../to/thing.ts or ./libs/path/to/thing.ts)

fbartho commented 1 year ago

I guess I should have called that a “root-relative-path” or repo-root-absolute-path? Idk what the right name for it is, but it is a pattern (that I discouraged in my repo(s)), that people ask for often enough that there’s instructions on how to use them in various runtime, typescript, webpack, etc.

fbartho commented 1 year ago

Or, do you mean internal (non-third-party) imports that are aliased and thus are non-relative like @src/helpers/module (ref https://github.com/trivago/prettier-plugin-sort-imports/issues/162)?

Yes, this. It’s clear it’s bedtime because I totally missed your comment about this. Sometimes those aliases don’t have any prefix and are just the path to the file, but as if you were at the root of the repo instead of wherever the file is importing from.

IanVS commented 1 year ago

I pushed up some examples for the README, let me know what you think, and feel free to adjust them.

fbartho commented 1 year ago

No objection to your README changes!