(file: string)
| 161 | } |
| 162 | |
| 163 | function fix(file: string) { |
| 164 | const src = readFileSync(path.join(ROOT, file), 'utf8'); |
| 165 | const lines = src.split('\n'); |
| 166 | let changed = false; |
| 167 | let fence: string | null = null; |
| 168 | for (let i = 0; i < lines.length; i++) { |
| 169 | const line = lines[i]; |
| 170 | const trim = line.trim(); |
| 171 | const fenceMatch = trim.match(/^(`{3,}|~{3,})/); |
| 172 | if (fenceMatch) { |
| 173 | const marker = fenceMatch[1][0]; |
| 174 | if (fence === null) fence = marker; |
| 175 | else if (marker === fence) fence = null; |
| 176 | continue; |
| 177 | } |
| 178 | if (fence !== null) continue; |
| 179 | if (!line.trimStart().startsWith('|')) continue; |
| 180 | if (!line.trimEnd().endsWith('|')) continue; |
| 181 | |
| 182 | const sep = isSep(line); |
| 183 | const next = rewriteRow(line, sep); |
| 184 | if (next !== line) { |
| 185 | lines[i] = next; |
| 186 | changed = true; |
| 187 | } |
| 188 | } |
| 189 | if (changed) writeFileSync(path.join(ROOT, file), lines.join('\n')); |
| 190 | return changed; |
| 191 | } |
| 192 | |
| 193 | const argv = process.argv.slice(2); |
| 194 | const fixFlag = argv.includes('--fix'); |
no test coverage detected