( filePath: string, encoding: BufferEncoding = 'utf8', )
| 118 | } |
| 119 | |
| 120 | export function detectLineEndings( |
| 121 | filePath: string, |
| 122 | encoding: BufferEncoding = 'utf8', |
| 123 | ): LineEndingType { |
| 124 | try { |
| 125 | const fs = getFsImplementation() |
| 126 | const { resolvedPath } = safeResolvePath(fs, filePath) |
| 127 | const { buffer, bytesRead } = fs.readSync(resolvedPath, { length: 4096 }) |
| 128 | |
| 129 | const content = buffer.toString(encoding, 0, bytesRead) |
| 130 | return detectLineEndingsForString(content) |
| 131 | } catch (error) { |
| 132 | logError(error) |
| 133 | return 'LF' |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | export function convertLeadingTabsToSpaces(content: string): string { |
| 138 | // The /gm regex scans every line even on no-match; skip it entirely |
no test coverage detected