eslint-plugin-perfectionist icon indicating copy to clipboard operation
eslint-plugin-perfectionist copied to clipboard

Bug: (The plugin does not respect inline type qualifiers)

Open in-in opened this issue 1 year ago • 4 comments

Describe the bug

The plugin does not respect inline type qualifiers

//.eslintrc.js
"perfectionist/sort-imports": [
  "error",
  {
    "type": "alphabetical",
    "ignore-case": true,
    "groups": [
      ["builtin-type", "type"],
      "internal-type",
      ["parent-type", "sibling-type", "index-type"],
      "customTypes",
      "builtin",
      "external",
      "internal",
      ["parent", "sibling", "index"],
      "side-effect",
      "object",
      "style",
      "unknown",
    ],
    "internal-pattern": ["@/**"],
  },
],

Code example

// webpack.config.ts
import type { Configuration as DevServerConfiguration } from "webpack-dev-server";

import path from "node:path";

import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import TerserPlugin from "terser-webpack-plugin";
import { type Configuration } from "webpack"; // <-- This import should not be the last import in the list
// webpack.config.ts
import type { Configuration } from "webpack"; // <-- Without inline type qualifiers, sorting occurs as expected
import type { Configuration as DevServerConfiguration } from "webpack-dev-server";

import path from "node:path";

import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import TerserPlugin from "terser-webpack-plugin";

ESLint version

8.55.0

ESLint Plugin Perfectionist version

2.5.0

Additional comments

https://typescript-eslint.io/blog/consistent-type-imports-and-exports-why-and-how/

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#type-modifiers-on-import-names

Validations

  • [X] Read the docs.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

in-in avatar Dec 07 '23 06:12 in-in

Yes, the plugin identifies type imports as type imports, and imports where types have been imported as normal imports.

// external-type group
import type { Configuration } from 'webpack' 

// external group
import { type Configuration } from 'webpack' 

azat-io avatar Dec 07 '23 13:12 azat-io

So it's not a bug, it's a feature, right?

in-in avatar Dec 07 '23 16:12 in-in

Yep. At least that's the idea. Do you think it should work differently?

azat-io avatar Dec 07 '23 19:12 azat-io

I'm really surprised that importing a type is treated like importing a module, but I don't have a strong opinion on that.

in-in avatar Dec 08 '23 04:12 in-in

Thank you for your issue!

I think this is expected behaviour. And I'll close the question. If you have a different opinion, please post.

azat-io avatar Jul 22 '24 12:07 azat-io