@apdesign/code-style-react 1.2.3 → 1.2.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/package.json +1 -1
- package/scripts/runEslint.js +8 -21
package/package.json
CHANGED
package/scripts/runEslint.js
CHANGED
@@ -75,16 +75,6 @@ async function runEslint(targetPathArg) {
|
|
75
75
|
|
76
76
|
const gitRoot = gitRootResult.stdout.trim();
|
77
77
|
|
78
|
-
let targetBranch = 'master';
|
79
|
-
if (targetPath !== process.cwd()) {
|
80
|
-
const pkgName = path.basename(targetPath); // 直接取传入的目录名
|
81
|
-
if (pkgName && pkgName.includes('-')) {
|
82
|
-
const suffix = pkgName.split('-').pop();
|
83
|
-
targetBranch = `master-${suffix}`;
|
84
|
-
}
|
85
|
-
}
|
86
|
-
|
87
|
-
// 获取当前分支
|
88
78
|
const currentBranchResult = spawnSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {
|
89
79
|
cwd: gitRoot,
|
90
80
|
encoding: 'utf-8',
|
@@ -98,12 +88,14 @@ async function runEslint(targetPathArg) {
|
|
98
88
|
|
99
89
|
const currentBranch = currentBranchResult.stdout.trim();
|
100
90
|
|
101
|
-
const branchToUse = branchArg ||
|
91
|
+
const branchToUse = branchArg || currentBranch;
|
102
92
|
|
103
93
|
console.log(`[Git 信息]`);
|
104
94
|
console.log(`仓库根目录: ${gitRoot}`);
|
105
95
|
console.log(`当前分支: ${currentBranch}`);
|
106
|
-
|
96
|
+
if (branchArg) {
|
97
|
+
console.log(`目标分支: ${branchToUse}`);
|
98
|
+
}
|
107
99
|
console.log('');
|
108
100
|
|
109
101
|
if (currentBranch !== branchToUse) {
|
@@ -161,7 +153,7 @@ async function runEslint(targetPathArg) {
|
|
161
153
|
const files = glob.sync('**/*.{js,jsx,ts,tsx}', { cwd: eslintTarget, absolute: true });
|
162
154
|
if (files.length === 0) {
|
163
155
|
console.log('- 没有需要检查的文件');
|
164
|
-
return;
|
156
|
+
return [];
|
165
157
|
}
|
166
158
|
|
167
159
|
console.log(`[ESLint 执行]`);
|
@@ -170,16 +162,11 @@ async function runEslint(targetPathArg) {
|
|
170
162
|
console.log('🚀 开始执行 ESLint ...\n');
|
171
163
|
|
172
164
|
const results = await eslint.lintFiles(files);
|
173
|
-
|
174
|
-
result.messages = result.messages.filter((message) => message.severity === 2); // 只保留错误
|
175
|
-
return result;
|
176
|
-
});
|
165
|
+
|
177
166
|
const formatter = await eslint.loadFormatter('stylish');
|
178
|
-
const resultText = formatter.format(
|
167
|
+
const resultText = formatter.format(results);
|
179
168
|
console.log(resultText);
|
180
|
-
|
181
|
-
const hasError = results.some((r) => r.errorCount > 0);
|
182
|
-
process.exit(hasError ? 1 : 0);
|
169
|
+
return results;
|
183
170
|
} catch (err) {
|
184
171
|
console.error('❌ 脚本执行出错:', err);
|
185
172
|
process.exit(1);
|