Skip to content

order rule does not respect parent, sibling, nor index in simple-to-reproduce setup #284

Closed
@kylemh

Description

@kylemh

Reproduction:

https://github.com/kylemh/demo-import-x-issue

  1. pnpm dlx create-next-app@latest --use-pnpm
  2. touch .nvmrc
  3. add 22 to .nvmrc
  4. nvm use
  5. pnpm add -D typescript-eslint eslint-plugin-import-x @typescript-eslint/parser
  6. paste below config into eslint.config.mjs
  7. Create dummy files and purposefully set bad order (source code at bottom of this post)

Config

eslint.config.mjs:

import tseslint from 'typescript-eslint';
import eslintPluginImportX from 'eslint-plugin-import-x';
import tsParser from '@typescript-eslint/parser';

/**
 * @type {import("eslint").Linter.Config['languageOptions']}
 * @see https://typescript-eslint.io/getting-started/typed-linting
 */
const languageOptions = {
  parser: tsParser,
  parserOptions: {
    project: true,
    tsconfigRootDir: import.meta.dirname,
  },
  ecmaVersion: 'latest',
  sourceType: 'module',
};

/**
 * @type {import("eslint").Linter.Config}
 */
const allTheRules = {
  files: ['./src/**/*.{ts,tsx}'],
  rules: {
    // @typescript-eslint plugin rules
    '@typescript-eslint/consistent-type-imports': 'error',
    '@typescript-eslint/explicit-module-boundary-types': 'off',
    '@typescript-eslint/naming-convention': [
      'error',
      {
        selector: ['variable', 'parameter', 'parameterProperty', 'typeProperty', 'classProperty'],
        types: ['boolean'],
        format: ['PascalCase', 'UPPER_CASE'],
        prefix: [
          'is',
          'was',
          'should',
          'has',
          'can',
          'did',
          'will',
          'IS_',
          'WAS_',
          'SHOULD_',
          'HAS_',
          'CAN_',
          'DID_',
          'WILL_',
        ],
      },
    ],
    '@typescript-eslint/no-empty-interface': ['error', { allowSingleExtends: true }],
    '@typescript-eslint/no-explicit-any': 'error',
    '@typescript-eslint/no-inferrable-types': 'error',
    '@typescript-eslint/no-unused-vars': 'error',

    // import plugin rules
    'import-x/order': [
      'error',
      {
        alphabetize: { order: 'asc', caseInsensitive: true },
        groups: [
          'builtin',
          'external',
          'internal',
          'parent',
          'sibling',
          'index',
          'unknown',
          'type',
        ],
        'newlines-between': 'always',
      },
    ],
    'import-x/no-named-as-default': 'off',
  },
};

export default tseslint.config(
  { ignores: ['./eslint.config.mjs'] },
  tseslint.configs.recommendedTypeChecked,
  { languageOptions }, // will be used for all configs below
  eslintPluginImportX.flatConfigs.recommended,
  eslintPluginImportX.flatConfigs.typescript,
  allTheRules,
);

Relevant Source Code

No errors in the below within src/app/layout.tsx

import './globals.css';
import './';
import { Geist, Geist_Mono } from 'next/font/google';

import { log } from '@/utils/log';

import type { Metadata } from 'next';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions