eslint-plugin-bf-eslint-plugin
v1.0.14
Published
bf es plugin
Downloads
111
Maintainers
Readme
eslint-plugin-bf-eslint-plugin
bf es plugin
Installation
You'll first need to install ESLint:
npm i eslint --save-devNext, install eslint-plugin-bf-eslint-plugin:
npm install eslint-plugin-bf-eslint-plugin --save-devUsage
In your configuration file, import the plugin eslint-plugin-bf-eslint-plugin and add bf-eslint-plugin to the plugins key:
import bf-eslint-plugin from "eslint-plugin-bf-eslint-plugin";
export default [
{
plugins: {
bf-eslint-plugin
}
}
];Then configure the rules you want to use under the rules key.
import bf-eslint-plugin from "eslint-plugin-bf-eslint-plugin";
export default [
{
plugins: {
bf-eslint-plugin
},
rules: {
"bf-eslint-plugin/rule-name": "warn"
}
}
];run single test
node test/lib/rules/XXXX.jsrun all the test
npm run test规则说明
bf-utility-function-jsdoc
该规则强制复杂工具函数必须包含完整的JSDoc注释。
工具函数定义:
- 函数名称包含工具关键字(如
Util、convert、handle、format等) - 驼峰命名段数超过2段(如
formatUserDataToJson)
注释要求:
- 必须包含功能说明(非标签的描述文本)
- 只有当函数有参数时才必须包含
@param标签(描述参数) - 只有当函数有返回值时才必须包含
@return标签(描述返回值)
配置选项:
utilityKeywords: 工具函数关键字数组,默认为["Util", "convert", "handle", "format"]reportIdNode: 是否报告ID节点而不是整个函数节点,默认为true
示例:
// ✓ 正确 - 有参数和返回值
/**
* 生成安全的用户ID工具函数
* @param {string} prefix 用户ID前缀
* @param {number} length ID长度
* @return {string} 生成的用户ID
*/
function generateSafeUserIdUtil(prefix, length) {
return prefix + Math.random();
}
// ✓ 正确 - 无参数,无返回值
/**
* 格式化日期
*/
function formatUserDate() {
console.log(new Date());
}
// ✗ 错误 - 缺少 @param 标签
/**
* 处理用户数据转换
* @return {Object} 处理后的数据
*/
function handleUserDataConversion(userData) {
return userData;
}git-diff-process 说明
假设原文件的的内容是:
function printHello() {
console.log("Hello2");
console.log("Hello2");
}然后修改为如下内容:
function printHello() {
console.log("Hello3");
}
function sum(a: number, b: number): number {
return a + b;
}则输出的git diff信息为
{
"old_path": "assets/test.ts",
"new_path": "assets/test.ts",
"a_mode": "100644",
"b_mode": "100644",
"new_file": false,
"renamed_file": false,
"deleted_file": false,
"diff": "@@ -1,4 +1,8 @@\n function printHello() {\n- console.log(\"Hello2\");\n- console.log(\"Hello2\");\n+ console.log(\"Hello3\");\n+}\n+\n+\n+function sum(a: number, b: number): number {\n+ return a + b;\n }\n"
}通过库gitdiff-parser解析之后,输出
[
{
"hunks": [
{
"content": "@@ -1,4 +1,8 @@",
"oldStart": 1,
"newStart": 1,
"oldLines": 4,
"newLines": 8,
"changes": [
{
"content": "function printHello() {",
"type": "normal",
"isNormal": true,
"oldLineNumber": 1,
"newLineNumber": 1
},
{
"content": " console.log(\"Hello2\");",
"type": "delete",
"isDelete": true,
"lineNumber": 2
},
{
"content": " console.log(\"Hello2\");",
"type": "delete",
"isDelete": true,
"lineNumber": 3
},
{
"content": " console.log(\"Hello3\");",
"type": "insert",
"isInsert": true,
"lineNumber": 2
},
{
"content": "}",
"type": "insert",
"isInsert": true,
"lineNumber": 3
},
{
"content": "",
"type": "insert",
"isInsert": true,
"lineNumber": 4
},
{
"content": "",
"type": "insert",
"isInsert": true,
"lineNumber": 5
},
{
"content": "function sum(a: number, b: number): number {",
"type": "insert",
"isInsert": true,
"lineNumber": 6
},
{
"content": " return a + b;",
"type": "insert",
"isInsert": true,
"lineNumber": 7
},
{
"content": "}",
"type": "normal",
"isNormal": true,
"oldLineNumber": 4,
"newLineNumber": 8
}
]
}
],
"oldEndingNewLine": true,
"newEndingNewLine": true,
"oldPath": "assets/test.ts",
"newPath": "assets/test.ts",
"oldRevision": "1234567",
"newRevision": "abcdefg",
"newMode": "100644",
"oldMode": "100644",
"type": "modify"
}
]可以得出几个信息
- 新增是insert
- 修改本质是先delete,再insert
