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: fallbackSort causes sort-imports failed to fix #483

Closed
2 tasks done
ntnyq opened this issue Mar 9, 2025 · 2 comments · Fixed by #485
Closed
2 tasks done

Bug: fallbackSort causes sort-imports failed to fix #483

ntnyq opened this issue Mar 9, 2025 · 2 comments · Fixed by #485
Labels
bug Something isn't working

Comments

@ntnyq
Copy link
Contributor

ntnyq commented Mar 9, 2025

Describe the bug

Repro steps

  • Run pnpm run lint will report errors.

  • Run pnpm run lint:fix error still exists.

  • Comment fallbackSort option in eslint.config.mjs, no error reported.

Besides, if there is no // eslint-disable-next-line perfectionist/sort-imports, it still works fine.

Reproduction repo

https://github.com/ntnyq-dev/repro-perfectionist-sort-imports

Code example

Config

// @ts-check

import pluginPerfectionist from 'eslint-plugin-perfectionist'
import { config, configs } from 'typescript-eslint'

export default config(
  {
    extends: configs.recommended,
  },
  {
    plugins: {
      perfectionist: pluginPerfectionist,
    },
    rules: {
      '@typescript-eslint/ban-ts-comment': 'off',
      'perfectionist/sort-imports': [
        'error',
        {
          fallbackSort: { order: 'asc', type: 'alphabetical' },
          order: 'asc',
          type: 'alphabetical',
          groups: [
            // Side effect style imports (e.g. 'normalize.css')
            'side-effect-style',

            // Styles (e.g. *.{css,scss,less})
            'style',
            /**
             * Imports that don’t fit into any other group
             */
            'unknown',
          ],
          internalPattern: ['^~/.+', '^@/.+', '^#.+'],
        },
      ],
    },
  },
)

Code

import '@unocss/reset/tailwind.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import 'element-plus/theme-chalk/index.css'
import 'uno.css'
// COMMENT BELLOW is IMPORTANT
// eslint-disable-next-line perfectionist/sort-imports
import '@/styles/app.scss'

ESLint version

v9.22.0

ESLint Plugin Perfectionist version

v4.10.0

Additional comments

Since option order and type is the same as option fallbackSort.

I think there is no need to attempt to apply fallback sort.

Maybe some deep equal check.

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
@ntnyq ntnyq added the bug Something isn't working label Mar 9, 2025
@hugop95
Copy link
Contributor

hugop95 commented Mar 9, 2025

@ntnyq Thank you for the details, a fix will come soon. Your reproduction case actually includes 2 bugs: one related to fallbackSort and one related to eslint-disable:

Minimal reproduction case for eslint-disable:

interface Test {
  b: string;
  c: string;
  // eslint-disable-next-line
  a: string;
}

The fallbackSort issue is more important as it impacts order of side-effects, so it will be fixed in priority.

@azat-io
Copy link
Owner

azat-io commented Mar 9, 2025

Fixed in 1ac83c9.
Released in v4.10.1.

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
3 participants