(stagedFiles)
| 156 | } |
| 157 | |
| 158 | function runChecks(stagedFiles) { |
| 159 | const failures = []; |
| 160 | |
| 161 | for (const relPath of stagedFiles) { |
| 162 | const ext = path.extname(relPath).toLowerCase(); |
| 163 | if (!JS_EXTENSIONS.has(ext) && ext !== '.json') { |
| 164 | continue; |
| 165 | } |
| 166 | |
| 167 | const content = readStagedContent(relPath); |
| 168 | if (SMART_QUOTES_RE.test(content)) { |
| 169 | failures.push( |
| 170 | `${relPath}: 检测到智能引号(U+201C/U+201D/U+2018/U+2019),请改为标准半角引号。` |
| 171 | ); |
| 172 | continue; |
| 173 | } |
| 174 | |
| 175 | try { |
| 176 | if (JS_EXTENSIONS.has(ext)) { |
| 177 | checkJavaScriptSyntax(relPath, content); |
| 178 | } else if (ext === '.json') { |
| 179 | JSON.parse(content); |
| 180 | } |
| 181 | } catch (error) { |
| 182 | failures.push(`${relPath}: ${error.message}`); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return failures; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Run pre-commit validation and normalization for staged files, aborting the commit on violations. |
no test coverage detected