@foundbyte/eslint-plugin 1.0.0 → 1.0.1

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.js CHANGED
@@ -1,7 +1,9 @@
1
1
  const arrowFunctionPaddingRule = require('./lib/rules/arrow-function-padding');
2
+ const vueScriptLinesLimitRule = require('./lib/rules/vue-script-lines-limit');
2
3
 
3
4
  module.exports = {
4
5
  rules: {
5
6
  'arrow-function-padding': arrowFunctionPaddingRule,
7
+ 'vue-script-lines-limit': vueScriptLinesLimitRule,
6
8
  },
7
9
  };
@@ -0,0 +1,76 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: 'problem',
4
+ docs: {
5
+ description: '限制 Vue 文件 script 标签内的行数',
6
+ category: 'Best Practices',
7
+ recommended: false,
8
+ },
9
+ fixable: null,
10
+ schema: [
11
+ {
12
+ type: 'object',
13
+ properties: {
14
+ maxLines: {
15
+ type: 'number',
16
+ minimum: 1,
17
+ },
18
+ },
19
+ additionalProperties: false,
20
+ },
21
+ ],
22
+ messages: {
23
+ exceedMaxLines: 'Vue 文件 script 标签内的代码行数不能超过 {{maxLines}} 行,当前有 {{currentLines}} 行',
24
+ },
25
+ },
26
+
27
+ create(context) {
28
+ const options = context.options[0] || {};
29
+ const maxLines = options.maxLines || 300;
30
+
31
+ // 只处理 .vue 文件
32
+ const filename = context.getFilename();
33
+ if (!filename.endsWith('.vue')) {
34
+ return {};
35
+ }
36
+
37
+ return {
38
+ Program(node) {
39
+ // 获取整个文件的源代码
40
+ const sourceCode = context.getSourceCode();
41
+ const text = sourceCode.getText();
42
+
43
+ // 使用正则表达式匹配 script 标签
44
+ const scriptRegex = /<script\b[^>]*>([\s\S]*?)<\/script>/gi;
45
+ let match;
46
+
47
+ while ((match = scriptRegex.exec(text)) !== null) {
48
+ const scriptContent = match[1];
49
+
50
+ // 计算 script 内容中的行数
51
+ const lines = scriptContent.split('\n').filter(line => line.trim() !== '');
52
+ const lineCount = lines.length;
53
+
54
+ if (lineCount > maxLines) {
55
+ // 找到 script 标签在 AST 中的位置
56
+ const scriptStartIndex = match.index;
57
+ const scriptEndIndex = scriptStartIndex + match[0].length;
58
+
59
+ // 在 script 标签的位置报告错误
60
+ context.report({
61
+ loc: {
62
+ start: sourceCode.getLocFromIndex(scriptStartIndex),
63
+ end: sourceCode.getLocFromIndex(scriptEndIndex),
64
+ },
65
+ messageId: 'exceedMaxLines',
66
+ data: {
67
+ maxLines,
68
+ currentLines: lineCount,
69
+ },
70
+ });
71
+ }
72
+ }
73
+ },
74
+ };
75
+ },
76
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@foundbyte/eslint-plugin",
3
- "version": "1.0.0",
4
- "description": "ESLint plugin for enforcing padding between arrow function declarations",
3
+ "version": "1.0.1",
4
+ "description": "ESLint plugin for enforcing code style rules including arrow function padding and Vue script lines limit",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -10,7 +10,10 @@
10
10
  "eslint",
11
11
  "eslintplugin",
12
12
  "arrow-function",
13
- "padding"
13
+ "padding",
14
+ "vue",
15
+ "script",
16
+ "lines-limit"
14
17
  ],
15
18
  "author": "",
16
19
  "license": "ISC",