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-no-relative-import

v1.0.2

Published

ESLint plugin to replace relative imports with tsconfig path aliases

Readme

eslint-plugin-no-relative-import

ESLint plugin to replace relative imports (./, ../) with TypeScript path aliases from the nearest tsconfig.json.

What it does

Transforms relative imports into clean, maintainable path aliases:

// Before
import { helper } from "../../../utils/helper";
import { Button } from "../components/Button";

// After (auto-fix)
import { helper } from "@/utils/helper";
import { Button } from "@/components/Button";

Features

  • Auto-fixable — run eslint --fix to convert all relative imports automatically
  • tsconfig-aware — reads compilerOptions.paths and baseUrl from the nearest tsconfig.json
  • Extends support — resolves extends chains in tsconfig
  • Monorepo-friendly — each package uses its own tsconfig
  • Manual aliases — works without tsconfig via rule options
  • Granular control — allowlist, ignore patterns, sibling import toggle

Supported import types

  • import { x } from "../thing"
  • export { x } from "../thing"
  • export * from "../thing"
  • await import("../thing")
  • require("../thing")

Installation

npm install --save-dev eslint-plugin-no-relative-import

Usage

ESLint Flat Config (v9+)

// eslint.config.js
import noRelativeImport from "eslint-plugin-no-relative-import";

export default [
  {
    plugins: {
      "no-relative-import": noRelativeImport,
    },
    rules: {
      "no-relative-import/no-relative-import": "error",
    },
  },
];

ESLint Legacy Config (v8)

// .eslintrc.js
module.exports = {
  plugins: ["no-relative-import"],
  rules: {
    "no-relative-import/no-relative-import": "error",
  },
};

Recommended preset

// eslint.config.js
import noRelativeImport from "eslint-plugin-no-relative-import";

export default [
  noRelativeImport.configs.recommended,
];

Oxlint

Oxlint supports ESLint v9+ compatible plugins via jsPlugins. Add to .oxlintrc.json:

{
  "jsPlugins": ["eslint-plugin-no-relative-import"],
  "rules": {
    "no-relative-import/no-relative-import": "error"
  }
}

The plugin must be installed in your project (npm install --save-dev eslint-plugin-no-relative-import). Oxlint resolves the plugin name relative to the config file.

Note: jsPlugins support is alpha in Oxlint. The plugins field is for native Oxlint plugins only — ESLint plugins go in jsPlugins.

Configuration

Rule options

"no-relative-import/no-relative-import": ["error", {
  // Manual aliases (when no tsconfig or to augment it)
  alias: {
    "@/*": "./src/*",
    "@components/*": "./src/components/*",
  },

  // Relative paths that are allowed (supports * wildcard)
  allowRelative: ["./styles.css", "../assets/*"],

  // Whether to convert sibling imports like "./foo". Default: true
  includeSiblingImports: false,

  // Import paths to ignore entirely (supports * wildcard)
  ignorePatterns: ["*.css", "*.graphql"],

  // Override working directory for tsconfig lookup and alias resolution
  cwd: "/path/to/project",
}]

Example: disable sibling imports

Keep ./ imports for co-located files, only fix ../:

rules: {
  "no-relative-import/no-relative-import": ["error", {
    includeSiblingImports: false,
  }],
}

Example: allow specific patterns

rules: {
  "no-relative-import/no-relative-import": ["error", {
    allowRelative: ["./styles", "../types/*"],
  }],
}

Example: manual aliases without tsconfig

rules: {
  "no-relative-import/no-relative-import": ["error", {
    alias: {
      "@": "./src",
      "@lib/*": "./lib/*",
    },
  }],
}

How it works

  1. Finds the nearest tsconfig.json for each linted file
  2. Reads compilerOptions.paths and compilerOptions.baseUrl
  3. Resolves extends chains in tsconfig
  4. When a relative import can be replaced by a path alias, reports it with an auto-fix
  5. Picks the most specific alias when multiple match

tsconfig example

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

Requirements

  • Node.js 18+
  • ESLint 8.57+ or 9+
  • TypeScript project (for automatic tsconfig discovery)

License

MIT