Skip to content
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

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

Open
2 tasks done
in-in opened this issue Dec 7, 2023 · 4 comments
Open
2 tasks done

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

in-in opened this issue Dec 7, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@in-in
Copy link

in-in commented Dec 7, 2023

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

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@in-in in-in added the bug Something isn't working label Dec 7, 2023
@azat-io
Copy link
Owner

azat-io commented Dec 7, 2023

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
Copy link
Author

in-in commented Dec 7, 2023

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

@azat-io
Copy link
Owner

azat-io commented Dec 7, 2023

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

@in-in
Copy link
Author

in-in commented Dec 8, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants