npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-import-category

v1.0.2

Published

ESLint plugin to enforce comment headers and ordering for import groups with full configurability

Readme

eslint-plugin-import-category

ESLint plugin to enforce comment headers and ordering for import groups with full configurability.

Installation

  npm install --save-dev eslint-plugin-import-category

Usage

With ESLint Flat Config (JavaScript - eslint.config.js)

const importCategory = require('eslint-plugin-import-category');
const tsParser = require('@typescript-eslint/parser');

module.exports = [{
    files: ['**/*.ts', '**/*.tsx'],
    languageOptions: {
        parser: tsParser,
        parserOptions: {
            ecmaVersion: 'latest',
            sourceType: 'module',
            project: './tsconfig.json',
        },
    },
    plugins: {
        'import-category': importCategory,
    },
    rules: {
        'import-category/import-category-comments': ['error'],
    },
}, ];

With ESLint Flat Config (TypeScript - eslint.config.ts)

import importCategory from 'eslint-plugin-import-category';
import tsParser from '@typescript-eslint/parser';
import type {
    Linter
} from 'eslint';

const config: Linter.FlatConfig[] = [{
    files: ['**/*.ts', '**/*.tsx'],
    languageOptions: {
        parser: tsParser,
        parserOptions: {
            ecmaVersion: 'latest',
            sourceType: 'module',
            project: './tsconfig.json',
        },
    },
    plugins: {
        'import-category': importCategory,
    },
    rules: {
        'import-category/import-category-comments': ['error'],
    },
}, ];

export default config;

Using Recommended Config

import importCategory from 'eslint-plugin-import-category';
import tsParser from '@typescript-eslint/parser';

export default [{
    files: ['**/*.ts', '**/*.tsx'],
    languageOptions: {
        parser: tsParser,
        parserOptions: {
            project: './tsconfig.json',
        },
    },
    ...importCategory.configs.recommended,
}, ];

Rule Configuration

Options

  • categories (array): Define your import categories with patterns and order

    • comment (string): The comment text for the category
    • patterns (string[]): RegExp patterns to match imports
    • order (number): Order priority (lower numbers come first)
  • typeImportsCategory (string | null): Comment for type-only imports (default: '// Types', use null to disable)

  • enforceOrder (boolean): Whether to enforce category order (default: true)

  • enforceComments (boolean): Whether to enforce category comments (default: true)

  • commentStyle ('line' | 'block'): Style of comments to use (default: 'line')

Default Configuration

{
    rules: {
        'import-category/import-category-comments': ['error', {
            categories: [{
                comment: '// React & Core Libraries',
                patterns: ['^react', '^react-dom', '^next'],
                order: 1,
            },
                {
                    comment: '// External Dependencies',
                    patterns: ['^@tanstack', '^axios', '^lodash'],
                    order: 2,
                },
                {
                    comment: '// UI Components',
                    patterns: ['^@/components', '^~/components'],
                    order: 3,
                },
                {
                    comment: '// Utilities & Helpers',
                    patterns: ['^@/utils', '^@/helpers', '^@/lib'],
                    order: 4,
                },
                {
                    comment: '// Styles',
                    patterns: ['\\.css$', '\\.scss$', '\\.module\\.css$'],
                    order: 5,
                },
            ],
            typeImportsCategory: '// Type Definitions',
            enforceOrder: true,
            enforceComments: true,
            commentStyle: 'line',
        }]
    }
}

Configuration Examples

Custom React Project Setup

    rules: {
        'import-category/import-category-comments': ['error', {
            categories: [{
                comment: '// React & Core Libraries',
                patterns: ['^react', '^react-dom', '^next'],
                order: 1,
            },
                {
                    comment: '// External Dependencies',
                    patterns: ['^@tanstack', '^axios', '^lodash'],
                    order: 2,
                },
                {
                    comment: '// UI Components',
                    patterns: ['^@/components', '^~/components'],
                    order: 3,
                },
                {
                    comment: '// Utilities & Helpers',
                    patterns: ['^@/utils', '^@/helpers', '^@/lib'],
                    order: 4,
                },
                {
                    comment: '// Styles',
                    patterns: ['\\.css$', '\\.scss$', '\\.module\\.css$'],
                    order: 5,
                },
            ],
            typeImportsCategory: '// Type Definitions',
            enforceOrder: true,
            enforceComments: true,
            commentStyle: 'line',
        }]
    }

Disable Type Imports Category

{
    rules: {
        'import-category/import-category-comments': ['error', {
            typeImportsCategory: null,
        }]
    }
}

Use Block Comments

{
    rules: {
        'import-category/import-category-comments': ['error', {
            commentStyle: 'block',
            categories: [{
                comment: 'External Libraries',
                patterns: ['^[a-z@]'],
                order: 1,
            }, ],
        }]
    }
}

Only Enforce Order (No Comments)

{
    rules: {
        'import-category/import-category-comments': ['error', {
            enforceComments: false,
            enforceOrder: true,
        }]
    }
}

Example Output

Before

import { useState } from 'react';
import type { User } from '@/types/user';
import axios from 'axios';
import { Button } from '@/components/Button';
import type { Config } from './config';
import './styles.css';

After (with default config)

// Types
import type { User } from '@/types/user';
import type { Config } from './config';

// External Libraries
import { useState } from 'react';
import axios from 'axios';

// Internal Modules
import { Button } from '@/components/Button';

// Relative Imports
import './styles.css';

Features

Fully Configurable: Define your own categories, patterns, and ordering
Flexible Patterns: Use RegExp for matching import paths
Type Imports Support: Separate category for import type statements
Comment Style Options: Support for both line (//) and block (/* */) comments
Optional Enforcement: Disable order or comment checks independently
Auto-Fix: Automatically add missing comments and remove duplicates
TypeScript First: Built with TypeScript for type safety

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Support

If you encounter any issues, please report them at GitHub Issues](https://github.com/mjhashemian/eslint-plugin-import-category/issues).