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 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-wizardry-fsd

v0.2.0

Published

Plugin for checking imports path in FSD project

Downloads

25

Readme

eslint-plugin-wizardry-fsd

WIP: Use with caution, the project may not be properly tested.

Plugin for checking import paths in FSD project.

Table of Contents:

Installation

npm i -D eslint eslint-plugin-wizardy-fsd

Supported Rules

  • slice-relative-path

    Imports within one slice should be relative.

    // .
    // └── 📂src/
    //     └── 📂features/                   # FSD layer
    //         └── 📂your-cool-feature/      # FSD slice
    //             ├── 📃file1.ts
    //             └── 📃file2.ts
    
    // file: src/features/your-cool-feature/file1
    
    // Examples of incorrect code for this rule:
    import { CoolFeature } from '~/features/your-cool-feature';
    import { CoolFeature } from '@/features/your-cool-feature';
    import { CoolFeature } from '@features/your-cool-feature';
    import { CoolFeature } from '$features/your-cool-feature';
    import { CoolFeature } from 'features/your-cool-feature';
    
    // Examples of correct code for this rule:
    import { CoolFeature } from '.file2';
  • public-api-imports

    Absolute imports should be only from public API.

    // .
    // └── 📂src/
    //     ├── 📂features/                   # FSD layer
    //     │   └── 📂your-cool-feature/      # FSD slice
    //     │       ├── 📃file1.ts
    //     │       └── 📃file2.ts
    //     └── 📂entities/                   # FSD layer
    //         └── 📂your-important-entity/  # FSD slice
    //             ├── 📂model/
    //             │   └── 📃file3.ts
    //             └── 📃index.ts
    
    // file: src/features/your-cool-feature/file1
    
    // Examples of incorrect code for this rule:
    import { ImportantEntity } from 'entities/your-important-entity/model/file3';
    
    // Examples of correct code for this rule:
    import { ImportantEntity } from 'entities/your-important-entity';
    
    // Output
    // Absolute import is allowed only from public API (index.ts) https://feature-sliced.design/docs/reference/public-api
  • layer-imports

    Modules on one layer can only interact with modules from the layers strictly below.

    // .
    // └── 📂src/
    //     ├── 📂features/                   # FSD layer
    //     │   └── 📂your-cool-feature/      # FSD slice
    //     │       ├── 📃file1.ts
    //     │       └── 📃file2.ts
    //     │       └── 📃index.ts
    //     └── 📂entities/                   # FSD layer
    //         └── 📂your-important-entity/  # FSD slice
    //             ├── 📃file3.ts
    //             └── 📃index.ts
    
    // file: src/entities/your-important-entity/file3
    
    // Examples of incorrect code for this rule:
    import { CoolFeature } from 'features/your-cool-feature/model';
    
    // Output:
    // Entities layer can import only below layers: (shared) https://feature-sliced.design/docs/reference/layers
  • complex (recommended)

    All rules above are executed in a single thread, which provides more accurate problem definition.

    // .
    // └── 📂src/
    //     └── 📂features/                   # FSD layer
    //         └── 📂your-cool-feature/      # FSD slice
    //             ├── 📃file1.ts
    //             └── 📃file2.ts
    
    // file: src/features/your-cool-feature/file2
    import { File1 } from 'features/your-cool-feature/file1';
    
    // Output if you use the rules separately:
    
    // Within one slice all paths should be relative                                                                                        wizardry-fsd/slice-relative-path
    // Views layer can import only below layers: (widgets, features, entities, shared) https://feature-sliced.design/docs/reference/layers  wizardry-fsd/layer-imports
    // Absolute import is allowed only from public API (index.ts) https://feature-sliced.design/docs/reference/public-api                   wizardry-fsd/public-api-imports
    
    // Output if you use complex rule:
    // Within one slice all paths should be relative  wizardry-fsd/complex

Rules options

Common options for all rules

  • pagesFolderRename Useful when we can't use the default folder name for example due to framework limitations like in Next.js
    Default: "pages"
    {
      "rules": {
        "wizardry-fsd/layer-imports": [
          "error",
          {
            "pagesFolderRename": "views"
          }
        ]
      }
    }

layer-imports options

  • entitiesCrossImport Allows you to import an entity into another entity.
    Default: false
    {
      "rules": {
        "wizardry-fsd/layer-imports": [
          "error",
          {
            "entitiesCrossImport": true
          }
        ]
      }
    }
  • ignoreImportPatterns Array of glob path templates to ignore of rule.
    Default: [ ]
    {
      "rules": {
        "wizardry-fsd/layer-imports": [
          "error",
          {
            "ignoreImportPatterns": ["**/StoreProvider", "**/*.test.*"]
          }
        ]
      }
    }

public-api-imports options

  • sharedImportFromAny Allows you to import from shared as you want, not just from the public api.
    Default: false
    {
      "rules": {
        "wizardry-fsd/public-api-imports": [
          "error",
          {
            "sharedImportFromAny": true
          }
        ]
      }
    }

⚠️ You can use all above rules without duplications in wizardry-fsd/complex

{
  "rules": {
    "wizardry-fsd/complex": [
      "error",
      {
        "pagesFolderRename": "views",
        "entitiesCrossImport": true,
        "sharedImportFromAny": true,
        "ignoreImportPatterns": ["**/StoreProvider", "**/*.test.*"]
      }
    ]
  }
}

Setup

Automatic

To use pre-built configurations, you need to add one of the following line to extends:

  • default
    {
      "extends": ["plugin:wizardry-fsd/default"]
    }
    which is similar to the following:
    {
      "plugins": ["wizardry-fsd"],
      "rules": {
        "wizardry-fsd/complex": [
          "error",
          {
            "sharedImportFromAny": true
          }
        ]
      }
    }
  • next
    {
      "extends": ["plugin:wizardry-fsd/next"]
    }
    which is similar to the following:
    {
      "plugins": ["wizardry-fsd"],
      "rules": {
        "wizardry-fsd/complex": [
          "error",
          {
            "pagesFolderRename": "views",
            "sharedImportFromAny": true
          }
        ]
      }
    }

Manual

Add wizardy-fsd to the plugins section of your .eslintrc configuration file:

{
  "plugins": ["wizardy-fsd"]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "wizardry-fsd/slice-relative-path": [
      "error",
      {
        "pagesFolderRename": "views"
      }
    ],
    "wizardry-fsd/layer-imports": [
      "error",
      {
        "pagesFolderRename": "views",
        "ignoreImportPatterns": ["**/StoreProvider", "**/*.test.*"],
        "entitiesCrossImport": true
      }
    ],
    "wizardry-fsd/public-api-imports": [
      "error",
      {
        "pagesFolderRename": "views",
        "sharedImportFromAny": true
      }
    ]
  }
}