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

feat: mult-line macro declarations

This commit is contained in:
Saad Jutt
2021-05-21 05:10:34 +05:00
parent 8bfb547427
commit af2d2c12c1
12 changed files with 325 additions and 86 deletions

View File

@@ -1,8 +1,9 @@
export const trimComments = (
statement: string,
commentStarted: boolean = false
commentStarted: boolean = false,
trimEnd: boolean = false
): { statement: string; commentStarted: boolean } => {
let trimmed = (statement || '').trim()
let trimmed = trimEnd ? (statement || '').trimEnd() : (statement || '').trim()
if (commentStarted || trimmed.startsWith('/*')) {
const parts = trimmed.split('*/')
@@ -20,13 +21,16 @@ export const trimComments = (
} else if (trimmed.includes('/*')) {
const statementBeforeCommentStarts = trimmed.slice(0, trimmed.indexOf('/*'))
const remainingStatement = trimmed.slice(
trimmed.indexOf('/*'),
trimmed.indexOf('*/') + 2,
trimmed.length
)
const result = trimComments(remainingStatement, false)
const result = trimComments(remainingStatement, false, true)
const completeStatement = statementBeforeCommentStarts + result.statement
return {
statement: statementBeforeCommentStarts + result.statement,
statement: trimEnd
? completeStatement.trimEnd()
: completeStatement.trim(),
commentStarted: result.commentStarted
}
}