-
Notifications
You must be signed in to change notification settings - Fork 30
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: Respect package.json#imports #70
Comments
Could you show me your current ESLint config? |
@azat-io sure, here it is: import typescriptPlugin from '@typescript-eslint/eslint-plugin'
import typescriptParser from '@typescript-eslint/parser'
import importPlugin from 'eslint-plugin-import'
import nodeImportPlugin from 'eslint-plugin-node-import'
import perfectionistPlugin from 'eslint-plugin-perfectionist'
import unusedImportsPlugin from "eslint-plugin-unused-imports"
import globals from "globals";
export default [
{
files: [`**/*.@(js|jsx|ts|tsx)`],
ignores: [`.dts/**`],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
},
parser: typescriptParser,
parserOptions: {
project: `./tsconfig.json`,
},
},
plugins: {
'@typescript-eslint': typescriptPlugin,
'import': importPlugin,
'node-import': nodeImportPlugin,
'perfectionist': perfectionistPlugin,
'unused-imports': unusedImportsPlugin,
},
rules: {
...typescriptPlugin.configs['eslint-recommended'].rules,
...typescriptPlugin.configs['strict-type-checked'].rules,
...typescriptPlugin.configs['stylistic-type-checked'].rules,
...importPlugin.configs.recommended.rules,
...perfectionistPlugin.configs['recommended-natural'].rules,
"@typescript-eslint/array-type": ["error", { default: "generic" }],
"@typescript-eslint/consistent-type-imports": "error",
"@typescript-eslint/no-unused-vars": "off",
"import/consistent-type-specifier-style": ["error", "prefer-inline"],
"import/no-duplicates": ["error", { "prefer-inline": true }],
"import/no-unresolved": "off",
"node-import/prefer-node-protocol": "error",
"perfectionist/sort-imports": ["error", { "internal-pattern": ["#*", "#**"] }],
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": ["error", { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }],
},
},
] |
It looks like you forgot to configure the import groups. 'perfectionist/sort-imports': [
'error',
{
groups: [
'type',
['builtin', 'external'],
'internal-type',
'internal',
['parent-type', 'sibling-type', 'index-type'],
['parent', 'sibling', 'index'],
'object',
'unknown',
],
'internal-pattern': ['#/**'],
},
], |
Yes I just realized that I override the whole Unfortunately it's still not working: "perfectionist/sort-imports": ["error", {
...perfectionistPlugin.configs["recommended-natural"].rules["perfectionist/sort-imports"][1],
"newlines-between": "never",
"internal-pattern": ["#*", "#**"],
}], I think the issue is that |
Fixed in f35deef. |
I just tested // it works
import fs from "node:fs/promises";
import { type SDK } from "#config.js";
// it doesn't work
import { type SDK } from "#config/index.js";
import fs from "node:fs/promises"; My config: "perfectionist/sort-imports": ["error", {
...perfectionistPlugin.configs["recommended-natural"].rules["perfectionist/sort-imports"][1],
"newlines-between": "never",
"internal-pattern": ["#**"],
}], EditThis "internal-pattern": ["#*", "#*/**"], |
Describe the bug
Currently when using package.json's
imports
key to map internal files like:The
recommended-natural
rules aren't placing the internal pattern where it should be.For example it considers this to be valid:
while it should be:
Code example
I tried using the
internal-pattern
option without success, I tried both{ "internal-pattern": ["#*"] }
and{ "internal-pattern": ["#**"] }
.ESLint version
v8.49.0
ESLint Plugin Perfectionist version
v2.0.1
Additional comments
No response
Validations
The text was updated successfully, but these errors were encountered: