Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
azinit opened this issue Dec 4, 2021 · 2 comments
Open
2 tasks

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

azinit opened this issue Dec 4, 2021 · 2 comments
Labels
help wanted Extra attention is needed
Milestone

Comments

@azinit
Copy link
Member

azinit commented Dec 4, 2021

Glossary

  • "External module" - entity/foo <-> entity/bar, entity/foo <-> shared/ui/button
  • "Internal module" - entity/foo <-> entity/foo/ui, entity/foo/ui/smth <-> entitiy/foo/lib

Description

  • Restrict relative imports for external modules (enforce for internalmodules)
  • Restrict absolute imports for internalmodules (enforce for external modules)

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

feature-sliced/documentation#52 (reply in thread)

@azinit azinit added the on-hold label Dec 11, 2021
@azinit azinit added this to the 0.2.X milestone Dec 12, 2021
@azinit azinit changed the title LINT: Public API boundaries (restrict-relative) LINT: (Public API) Add semantic-imports rule Feb 2, 2022
@azinit azinit added help wanted Extra attention is needed and removed on-hold labels Feb 2, 2022
@SimeonC
Copy link

SimeonC commented May 31, 2023

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
Copy link
Member Author

azinit commented May 31, 2023

@SimeonC Thanks! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants