Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-conarti-fsd

conarti369ISC0.0.39

Feature-sliced design methodology plugin

eslint, eslintplugin, eslint-plugin, feature-sliced, feature-slices, feature-driven, feature-based

readme

eslint-plugin-conarti-fsd

Feature-sliced design methodology plugin.

Attention: the plugin is being actively developed and is in beta. The names of rules and configurations may change in new versions. If you find a bug, please open an issue or pull request. Feel free to contribute

Features

  • Works with any framework

  • Support for any aliases out of the box

import { AppButton } from "~/shared/ui/app-button";
import { AppButton } from "@/shared/ui/app-button";
import { AppButton } from "@shared/ui/app-button";
import { AppButton } from "$shared/ui/app-button";
import { AppButton } from "$@#$%%shared/ui/app-button";
  • Checks for absolute and relative paths
// file: src/widgets/TheHeader/ui/TheHeader.stories.tsx

import { TheHeader } from './TheHeader'; // valid
import { TheHeader } from 'src/widgets/TheHeader'; // error: should relative
import { TheHeader } from 'widgets/TheHeader'; // error: should relative
import { useBar } from '../../../shared/hooks'; // error: should absolute
  • Checks for imports from public api and fix them
// file: src/features/search-articles/...

import { addCommentFormActions, addCommentFormReducer } from 'entities/Article/model/file.ts'; // error
// fix: import { addCommentFormActions, addCommentFormReducer } from 'entities/Article';
  • Sort imports
import axios from "axios";                           // 1) external libs
import { Header } from "widgets/header";             // 2.1) Layers: widgets
import { Zero } from "widgets/zero";                 // 2.1) Layers: widget 
import { LoginForm } from "features/login-form";     // 2.2) Layers: features
import { globalEntities } from "entities";           // 2.4) Layers: entities
import { authModel } from "entities/auth";           // 2.4) Layers: entities
import { Cart } from "entities/cart";                // 2.4) Layers: entities 
import { One } from "entities/one";                  // 2.4) Layers: entities 
import { Two } from "entities/two";                  // 2.4) Layers: entities
import { debounce } from "shared/lib/fp";            // 2.5) Layers: shared
import { Button } from "shared/ui";                  // 2.5) Layers: shared
import { Input } from "shared/ui";                   // 2.5) Layers: shared
import { data } from "../fixtures";                  // 3) parent
import { getSmth } from "./lib";                     // 4) sibling

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-conarti-fsd and dependencies:

npm install -D eslint-plugin-conarti-fsd eslint-plugin-import
# or by yarn
yarn add -D eslint-plugin-conarti-fsd eslint-plugin-import

Usage

Add conarti-fsd to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

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

Then enable rules:

{
  "extends": [
    "plugin:conarti-fsd/recommended"
  ]
}

Customization

You can use warnings instead of errors for specific rules. Or turn off certain rules:

{
  "rules": {
    "conarti-fsd/layers-slices": "warn",
    "conarti-fsd/absolute-relative": "off",
    "conarti-fsd/public-api": "warn",
    "import/order": "warn"
  }
}

If you don't want to use the 'import/order' rule, you can choose not to install the 'eslint-plugin-import' package. And also you will have to configure all the rules separately, without using the config. Recommended settings:

{
  "rules": {
    "conarti-fsd/layers-slices": ["error", { 
      "allowTypeImports": true
    }],
    "conarti-fsd/absolute-relative": "error",
    "conarti-fsd/public-api": "error"
  }
}

Rules

🔧 Automatically fixable by the --fix CLI option. 💡 Suggestion fix (no automatic fix)

Name Description 🔧
conarti-fsd/layers-slices Checks layer imports
conarti-fsd/absolute-relative Checks for absolute and relative paths
conarti-fsd/public-api Check for module imports from public api 💡
import/order Sort imports using 'eslint-plugin-import' 🔧

changelog

0.0.39 (2023-05-28)

Bug Fixes

  • layers-slices: remove import path normalization to check if it is ignored (6569e75)
  • import-order: error when using 'recommended' config without 'eslint-plugin-import' package installed (now the rule simply won't work, and you can always use 'recommended' config) (8f3dfa7)

Features

  • absolute-relative: improve logic for getting layer and slice from paths (now understands relative paths) (c6d264a)
  • public-api: add the option which adjust the level of validation (ab6b7e5), closes #5

0.0.38 (2023-05-11)

Features

  • public-api: validate 'export ... from ...' syntax (db343f4)

0.0.37 (2023-05-08)

Bug Fixes

  • import-order: cycle fsd imports errors bug (f0107ed)

0.0.36 (2023-05-03)

Features

  • absolute-relative: add 'ignoreInFilesPatterns' options for ignoring validations in files by patterns (ec87cd1)

0.0.35 (2023-04-30)

Bug Fixes

  • public-api: incorrect working if segment files has segment-like naming (4e7cade)

0.0.34 (2023-04-30)

Bug Fixes

  • layers-slices: incorrect work with 'layers-like' names at not layer path part (d13544b)

Features

  • layers-slices: allow imports inside 'app' layer (a2cc503)

0.0.33 (2023-04-30)

Bug Fixes

  • layers-slices: correctly understand layers from paths if usual folder names is same as layer names (0.0.33)

0.0.32 (2023-04-17)

Bug Fixes

  • public-api: incorrect getting slices from the path (5876679)
  • public-api: incorrect validation imports from 'index' files (a335984)
  • public-api: incorrect validation within same segment (61425a4)

0.0.31 (2023-04-16)

Bug Fixes

  • public-api: working with file extension if import was from segment (64ac21c)

Features

  • absolute-relative: validate in import expressions (d0e82f0)
  • layers-slices: validate in import expressions (de3971b)
  • public-api: validate in import expressions (c439acc)

0.0.30 (2023-04-16)

Bug Fixes

  • public-api: don't replace quotes style to single after fix invalid paths (5881993)

0.0.29 (2023-04-16)

Features

  • convert-to-absolute: add work with absolute target path (b36fb06)
  • public-api: add relative path validation (af2a104)
  • public-api: validate relative paths (93e287c)

0.0.28 (2023-04-09)

Bug Fixes

  • incorrect working with windows paths (7efc4c5)
  • set rules meta type to 'problem' (89c7fdd)

0.0.27 (2023-04-04)

Reverts

  • Revert "refactor(configs): extract 'base' config from 'recommended'" (c7f7bd9)
  • Revert "refactor(import-order): move to 'configs'" (8ef7228)

0.0.26 (2023-04-04)

Bug Fixes

  • incorrect handling of windows paths (f4d8877)
  • public-api: validation with sub-grouping folders (675546e)

0.0.25 (2023-03-29)

Bug Fixes

  • public-api: validation with grouping folders (88d282a)
  • public-api: working with paths in 'kebab-case' (1a73850)

0.0.24 (2023-03-06)

Bug Fixes

  • absolute-relative: error when validating exported values (not re-exports) (36a9b77)

0.0.23 (2023-03-06)

Features

  • absolute-relative: export validation (d4243e2)

0.0.22 (2023-03-06)

Bug Fixes

  • get-layer-slice-from-path: correction of work with segment names (741bfa3)

Features

  • get-layer-slice-from-path: case insensitive (7b81eed)

0.0.21 (2023-03-06)

Bug Fixes

  • normalize-path: do not delete '.' (ae463bb)

0.0.20 (2023-03-06)

Bug Fixes

  • get-layer-slice-from-path: working with kebab-case paths (9d61320)

Features

  • helpers: add convert-to-absolute helper (2d93396)
  • layers-slices: validate relative paths (1b153ab)

0.0.19 (2023-03-04)

  • feat(public-api-imports)!: rename rule to 'public-api' (fb6b6d3)

Features

  • public-api-imports: change rule fix to suggestion (f0489f3)
  • public-api: add fixed path to error message (4fddcde)

BREAKING CHANGES

  • the name of the rule has been changed, you need to rename it in your eslint configs

0.0.18 (2023-03-03)

Bug Fixes

  • layers-slices: remove extra '>' (70a219b)
  • feat(path-checker)!: rename rule to 'absolute-relative' (68ce50a)

Features

  • import-order: add padding and separate type imports (fb36189)
  • layers-slices: update error message (3787909)
  • rules: show rule errors over paths instead 'import' (74e2b79)

BREAKING CHANGES

  • the name of the rule has been changed, you need to rename it in your eslint configs

0.0.17 (2023-03-03)

Bug Fixes

  • layer-imports: add 'processes' layer to error message (11cbf93)
  • feat(layer-imports)!: rename rule 'layer-imports' to 'layers-slices' (b732ec1)

Features

  • layer-imports: don't throw an error when importing from the same slice (28a002f)

BREAKING CHANGES

  • the name of the rule has been changed, you need to rename it in your eslint configs

0.0.16 (2023-02-22)

Features

  • layer-imports: add functionality for ignoring by patterns (751e86c)

0.0.15 (2023-02-21)

Bug Fixes

  • path-checker: imports inside 'app' and 'shared' should be relative (5ebb65d)
  • path-checker: update message for relative path errors (4aeea52)

Features

  • configs: set 'all' config as 'recommended', enable 'allowTypeImports' by default (e2f800d)
  • layer-imports: add a setting to disable checking for type imports (8605f58)

0.0.14 (2023-02-12)

Bug Fixes

  • path-checker: shouldBeRelative - don't error for imports from another layer (aad40c0)

0.0.13 (2023-02-12)

Bug Fixes

  • get-layer-slice-from-path: don't find a file as a slice (1de7f4b)
  • layer-imports: allow imports from same layer for '{layer}/{file}' pattern (f00cdaf)

Features

  • path-checker: error if should relative import at files like {layer}/{filename} pattern (e34ff41)

0.0.12 (2023-02-12)

Bug Fixes

  • public-api-imports: don't check imports from 'shared' (2e0801b)

0.0.11 (2023-02-12)

Bug Fixes

  • layer-imports: disable imports from one layer except 'shared', correct validation mistakes, 'canNotImportLayer' -> 'canImportLayer' (5623b69)

Features

  • get-layer-slice-from-path: rename from 'getPathParts', fix implementation (72c543f)
  • layer-imports: implementation without 'alias' option (db41630)
  • normalize-path: don't remove aliases (5e00cae)
  • normalizePath: automatic detection of aliases and their removal from the path (c8ff1b2)
  • path-checker: checks 'should be absolute' (6510e71)
  • path-checker: implementation without 'alias' option (5ba3dac)
  • public-api-imports: automatically detect aliases in the path (be743b8)
  • public-api-imports: new implementation with auto-detect aliases and working with any paths (1b3e2ad)

Reverts

  • add 'getByRegExp' and 'getAlias' to helpers public api (e71f8aa)

0.0.10 (2023-01-17)

Features

  • import-order: disable rule for imports from the same slice (90668ac)

Reverts

  • Revert "refactor(layer-imports): change function canNotImportLayer to canImportLayer, move to global helpers" (284ca0c)

0.0.9 (2023-01-16)

Features

  • import-order: throw errors when has lines between groups (38a5420)

0.0.8-beta1 (2023-01-16)

Features

0.0.8 (2023-01-16)

Features

  • setup import-order rule, update docs (b333104)

0.0.7 (2023-01-06)

Bug Fixes

  • public-api-imports: disable for 'app' imports (b5032e9)

Features

  • add public-api-imports rule (5c1cfe3)
  • path-checker: add alias implementation (d7d1f13)
  • public-api-imports: add auto fix for rule (7889f73)
  • rules: setup 'layer-imports' rule (ec86bd3)