-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type imports #35
Comments
@mattiaz9, do you prefer that over this syntax? import { a, type A } from 'foo';
import { b, type B } from 'bar'; |
@IanVS yes, I prefer to separate them |
@mattiaz9 you can try https://github.com/serverless-guru/prettier-import-order which is a fork of this project and have this feature. |
Thank you @tusharf5, but I can't put the types where I want, so I rather wait for the feature to be implemented |
Closes #35 Adapted from trivago/prettier-plugin-sort-imports#153, by @Xenfo. This adds a new special string, `<TYPES>` that can be added to the `importOrder` array. When used, it will cause type imports to be sorted as specified by its location in the array. Notes: - If it is used, it will disable `importOrderCombineTypeAndValueImports`, throwing a warning if both are used. This is because: - We will split apart type and value import declarations if `<TYPES>` is used, so that types can be sorted appropriately. - Thinking towards the next breaking change when we remove options, I think the default will be to enable `importOrderCombineTypeAndValueImports`, and this change will give users a good way to opt-out of that behavior if they want, by specifying the location for `<TYPES>`.
@IanVS I'm trying out the new version, but it doesn't seem to work. Or maybe I'm doing something wrong. This is my config: module.exports = {
importOrder: [
"^react",
"^next",
"<THIRD_PARTY_MODULES>",
"",
".s?css$",
"^@heroicons",
"^@/assets",
"",
"^[./]",
"^@/",
"",
"<TYPES>^[./]",
"<TYPES>^react",
"<TYPES>^next",
"<TYPES>^@/",
"<TYPES>",
],
importOrderSeparation: false,
importOrderMergeDuplicateImports: true,
} This is an example result of how it sorts the imports: import React, { useCallback, useEffect, useState } from "react"
import isHotkey from "is-hotkey"
import { createEditor, Transforms, Editor as SlateEditor } from "slate"
import { Slate, Editable, ReactEditor } from "slate-react"
import Block from "./blocks/Block"
import type { BlockProps } from "./blocks/Block"
import Field from "./blocks/Field"
import Image from "./blocks/Image"
import type { LeafProps } from "./blocks/Leaf"
import Leaf from "./blocks/Leaf"
import Page from "./blocks/Page"
import type { PageProps } from "./blocks/Page"
import Table from "./blocks/Table"
import TableCell from "./blocks/TableCell"
import TableRow from "./blocks/TableRow"
import type { FullEditor } from "./plugins/with-plugins"
import withPlugins from "./plugins/with-plugins"
import EditorSidebar from "./sidebar/EditorSidebar"
import Toolbar from "./toolbar/Toolbar"
import { injectFonts } from "@/utils/fonts"
import { DEFAULT_FONT, FONT_FAMILIES, HOTKEYS, toggleMark } from "@/utils/slate"
import type { DescendantExtra, SlateElementExtra } from "@/utils/slate" |
Thanks for trying it out, and for providing the example. I'm looking into it. |
We had a bug, identified in #35 (comment), which was causing the `"^[./]"` group to include both type and value imports, instead of only value imports. This PR fixes that bug, and expands both the unit and e2e tests, which fail without this change and pass with it.
@mattiaz9 I've pushed up a fix in https://github.com/IanVS/prettier-plugin-sort-imports/releases/tag/v3.7.1. Using your config and example, I now get this output: import React, { useCallback, useEffect, useState } from "react";
import isHotkey from "is-hotkey";
import { createEditor, Transforms, Editor as SlateEditor } from "slate";
import { Slate, Editable, ReactEditor } from "slate-react";
import Block from "./blocks/Block";
import Field from "./blocks/Field";
import Image from "./blocks/Image";
import Leaf from "./blocks/Leaf";
import Page from "./blocks/Page";
import Table from "./blocks/Table";
import TableCell from "./blocks/TableCell";
import TableRow from "./blocks/TableRow";
import withPlugins from "./plugins/with-plugins";
import EditorSidebar from "./sidebar/EditorSidebar";
import Toolbar from "./toolbar/Toolbar";
import { injectFonts } from "@/utils/fonts";
import {
DEFAULT_FONT,
FONT_FAMILIES,
HOTKEYS,
toggleMark,
} from "@/utils/slate";
import type { BlockProps } from "./blocks/Block";
import type { LeafProps } from "./blocks/Leaf";
import type { PageProps } from "./blocks/Page";
import type { FullEditor } from "./plugins/with-plugins";
import type { DescendantExtra, SlateElementExtra } from "@/utils/slate"; |
Is your feature request related to a problem?
I'd like to sort all my types into one single group.
Example:
Describe the solution you'd like
Something like this:
trivago/prettier-plugin-sort-imports#153
Describe alternatives you've considered
None
The text was updated successfully, but these errors were encountered: