# dir-structure **Repository Path**: zhaoshiqiang/dir-structure ## Basic Information - **Project Name**: dir-structure - **Description**: 检测目录结构是否符合规范 - **Primary Language**: JavaScript - **License**: ISC - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-10-09 - **Last Updated**: 2023-11-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # eslint-plugin-dir-structure 检测目录结构,变量命名是否符合规范 >目前主要用于vue+vue-router技术栈的相关项目 ## Installation 首先你应该下载eslint [ESLint](https://eslint.org/): ```sh npm i eslint --save-dev ``` 第二步下载 `eslint-plugin-dir-structure`: ```sh npm install eslint-plugin-dir-structure --save-dev ``` ## 使用 Add `dir-structure` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix: 将`dir-structure`添加到` .eslintrc `配置文件的`plugins`部分。你可以省略`eslint-plugin-`前缀: ```json { "plugins": [ "dir-structure" ] } ``` 然后在规则部分配置您想要使用的规则。 ```json { "rules": { "dir-structure/router-path": [2, "always", { "includeFile": ["*configManage"],//根据下方设置的目录及后缀划定检测范围,为空全检测 "excludeFile": [],// 设置无需检测的文件 "dirTypeOptions" : { //检测以下文件夹的命名是否和router的path一致 "port-service":".js" //可根据自己项目的实际名称进行变更 } }], "dir-structure/name-defined": [2, "always", { "includeFile": ["*configManage/dash","*demo"], //根据下方设置的目录及后缀划定检测范围,为空全检测 "excludeFile": [],// 设置无需检测的文件 "dirTypeOptions" : { // 检测当前service options 等js文件的export default 变量命名与路径是否一一对应 "options":".js", "service":".js" }, "nameType":{ "variableName":"camelCase", // camelCase 驼峰 Snake 下划线 "fileName":"kebab-case" // camelCase 驼峰 kebab-case 短横杠 } }] } } ``` ##### includeFile 代表需要检测router下的指定路径文件,类型为数组 []空代表router文件夹下需要全检测 示例如下,支持开头使用通配符的形式,变量后自动支持通配符, 注意:通配符只能存在一个,并且在开头 | Wildcard | Matching | |:------------|:----------------------------------------------------------| | `*stable` | `productionstable`, `stagingstable` ,`stagingstable/demo` | | `stable/dem` | `stable/dem/aa`, `stable/demfff` | ##### nameType 选择命名类型 | 属性 | 说明 | |:-------------|:--------------------------------------------------------------------| | `variableName` | export default变量命名规则,主要有俩种 `camelCase`代表小驼峰的形式命名 `Snake` 代表下划线的形式命名 | | `fileName` | 文件、文件夹命名类型模式,主要有俩种 `camelCase`代表小驼峰的形式命名 `kebab-case` 代表短横行的形式命名 | ## 规则 | Name | Description | |:-------------------------------------------|:--------------------------| | [router-path](docs/rules/router-path.md) | 检测目录结构是否符合规范 | | [name-defined](docs/rules/name-defined.md) | 检测文件export default的对应变量命名 | 更多检测规则持续补充中