diff --git a/src/utils/formatCode.spec.ts b/src/utils/formatCode.spec.ts index df46263b..49a4665f 100644 --- a/src/utils/formatCode.spec.ts +++ b/src/utils/formatCode.spec.ts @@ -1,3 +1,4 @@ +import {EOL} from 'os'; import { formatCode } from './formatCode'; const input1 = `{ foo: true }`; @@ -13,20 +14,14 @@ foo: true, bar: 123 }`; -const output3 = `{ -\tfoo: true, -\tbar: 123 -}`; +const output3 = `{${EOL}\tfoo: true,${EOL}\tbar: 123${EOL}}`; const input4 = `{ \t\t\t\tfoo: true, \t\t\t\tbar: 123 }`; -const output4 = `{ -\tfoo: true, -\tbar: 123 -}`; +const output4 = `{${EOL}\tfoo: true,${EOL}\tbar: 123${EOL}}`; describe('format', () => { it('should produce correct result', () => { diff --git a/src/utils/formatCode.ts b/src/utils/formatCode.ts index 42cfd5cf..9d0e8e69 100644 --- a/src/utils/formatCode.ts +++ b/src/utils/formatCode.ts @@ -2,7 +2,7 @@ import { EOL } from 'os'; export const formatCode = (s: string): string => { let indent: number = 0; - let lines = s.split(EOL); + let lines = s.split(/[\r\n]+/); lines = lines.map(line => { line = line.trim().replace(/^\*/g, ' *'); let i = indent;