1
0
mirror of https://github.com/sasjs/lint.git synced 2026-01-05 03:30:06 +00:00

feat(*): add line endings rule, add automatic formatting for fixable violations

This commit is contained in:
Krishna Acondy
2021-04-19 21:00:38 +01:00
parent 99813f04c0
commit 519a0164b5
32 changed files with 941 additions and 259 deletions

17
src/utils/splitText.ts Normal file
View File

@@ -0,0 +1,17 @@
import { LintConfig } from '../types/LintConfig'
import { LineEndings } from '../types/LineEndings'
/**
* Splits the given content into a list of lines, regardless of CRLF or LF line endings.
* @param {string} text - the text content to be split into lines.
* @returns {string[]} an array of lines from the given text
*/
export const splitText = (text: string, config: LintConfig): string[] => {
if (!text) return []
const expectedLineEndings =
config.lineEndings === LineEndings.LF ? '\n' : '\r\n'
const incorrectLineEndings = expectedLineEndings === '\n' ? '\r\n' : '\n'
return text
.replace(new RegExp(incorrectLineEndings, 'g'), expectedLineEndings)
.split(expectedLineEndings)
}