1
0
mirror of https://github.com/sasjs/lint.git synced 2025-12-10 17:34:36 +00:00

fix(trimComments): handle case special comment case

This commit is contained in:
Saad Jutt
2021-05-21 18:05:22 +05:00
parent f793eb3a76
commit d391a4e8fc
2 changed files with 17 additions and 5 deletions

View File

@@ -8,6 +8,18 @@ describe('trimComments', () => {
`)
).toEqual({ statement: 'some code;', commentStarted: false })
expect(
trimComments(`
/*/ some comment */ some code;
`)
).toEqual({ statement: 'some code;', commentStarted: false })
expect(
trimComments(`
some code;/*/ some comment */ some code;
`)
).toEqual({ statement: 'some code; some code;', commentStarted: false })
expect(
trimComments(`/* some comment */
/* some comment */ CODE_Keyword1 /* some comment */ CODE_Keyword2/* some comment */;/* some comment */

View File

@@ -6,7 +6,9 @@ export const trimComments = (
let trimmed = trimEnd ? (statement || '').trimEnd() : (statement || '').trim()
if (commentStarted || trimmed.startsWith('/*')) {
const parts = trimmed.split('*/')
const parts = trimmed.startsWith('/*')
? trimmed.slice(2).split('*/')
: trimmed.split('*/')
if (parts.length === 2) {
return {
statement: (parts.pop() as string).trim(),
@@ -20,10 +22,8 @@ export const trimComments = (
}
} else if (trimmed.includes('/*')) {
const statementBeforeCommentStarts = trimmed.slice(0, trimmed.indexOf('/*'))
const remainingStatement = trimmed.slice(
trimmed.indexOf('*/') + 2,
trimmed.length
)
trimmed = trimmed.slice(trimmed.indexOf('/*') + 2)
const remainingStatement = trimmed.slice(trimmed.indexOf('*/') + 2)
const result = trimComments(remainingStatement, false, true)
const completeStatement = statementBeforeCommentStarts + result.statement