@foundbyte/eslint-plugin 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +10 -0
- package/index.js +2 -0
- package/lib/rules/arrow-function-padding.d.ts +14 -0
- package/lib/rules/hooks-arrow-function-only.d.ts +14 -0
- package/lib/rules/hooks-arrow-function-only.js +69 -0
- package/lib/rules/hooks-export-limit.d.ts +18 -0
- package/lib/rules/index.d.ts +52 -0
- package/lib/rules/type-comment-requirement.d.ts +33 -0
- package/lib/rules/vue-script-lines-limit.d.ts +18 -0
- package/package.json +29 -28
- package/types.d.ts +2 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ESLint } from 'eslint'
|
|
2
|
+
import { Rules } from './lib/rules'
|
|
3
|
+
|
|
4
|
+
export { ArrowFunctionPaddingOptions, HooksExportLimitOptions, TypeCommentRequirementOptions, VueScriptLinesLimitOptions, HooksArrowFunctionOnlyOptions } from './types'
|
|
5
|
+
|
|
6
|
+
declare const plugin: ESLint.Plugin & {
|
|
7
|
+
rules: Rules
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { type Rules, plugin as default }
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const arrowFunctionPaddingRule = require('./lib/rules/arrow-function-padding')
|
|
|
2
2
|
const vueScriptLinesLimitRule = require('./lib/rules/vue-script-lines-limit')
|
|
3
3
|
const typeCommentRequirementRule = require('./lib/rules/type-comment-requirement')
|
|
4
4
|
const hooksExportLimitRule = require('./lib/rules/hooks-export-limit')
|
|
5
|
+
const hooksArrowFunctionOnlyRule = require('./lib/rules/hooks-arrow-function-only')
|
|
5
6
|
|
|
6
7
|
module.exports = {
|
|
7
8
|
rules: {
|
|
@@ -9,5 +10,6 @@ module.exports = {
|
|
|
9
10
|
'vue-script-lines-limit': vueScriptLinesLimitRule,
|
|
10
11
|
'type-comment-requirement': typeCommentRequirementRule,
|
|
11
12
|
'hooks-export-limit': hooksExportLimitRule,
|
|
13
|
+
'hooks-arrow-function-only': hooksArrowFunctionOnlyRule,
|
|
12
14
|
},
|
|
13
15
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Rule } from 'eslint'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 箭头函数间距规则配置
|
|
5
|
+
*/
|
|
6
|
+
export interface ArrowFunctionPaddingOptions {
|
|
7
|
+
// 此规则没有配置选项
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 箭头函数间距规则
|
|
12
|
+
*/
|
|
13
|
+
declare const arrowFunctionPaddingRule: Rule.RuleModule
|
|
14
|
+
export default arrowFunctionPaddingRule
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Rule } from 'eslint'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hooks 箭头函数要求规则配置
|
|
5
|
+
*/
|
|
6
|
+
export interface HooksArrowFunctionOnlyOptions {
|
|
7
|
+
// 此规则没有配置选项
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hooks 箭头函数要求规则
|
|
12
|
+
*/
|
|
13
|
+
declare const hooksArrowFunctionOnlyRule: Rule.RuleModule
|
|
14
|
+
export default hooksArrowFunctionOnlyRule
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'suggestion',
|
|
4
|
+
docs: {
|
|
5
|
+
description: '禁止 hooks 使用 function 声明,必须使用箭头函数',
|
|
6
|
+
category: 'Best Practices',
|
|
7
|
+
recommended: false,
|
|
8
|
+
},
|
|
9
|
+
fixable: 'code',
|
|
10
|
+
schema: [],
|
|
11
|
+
messages: {
|
|
12
|
+
useArrowFunction: 'hooks 必须使用箭头函数,不能使用 function 声明',
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
create(context) {
|
|
17
|
+
return {
|
|
18
|
+
// 检查函数声明
|
|
19
|
+
FunctionDeclaration(node) {
|
|
20
|
+
// 检查函数名是否以 use 开头(hooks 命名约定)
|
|
21
|
+
if (node.id && node.id.name && node.id.name.startsWith('use')) {
|
|
22
|
+
context.report({
|
|
23
|
+
node: node,
|
|
24
|
+
messageId: 'useArrowFunction',
|
|
25
|
+
fix(fixer) {
|
|
26
|
+
// 将 function 声明转换为箭头函数
|
|
27
|
+
const sourceCode = context.getSourceCode()
|
|
28
|
+
const functionName = node.id.name
|
|
29
|
+
const params = node.params.map(param => sourceCode.getText(param)).join(', ')
|
|
30
|
+
const body = sourceCode.getText(node.body)
|
|
31
|
+
|
|
32
|
+
// 构建箭头函数
|
|
33
|
+
const arrowFunction = `const ${functionName} = (${params}) => ${body}`
|
|
34
|
+
|
|
35
|
+
return fixer.replaceText(node, arrowFunction)
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
// 检查函数表达式(变量声明中的函数表达式)
|
|
42
|
+
VariableDeclarator(node) {
|
|
43
|
+
if (
|
|
44
|
+
node.init &&
|
|
45
|
+
node.init.type === 'FunctionExpression' &&
|
|
46
|
+
node.id &&
|
|
47
|
+
node.id.name &&
|
|
48
|
+
node.id.name.startsWith('use')
|
|
49
|
+
) {
|
|
50
|
+
context.report({
|
|
51
|
+
node: node.init,
|
|
52
|
+
messageId: 'useArrowFunction',
|
|
53
|
+
fix(fixer) {
|
|
54
|
+
// 将函数表达式转换为箭头函数
|
|
55
|
+
const sourceCode = context.getSourceCode()
|
|
56
|
+
const params = node.init.params.map(param => sourceCode.getText(param)).join(', ')
|
|
57
|
+
const body = sourceCode.getText(node.init.body)
|
|
58
|
+
|
|
59
|
+
// 构建箭头函数
|
|
60
|
+
const arrowFunction = `(${params}) => ${body}`
|
|
61
|
+
|
|
62
|
+
return fixer.replaceText(node.init, arrowFunction)
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Rule } from 'eslint'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Hooks 导出限制规则配置
|
|
5
|
+
*/
|
|
6
|
+
export interface HooksExportLimitOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 最大导出数量
|
|
9
|
+
* @default 20
|
|
10
|
+
*/
|
|
11
|
+
maxExports?: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Hooks 导出限制规则
|
|
16
|
+
*/
|
|
17
|
+
declare const hooksExportLimitRule: Rule.RuleModule
|
|
18
|
+
export default hooksExportLimitRule
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export { ArrowFunctionPaddingOptions } from './arrow-function-padding'
|
|
2
|
+
export { HooksExportLimitOptions } from './hooks-export-limit'
|
|
3
|
+
export { TypeCommentRequirementOptions } from './type-comment-requirement'
|
|
4
|
+
export { VueScriptLinesLimitOptions } from './vue-script-lines-limit'
|
|
5
|
+
export { HooksArrowFunctionOnlyOptions } from './hooks-arrow-function-only'
|
|
6
|
+
|
|
7
|
+
import { Rule } from 'eslint'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @foundbyte/eslint-plugin 规则配置
|
|
11
|
+
*/
|
|
12
|
+
export interface Rules {
|
|
13
|
+
/**
|
|
14
|
+
* 要求箭头函数声明之间有空行
|
|
15
|
+
*/
|
|
16
|
+
'arrow-function-padding': Rule.RuleModule
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 限制 hooks 导出的变量和方法数量
|
|
20
|
+
*/
|
|
21
|
+
'hooks-export-limit': Rule.RuleModule
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 要求 TypeScript interface 和 type 定义中字段必须有注释
|
|
25
|
+
*/
|
|
26
|
+
'type-comment-requirement': Rule.RuleModule
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 限制 Vue 文件 script 标签内的行数
|
|
30
|
+
*/
|
|
31
|
+
'vue-script-lines-limit': Rule.RuleModule
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 禁止 hooks (useXXX) 使用 function 声明,必须使用箭头函数
|
|
35
|
+
*/
|
|
36
|
+
'hooks-arrow-function-only': Rule.RuleModule
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 索引签名,用于兼容 ESLint 插件类型
|
|
40
|
+
*/
|
|
41
|
+
[key: string]: Rule.RuleModule
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @foundbyte/eslint-plugin 配置
|
|
46
|
+
*/
|
|
47
|
+
export interface Config {
|
|
48
|
+
rules: Rules
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
declare const config: Config
|
|
52
|
+
export default config
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Rule } from 'eslint'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 类型注释要求规则配置
|
|
5
|
+
*/
|
|
6
|
+
export interface TypeCommentRequirementOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 每多少个字段为一组进行检查
|
|
9
|
+
* @default 5
|
|
10
|
+
*/
|
|
11
|
+
groupSize?: number
|
|
12
|
+
/**
|
|
13
|
+
* 每组中至少有多少个字段必须加注释
|
|
14
|
+
* @default 1
|
|
15
|
+
*/
|
|
16
|
+
minCommentsPerGroup?: number
|
|
17
|
+
/**
|
|
18
|
+
* 是否检查 type 定义
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
includeTypes?: boolean
|
|
22
|
+
/**
|
|
23
|
+
* 是否检查 interface 定义
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
includeInterfaces?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 类型注释要求规则
|
|
31
|
+
*/
|
|
32
|
+
declare const typeCommentRequirementRule: Rule.RuleModule
|
|
33
|
+
export default typeCommentRequirementRule
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Rule } from 'eslint'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Vue Script 行数限制规则配置
|
|
5
|
+
*/
|
|
6
|
+
export interface VueScriptLinesLimitOptions {
|
|
7
|
+
/**
|
|
8
|
+
* 最大行数限制
|
|
9
|
+
* @default 300
|
|
10
|
+
*/
|
|
11
|
+
maxLines?: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Vue Script 行数限制规则
|
|
16
|
+
*/
|
|
17
|
+
declare const vueScriptLinesLimitRule: Rule.RuleModule
|
|
18
|
+
export default vueScriptLinesLimitRule
|
package/package.json
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
2
|
+
"name": "@foundbyte/eslint-plugin",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "ESLint plugin for enforcing code style rules including arrow function padding, Vue script lines limit, and TypeScript type comment requirements",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"eslint",
|
|
9
|
+
"eslintplugin",
|
|
10
|
+
"arrow-function",
|
|
11
|
+
"padding",
|
|
12
|
+
"vue",
|
|
13
|
+
"script",
|
|
14
|
+
"lines-limit",
|
|
15
|
+
"typescript",
|
|
16
|
+
"type-comment",
|
|
17
|
+
"comment-requirement"
|
|
18
|
+
],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"eslint": ">=8.0.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/types.d.ts
ADDED