Skip to content

formatter/sort-imports: newlinesBetween inside groups option #17830

@Sysix

Description

@Sysix

I want to strictly sort my imports by type and defining where to put a newline between.

My json .oxfmtrc.json looks like this:

{
  "experimentalSortImports": {
    "newlinesBetween": false,
    "groups": [
      "value-builtin",
      "value-internal",
      "value-external",
      "value-parent",
      "value-sibling",
      "value-index",
      // { "newlinesBetween": 1 },
      "type-internal",
      "type-import",
      "type-parent",
      "type-sibling",
      "type-index",
      "ts-equals-import",
      // { "newlinesBetween": 1 },
      "unknown",
    ],
  },
}

When I use newslinesBetweeen: true and create subgroups like groups: [[/* all values */], [/* all types*/]], the subgroups order is no longer respected, and all value imports are getting sort alphabetical

possible solution

https://perfectionist.dev/rules/sort-imports#groups

perfectionist ESLint plugin has a newlinesBetween object which can be passed into groups.
oxfmt does not parse it:

Failed to parse configuration.
Failed to deserialize Oxfmtrc: groups must be an array of strings or arrays of strings

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions