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-dependency-relation

v0.1.5

Published

Import relation linting rule for ESLint.

Readme

eslint-plugin-dependency-relation

Import relation linting rule for ESLint.
beta-version, testing now.

Can use this in.

  • JavaScript Project
  • TypeScript Project
  • React Project
  • Vue Project

Motivation

The import relation is difficult to have being clean, because many developers join in development and every member don't necessarily know a lot about implicit import relation rules. Hence, even if you DID think of what is the best architect at beginning, someone will break the great rules one day, then someone who see it will also break rule, then someone..... ultimately import relation will become very complex like below.

relation

Since we're human, we have no choice. Instead, lets' use this eslint-plugin😀.

This plugin protects the great rule you thought of, like below.

// @dependency-relation: allow: ../app.js
export function moduleA() {
  
}

This comment means this module is able to be imported just only from ../app.js file, so if you try to import moduleA from any place besides the file(../app.js), this plugin will get mad at you and inform broken the great rule.

import path ../../moduleA is not allowed from this file  dependency-relation/import

Installation

Install ESLint before using this plugin, please. To make sure how to install eslint, please visit eslint page

yarn add eslint-plugin-dependency-relation -D

or

npm install eslint-plugin-dependency-relation -D

Configuration

  • for js Project
  • for ts Project(including React Project)
  • for vue project

for js project

You can use this plugin by adding below info to .eslintrc.

{
  "plugins": ["dependency-relation"],
  "extends": ["plugin:dependency-relation/presetJs"]
}

for ts project

If you'd like this plugin in ts project, need to install @typescript-eslint/parser.

yarn add -D typescript @typescript-eslint/parser

or

npm i --save-dev typescript @typescript-eslint/parser

You can use this plugin by adding below properties to .eslintrc.

{
  "plugins": ["dependency-relation"],
  "extends": ["plugin:dependency-relation/preset"]
}

If you'd like to do manual configuration, please see Manual Configuration(ts) section.

for vue project

If you'd like this plugin in your vue project. You need to add some properties to .eslintrc like this.

{
  "plugins": ["dependency-relation"],
  "extends": [
    "@vue/typescript/recommended",
    "plugin:dependency-relation/presetVue"
  ]
}

Rules

import

To make sure details, please see this doc. import is the rule to limit importing file from a lot of location.

Let's say there are two directories and three files.

┝ app.ts
┝ repository
│  └ index.ts
└ infrastracture
    ┝ index.ts
    └ mysql.ts

In addition, let's say there are other rules you want to limit.

example

  1. don't allow accessing infrastracture directory besides repository directory
  2. don't allow direct accessing mysql.ts. (e.g import {save} from './infrastracture/mysql'). Instead, allow accessing mysql module via index.ts

write rule

At first let's write rule, but all thing I'll introduce you are just only basic rule.

To achieve rule 1 and rule2, we need to write comment in infrastructure/index.ts.

// @dependency-relation: allowOnly@root: ../repository

We're using allonOnly@root options in this example. This rule means

  • This directory's files arn't able to be imported except index file(index.ts)
  • This directory's files arn't able to be imported except ../repository dir.

Hence, it's oke to just only write this comment (it may be better to write comment in repository).

I have a few useful option which has a lot of behaviors, please see details details

require

This rule is as same as import, but this rule expect requireSyntax instead of import.

Manual Configuration(ts)

In order to set up manually, it's better to write it in your .eslintrc. Note: If you use preset, don't need this section.

{
    "settings": {
        "import/resolver": {
          "node": {
            "extensions": [".ts", ".tsx", ".js", ".jsx"]
          }
        },
      "rules": {
        "dependency-relation/import": 2,
        "dependency-relation/require": 2
      }
    } 
}

In addition, if you'd like to ignore test directories from this plugin. It's better to use ignorePatterns like below.

Note: At default, *.spec.* or *.test.* file will be ignored by this plugin.

{
  "ignorePatterns": ["tests/*spec.js"],
  "rules": {
    "dependency-relation/import": 0,
    "dependency-relation/require": 0
  }
}