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

chore: Code Refactor

This commit is contained in:
Saad Jutt
2021-05-22 00:08:24 +05:00
parent 020a1e08d0
commit 0caf31b7ff
4 changed files with 140 additions and 124 deletions

View File

@@ -1,20 +1,7 @@
import { LintConfig } from '../types/LintConfig'
import { LintConfig, Macro } from '../types'
import { LineEndings } from '../types/LineEndings'
import { trimComments } from './trimComments'
interface Macro {
name: string
startLineNumbers: number[]
endLineNumber: number | null
declarationLines: string[]
terminationLine: string
declaration: string
termination: string
parentMacro: string
hasMacroNameInMend: boolean
mismatchedMendMacroName: string
}
export const parseMacros = (text: string, config?: LintConfig): Macro[] => {
const lineEnding = config?.lineEndings === LineEndings.CRLF ? '\r\n' : '\n'
const lines: string[] = text ? text.split(lineEnding) : []
@@ -39,6 +26,8 @@ export const parseMacros = (text: string, config?: LintConfig): Macro[] => {
const statements: string[] = trimmedLine.split(';')
if (isReadingMacroDefinition) {
// checking if code is split into statements based on `;` is a part of HTML Encoded Character
// if it happened, merges two statements into one
statements.forEach((statement, statementIndex) => {
if (/&[^\s]{1,5}$/.test(statement)) {
const next = statements[statementIndex]