eslint-plugin-perfectionist
eslint-plugin-perfectionist copied to clipboard
Bug: (The plugin does not respect inline type qualifiers)
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.
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'
So it's not a bug, it's a feature, right?
Yep. At least that's the idea. Do you think it should work differently?
I'm really surprised that importing a type is treated like importing a module, but I don't have a strong opinion on that.
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.