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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@marqhq/eslint-plugin-shortest-import

v1.1.0

Published

ESLint plugin to prefer the shortest import path (relative vs alias)

Readme

eslint-plugin-shortest-import

ESLint plugin to prefer the shortest import path, automatically choosing between relative imports and TypeScript path aliases based on which one results in fewer path segments.

Installation

npm install @marqhq/eslint-plugin-shortest-import --save-dev

Usage

ESLint Flat Config (eslint.config.js)

import shortestImport from "@marqhq/eslint-plugin-shortest-import";

export default [
  {
    plugins: {
      "@marqhq/shortest-import": shortestImport,
    },
    rules: {
      "@marqhq/shortest-import/shortest-import": "warn",
    },
  },
];

Legacy ESLint Config (.eslintrc)

{
  "plugins": ["@marqhq/shortest-import"],
  "rules": {
    "@marqhq/shortest-import/shortest-import": "warn"
  }
}

Rule Options

"@marqhq/shortest-import/shortest-import": ["warn", {
  "tsconfigPath": "./tsconfig.json", // Optional: path to tsconfig.json
  "preferOnTie": "alias" // Optional: "alias" | "relative" | "keep" (default: "keep")
}]

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | tsconfigPath | string | ./tsconfig.json | Path to your tsconfig.json file | | preferOnTie | "alias" | "relative" | "keep" | "keep" | What to prefer when segment counts are equal |

  • "alias" - On tie, convert to the tsconfig path alias
  • "relative" - On tie, convert to the relative import
  • "keep" - On tie, keep the current import style (default)

How It Works

The rule compares the "segment count" of import paths:

  • ./Button = 1 segment
  • ../utils/helpers = 3 segments (.., utils, helpers)
  • @components/Button = 2 segments (@components, Button)
  • @/components/Button = 3 segments (@, components, Button)

The rule suggests switching to whichever form has fewer segments.

Examples

Given this tsconfig.json:

{
  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "@/*": ["./*"],
      "@components/*": ["./components/*"],
      "@utils/*": ["./utils/*"]
    }
  }
}

Relative to Alias (when alias is shorter)

// File: src/features/auth/login.ts

// Bad - 4 segments
import { Button } from "../../components/Button";

// Good - 2 segments
import { Button } from "@components/Button";

Alias to Relative (when relative is shorter)

// File: src/components/App.ts

// Bad - 3 segments
import { Button } from "@/components/Button";

// Good - 1 segment
import { Button } from "./Button";

Auto-fix

This rule supports ESLint's --fix option to automatically convert imports to the shorter form.

eslint --fix src/

Requirements

  • ESLint >= 8.0.0
  • TypeScript >= 4.0.0
  • A tsconfig.json with paths configured

Development

Setup

npm install
npm run build
npm test

Releasing

To publish a new version:

  1. Update the version in package.json
  2. Commit the change: git commit -am "Bump version to x.x.x"
  3. Create and push a tag: git tag vx.x.x && git push origin vx.x.x
  4. Create a GitHub release: gh release create vx.x.x --title "vx.x.x" --notes "Release notes here"

The GitHub Action will automatically build, test, and publish to GitHub Packages.

License

MIT