auto-cr-rules 1.0.11 → 1.0.13
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BabelCore from '@babel/core';
|
|
2
|
-
import type { CallExpression, ImportDeclaration } from '@babel/types';
|
|
2
|
+
import type { CallExpression, ExportAllDeclaration, ExportNamedDeclaration, ImportDeclaration } from '@babel/types';
|
|
3
3
|
import type { NodePath } from '@babel/traverse';
|
|
4
4
|
import { PluginOptions } from '../types';
|
|
5
5
|
export default function (api: typeof BabelCore, options: PluginOptions): {
|
|
@@ -7,5 +7,7 @@ export default function (api: typeof BabelCore, options: PluginOptions): {
|
|
|
7
7
|
visitor: {
|
|
8
8
|
ImportDeclaration(path: NodePath<ImportDeclaration>): void;
|
|
9
9
|
CallExpression(path: NodePath<CallExpression>): void;
|
|
10
|
+
ExportNamedDeclaration(path: NodePath<ExportNamedDeclaration>): void;
|
|
11
|
+
ExportAllDeclaration(path: NodePath<ExportAllDeclaration>): void;
|
|
10
12
|
};
|
|
11
13
|
};
|
|
@@ -14,7 +14,7 @@ function checkRelativePath(sourceValue, path, maxDepth, report) {
|
|
|
14
14
|
// 计算路径深度:通过计算 "../" 的出现次数
|
|
15
15
|
var depth = (sourceValue.match(/\.\.\//g) || []).length;
|
|
16
16
|
if (depth > maxDepth) {
|
|
17
|
-
report(path, "\u5BFC\u5165\u8DEF\u5F84 \"".concat(sourceValue, "\" \u4E0D\u80FD\u8D85\u8FC7\u6700\u5927\u5C42\u7EA7").concat(maxDepth));
|
|
17
|
+
report(path, "\u5BFC\u5165/\u5BFC\u51FA\u8DEF\u5F84 \"".concat(sourceValue, "\" \u4E0D\u80FD\u8D85\u8FC7\u6700\u5927\u5C42\u7EA7\uFF08").concat(maxDepth, "\uFF1A\u5C42\uFF09"));
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -57,6 +57,22 @@ function default_1(api, options) {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
|
+
// 处理命名导出(export { ... } from 'module')
|
|
61
|
+
ExportNamedDeclaration: function (path) {
|
|
62
|
+
if (path.node.source) {
|
|
63
|
+
var sourceValue = path.node.source.value;
|
|
64
|
+
if (typeof sourceValue === 'string') {
|
|
65
|
+
checkRelativePath(sourceValue, path, maxDepth, report);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
// 处理全部导出(export * from 'module')
|
|
70
|
+
ExportAllDeclaration: function (path) {
|
|
71
|
+
var sourceValue = path.node.source.value;
|
|
72
|
+
if (typeof sourceValue === 'string') {
|
|
73
|
+
checkRelativePath(sourceValue, path, maxDepth, report);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
60
76
|
},
|
|
61
77
|
};
|
|
62
78
|
}
|