azat-io / eslint-plugin-perfectionist

🦄 ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://eslint-plugin-perfectionist.azat.io
MIT License
1.62k stars 28 forks source link

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

Open in-in opened 5 months ago

in-in commented 5 months ago

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

azat-io commented 5 months ago

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' 
in-in commented 5 months ago

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

azat-io commented 5 months ago

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

in-in commented 5 months ago

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