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'

另请参阅

编辑推荐精选

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绘画GOAI艺术字堆友相机AI图像热门
码上飞

码上飞

零代码AI应用开发平台

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

Vora

Vora

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

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

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

AI工具TraeAI IDE协作生产力转型热门
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

AI辅助写作AI工具AI论文工具论文写作智能生成大纲数据安全AI助手热门
下拉加载更多