feature-sliced / eslint-config

🍰 Lint feature-sliced concepts by existing eslint plugins
https://npmjs.com/@feature-sliced/eslint-config
MIT License
120 stars 5 forks source link

LINT: (Public API) Add `semantic-imports` rule #29

Open azinit opened 2 years ago

azinit commented 2 years ago

Glossary

Description

Example

// Fail 👎 
// @path features/baz/model/index.ts
import { ... } from "../../bar" // Sibling feature-slice
import { ... } from "@/features/baz/model/smth" // Invalid access to internal resource as external module
// Pass 👍 
// @path features/baz/model/index.ts
import { ... } from "../lib" // Import of internal module as internal resource - no illegal
import { ... } from "../entities/foo" // Lower layer slice - no illegal
import { ... } from "@entities/foo" // Import as external module
import { ... } from "shared/ui/button" // Import as external module

Reference

https://github.com/feature-sliced/documentation/discussions/52#discussioncomment-477443

SimeonC commented 1 year ago

I built something a bit similar for my company's custom eslint-plugin, mine is a typescript specific plugin but you can probably adapt the code to build this check. https://github.com/tablecheck/tablecheck-react-system/blob/refactor-to-vite-and-typescript/packages/eslint-plugin/src/shortestImport.ts

azinit commented 1 year ago

@SimeonC Thanks! ❤️