Giter VIP home page Giter VIP logo

Comments (6)

azat-io avatar azat-io commented on May 23, 2024 1

Fixed in f35deef.
Will be released today.

from eslint-plugin-perfectionist.

jgoux avatar jgoux commented on May 23, 2024 1

I just tested v2.1.0, it seems to work for files directly in the root but not for paths with folders:

// 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": ["#**"],
}],

Edit

This internal-pattern syntax seems to do the trick! 💯

"internal-pattern": ["#*", "#*/**"],

from eslint-plugin-perfectionist.

azat-io avatar azat-io commented on May 23, 2024

Could you show me your current ESLint config?

from eslint-plugin-perfectionist.

jgoux avatar jgoux commented on May 23, 2024

@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": "^_" }],
    },
  },
]

from eslint-plugin-perfectionist.

azat-io avatar azat-io commented on May 23, 2024

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': ['#/**'],
      },
    ],

from eslint-plugin-perfectionist.

jgoux avatar jgoux commented on May 23, 2024

Yes I just realized that I override the whole sort-imports rule. 😅

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 minimatch is not able to apply the patterns #* or #**. With imports aliases, you can't have #/ (notice the slash here).

from eslint-plugin-perfectionist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.