@foundbyte/eslint-plugin 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ const arrowFunctionPaddingRule = require('./lib/rules/arrow-function-padding');
2
+
3
+ module.exports = {
4
+ rules: {
5
+ 'arrow-function-padding': arrowFunctionPaddingRule,
6
+ },
7
+ };
@@ -0,0 +1,64 @@
1
+ module.exports = {
2
+ meta: {
3
+ type: 'layout',
4
+ docs: {
5
+ description: '要求箭头函数声明之间有空行',
6
+ category: 'Stylistic Issues',
7
+ recommended: false,
8
+ },
9
+ fixable: 'whitespace',
10
+ schema: [],
11
+ messages: {
12
+ missingPadding: '箭头函数声明之间需要空行',
13
+ },
14
+ },
15
+
16
+ create(context) {
17
+ let previousVariableDeclarationEndLine = null;
18
+
19
+ return {
20
+ VariableDeclaration(node) {
21
+ // 只检查顶层的变量声明,忽略嵌套在函数内部的声明
22
+ // 检查父节点是否是 Program(文件顶层)或者父节点是 BlockStatement 且父节点的父节点是 Program
23
+ if (node.parent.type !== 'Program' &&
24
+ !(node.parent.type === 'BlockStatement' && node.parent.parent && node.parent.parent.type === 'Program')) {
25
+ return;
26
+ }
27
+
28
+ if (node.kind !== 'const') {
29
+ previousVariableDeclarationEndLine = null;
30
+ return;
31
+ }
32
+
33
+ // 检查当前变量声明是否包含箭头函数
34
+ let hasArrowFunction = false;
35
+ for (const declarator of node.declarations) {
36
+ if (declarator.init && declarator.init.type === 'ArrowFunctionExpression') {
37
+ hasArrowFunction = true;
38
+ break;
39
+ }
40
+ }
41
+
42
+ if (hasArrowFunction) {
43
+ const currentStartLine = node.loc.start.line;
44
+ const currentEndLine = node.loc.end.line;
45
+
46
+ if (previousVariableDeclarationEndLine !== null && currentStartLine === previousVariableDeclarationEndLine + 1) {
47
+ context.report({
48
+ node: node,
49
+ messageId: 'missingPadding',
50
+ fix(fixer) {
51
+ return fixer.insertTextBefore(node, '\n');
52
+ },
53
+ });
54
+ }
55
+
56
+ previousVariableDeclarationEndLine = currentEndLine;
57
+ } else {
58
+ // 如果不包含箭头函数,重置计数器
59
+ previousVariableDeclarationEndLine = null;
60
+ }
61
+ },
62
+ };
63
+ },
64
+ };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@foundbyte/eslint-plugin",
3
+ "version": "1.0.0",
4
+ "description": "ESLint plugin for enforcing padding between arrow function declarations",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [
10
+ "eslint",
11
+ "eslintplugin",
12
+ "arrow-function",
13
+ "padding"
14
+ ],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "peerDependencies": {
21
+ "eslint": ">=8.0.0"
22
+ }
23
+ }