eslint-plugin-dir-structure
v0.1.6
Published
检测目录结构是否符合规范
Downloads
194
Maintainers
Readme
eslint-plugin-dir-structure
检测目录结构,变量命名是否符合规范
目前主要用于vue+vue-router技术栈的相关项目
Installation
首先你应该下载eslint ESLint:
npm i eslint --save-dev
第二步下载 eslint-plugin-dir-structure
:
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-
前缀:
{
"plugins": [
"dir-structure"
]
}
然后在规则部分配置您想要使用的规则。
{
"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 | 检测目录结构是否符合规范 | | name-defined | 检测文件export default的对应变量命名 |
更多检测规则持续补充中