eslint-config

eslint-config

Feature Sliced架构专用ESLint配置工具

@feature-sliced/eslint-config是专为Feature Sliced架构开发的ESLint配置包。该工具利用现有ESLint插件,实现对代码隔离性、模块分解、公共API、层级范围和命名规范的控制。配置支持别名、相对和绝对导入,且大小写不敏感。开发者可根据项目需求自定义配置,如选择性使用规则、采用实验性规则或调整警告级别。

Feature-SlicedESLint前端架构代码规范模块化Github开源项目

@feature-sliced/eslint-config

WIP: 目前处于beta测试阶段 - 请谨慎使用

npm npm npm bundle size GitHub Workflow Status

<img src="https://avatars.githubusercontent.com/u/60469024?s=120&v=4" align="right">

通过现有的eslint插件对FeatureSliced概念进行lint

规则

每个规则都有自己的测试用例和定制方面

开始使用

  1. 首先需要安装ESLint:

    $ npm install -D eslint # 或者使用yarn $ yarn add -D eslint
  2. 接下来,安装@feature-sliced/eslint-config和依赖项:

    $ npm install -D @feature-sliced/eslint-config eslint-plugin-import eslint-plugin-boundaries # 或者使用yarn $ yarn add -D @feature-sliced/eslint-config eslint-plugin-import eslint-plugin-boundaries
  3. .eslintrc配置文件的extends部分添加配置(用于推荐规则)。你可以省略eslint-config后缀:

    { "extends": ["@feature-sliced"] }
  4. 仅限TypeScript: 还需要设置TS解析器和TS插件(原因?)

    <details> <summary>详情</summary>

    安装依赖:

    $ npm i -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-import-resolver-typescript # 或者使用yarn $ yarn add -D @typescript-eslint/eslint-plugin @typescript-eslint/parser eslint-import-resolver-typescript

    .eslintrc配置文件中将@typescript-eslint/parser配置为解析器,并设置eslint-import-resolver-typescript解析器:

    { "parser": "@typescript-eslint/parser", "settings": { "import/resolver": { "typescript": { "alwaysTryTypes": true } } } }
    </details>

使用方法

  • 支持常见的别名

    import { Input } from "~/shared/ui/input"; import { Input } from "@/shared/ui/input"; import { Input } from "@shared/ui/input"; import { Input } from "$shared/ui/input"; // 但不支持 - import { Input } from "$UIKit/input";
  • 支持相对绝对导入(但请查看建议

    import { ... } from "entities/foo"; // 绝对导入 import { ... } from "@/entities/foo"; // 别名导入 import { ... } from "../entities/foo"; // 相对导入
  • 大小写不敏感

    import { ... } from "entities/user-post"; // 支持kebab-case(推荐) import { ... } from "entities/UserPost"; // 支持PascalCase import { ... } from "entities/userPost"; // 支持camelCase import { ... } from "entities/user_post"; // 支持snake_case
  • 对于特殊情况,支持⚠️危险模式⚠️(查看特定规则了解更多)

自定义

  1. 你可以部分使用规则

    警告: 在自定义时不要使用主配置("@feature-sliced")以避免规则冲突。

    "extends": [ "@feature-sliced/eslint-config/rules/import-order", "@feature-sliced/eslint-config/rules/public-api", "@feature-sliced/eslint-config/rules/layers-slices", ]
  2. 你可以使用替代性实验规则

    • 使用import-order/experimental来格式化组之间的空格和反转层级顺序(原因?)

      "extends": [ // ... 其他规则或配置 "@feature-sliced/eslint-config/rules/import-order/experimental", ]
    • 使用public-api/lite来减少PublicAPI边界的严格程度(原因?)

      "extends": [ // ... 其他规则或配置 "@feature-sliced/eslint-config/rules/public-api/lite", ]
  3. 你可以对特定规则使用警告而不是错误

    "rules": { // feature-sliced/import-order "import/order": "warn" // ~ 1, // feature-sliced/public-api "import/no-internal-modules": "warn" // ~ 1, // feature-sliced/layers-slices "boundaries/element-types": "warn" // ~ 1, }
  4. 你可以使用*高级FSD特定消息处理*

    # (feature-sliced/public-api) - '不允许访问 "features/search/ui"。' + '违反了模块公共API的使用规则 | https://git.io/Jymjf'

另请参阅

编辑推荐精选

音述AI

音述AI

全球首个AI音乐社区

音述AI是全球首个AI音乐社区,致力让每个人都能用音乐表达自我。音述AI提供零门槛AI创作工具,独创GETI法则帮助用户精准定义音乐风格,AI润色功能支持自动优化作品质感。音述AI支持交流讨论、二次创作与价值变现。针对中文用户的语言习惯与文化背景进行专门优化,支持国风融合、C-pop等本土音乐标签,让技术更好地承载人文表达。

QoderWork

QoderWork

阿里Qoder团队推出的桌面端AI智能体

QoderWork 是阿里推出的本地优先桌面 AI 智能体,适配 macOS14+/Windows10+,以自然语言交互实现文件管理、数据分析、AI 视觉生成、浏览器自动化等办公任务,自主拆解执行复杂工作流,数据本地运行零上传,技能市场可无限扩展,是高效的 Agentic 生产力办公助手。

lynote.ai

lynote.ai

一站式搞定所有学习需求

不再被海量信息淹没,开始真正理解知识。Lynote 可摘要 YouTube 视频、PDF、文章等内容。即时创建笔记,检测 AI 内容并下载资料,将您的学习效率提升 10 倍。

AniShort

AniShort

为AI短剧协作而生

专为AI短剧协作而生的AniShort正式发布,深度重构AI短剧全流程生产模式,整合创意策划、制作执行、实时协作、在线审片、资产复用等全链路功能,独创无限画布、双轨并行工业化工作流与Ani智能体助手,集成多款主流AI大模型,破解素材零散、版本混乱、沟通低效等行业痛点,助力3人团队效率提升800%,打造标准化、可追溯的AI短剧量产体系,是AI短剧团队协同创作、提升制作效率的核心工具。

seedancetwo2.0

seedancetwo2.0

能听懂你表达的视频模型

Seedance two是基于seedance2.0的中国大模型,支持图像、视频、音频、文本四种模态输入,表达方式更丰富,生成也更可控。

nano-banana纳米香蕉中文站

nano-banana纳米香蕉中文站

国内直接访问,限时3折

输入简单文字,生成想要的图片,纳米香蕉中文站基于 Google 模型的 AI 图片生成网站,支持文字生图、图生图。官网价格限时3折活动

扣子-AI办公

扣子-AI办公

职场AI,就用扣子

AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!

堆友

堆友

多风格AI绘画神器

堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。

图像生成热门AI工具AI图像AI反应堆AI工具箱AI绘画GOAI艺术字堆友相机
码上飞

码上飞

零代码AI应用开发平台

零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

下拉加载更多