1
0
mirror of https://github.com/sasjs/lint.git synced 2026-01-16 08:40:05 +00:00

fix(hasMacroNameInMend): linting through comments

This commit is contained in:
Saad Jutt
2021-04-05 21:56:28 +05:00
parent a0e2c2d843
commit 5782886bdc
2 changed files with 21 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ const test = (value: string) => {
const stack: string[] = []
statements.forEach((statement, index) => {
const trimmedStatement = statement.trim()
const trimmedStatement = trimComments(statement).trim()
if (trimmedStatement.startsWith('%macro ')) {
const macroName = trimmedStatement
.split(' ')
@@ -58,6 +58,15 @@ const test = (value: string) => {
return diagnostics
}
const trimComments = (statement: string): string => {
let trimmed = statement.trim()
if (trimmed.startsWith('/*'))
trimmed = (trimmed.split('*/').pop() as string).trim()
return trimmed
}
const getLineNumber = (statements: string[], index: number): number => {
const combinedCode = statements.slice(0, index).join(';')
const lines = (combinedCode.match(/\n/g) || []).length + 1
@@ -65,7 +74,7 @@ const getLineNumber = (statements: string[], index: number): number => {
}
const getColNumber = (statement: string, text: string): number => {
return statement.replace(/[\r\n]+/, '').indexOf(text) + 1
return (statement.split('\n').pop() as string).indexOf(text) + 1
}
/**