MCPcopy Create free account
hub / github.com/Silentely/eSIM-Tools / main

Function main

scripts/pre-commit-check.js:202–233  ·  view source on GitHub ↗

* Run pre-commit validation and normalization for staged files, aborting the commit on violations. * * Checks for changes to protected files and exits with status 1 if any are touched. If there are no * staged files, exits with status 0. For staged text files, normalizes line endings, trims trail

()

Source from the content-addressed store, hash-verified

200 * - 1: protected file touched or one or more validation failures
201 */
202function main() {
203 const touchedProtectedFiles = PROTECTED_FILES.length > 0 ? getTouchedProtectedFiles() : [];
204 if (touchedProtectedFiles.length > 0) {
205 console.error('\n❌ pre-commit 检查失败:');
206 for (const relPath of touchedProtectedFiles) {
207 console.error(` - ${relPath}: 该文件受保护,禁止提交改动。`);
208 }
209 console.error(' - 如确需调整,请改为维护对应 modular 版本文件。');
210 process.exit(1);
211 }
212
213 const stagedFiles = getStagedFiles();
214 if (stagedFiles.length === 0) {
215 process.exit(0);
216 }
217
218 const formatted = formatStagedFiles(stagedFiles);
219 if (formatted.length > 0) {
220 console.log(`✅ 已格式化并重新暂存 ${formatted.length} 个文件`);
221 }
222
223 const failures = runChecks(stagedFiles);
224 if (failures.length > 0) {
225 console.error('\n❌ pre-commit 检查失败:');
226 for (const failure of failures) {
227 console.error(` - ${failure}`);
228 }
229 process.exit(1);
230 }
231
232 console.log('✅ pre-commit 检查通过');
233}
234
235main();

Callers 1

Calls 6

getStagedFilesFunction · 0.85
formatStagedFilesFunction · 0.85
getTouchedProtectedFilesFunction · 0.70
runChecksFunction · 0.70
errorMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected