0.3.4 • Published 1 year ago

@technote-space/eslint-plugin-strict-dependencies v0.3.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

eslint-plugin-strict-dependencies

ESlint plugin to define custom module dependency rules.

NOTE: eslint-plugin-strict-dependencies uses tsconfig, tsconfig.json must be present.

Table of Contents

Installation

npm install @technote-space/eslint-plugin-strict-dependencies --save-dev

Supported Rules

  • strict-dependencies
    • module: string (Glob or Forward matching string)
      • target module path
    • allowReferenceFrom: string[] (Glob or Forward matching string)
      • Paths of files where target module imports are allowed.
    • allowSameModule: boolean
      • Whether it can be imported by other files in the same directory
    • allowTypeImport: boolean
      • Whether to allow type import

Options

  • resolveRelativeImport: boolean[default = false]
    • Whether to resolve relative import as in the following example
    • src/components/aaa.ts
      import bbb from './bbb';
      • ./bbb: resolveRelativeImport = false
      • src/components/bbb: resolveRelativeImport = true
  • allowTypeImport: boolean
    • Whether to allow type import

Usage

.eslintrc:

"plugins": [
  "@technote-space/strict-dependencies",
],
"rules": {
  "@technote-space/strict-dependencies/strict-dependencies": [
    "error",
    [
      /**
       * Example:
       * Limit the dependencies in the following directions
       * pages -> components/page -> components/ui
       */
      {
        "module": "src/components/page",
        "allowReferenceFrom": ["src/pages"],
        // components/page can't import other components/page
        "allowSameModule": false,
        "allowTypeImport": true
      },
      {
        "module": "src/components/ui",
        "allowReferenceFrom": ["src/components/page"],
        // components/ui can import other components/ui
        "allowSameModule": true
      },

      /**
       * example:
       * Disallow to import `next/router` directly. it should always be imported using `libs/router.ts`.
       */
      {
        "module": "next/router",
        "allowReferenceFrom": ["src/libs/router.ts"],
        "allowSameModule": false
      },
    ],
    // options
    // {
    //   "resolveRelativeImport": true,
    //   "allowTypeImport": true
    // }
  ]
}

License

MIT

0.3.4

1 year ago

0.3.2

1 year ago

0.3.3

1 year ago

0.3.1

1 year ago

0.3.0

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.3

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.2

2 years ago

0.1.0

3 years ago