mirror of
https://github.com/sasjs/lint.git
synced 2026-01-07 12:40:05 +00:00
fix(strictMacroDefinition): updated logic for getting options
This commit is contained in:
@@ -37,6 +37,10 @@ describe('strictMacroDefinition', () => {
|
|||||||
|
|
||||||
const content11 = '`%macro macroName() /* / store source */;'
|
const content11 = '`%macro macroName() /* / store source */;'
|
||||||
expect(strictMacroDefinition.test(content11)).toEqual([])
|
expect(strictMacroDefinition.test(content11)).toEqual([])
|
||||||
|
|
||||||
|
const content12 =
|
||||||
|
'%macro macroName()/ /* some comment */ store des="some description";'
|
||||||
|
expect(strictMacroDefinition.test(content12)).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should return an array with a single diagnostic when Macro definition has space in param', () => {
|
it('should return an array with a single diagnostic when Macro definition has space in param', () => {
|
||||||
|
|||||||
@@ -101,28 +101,43 @@ const test = (value: string, config?: LintConfig) => {
|
|||||||
_declaration = declaration.split(`(${paramsPresent})`)[1]
|
_declaration = declaration.split(`(${paramsPresent})`)[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
const optionsPresent = _declaration.split('/')?.[1]?.trim().split(' ')
|
let optionsPresent = _declaration.split('/')?.[1]?.trim()
|
||||||
|
|
||||||
optionsPresent
|
if (optionsPresent) {
|
||||||
?.filter((o) => !!o)
|
const regex = new RegExp(/="(.*?)"/, 'g')
|
||||||
.forEach((option) => {
|
|
||||||
const trimmedOption = option.trim()
|
|
||||||
if (!validOptions.includes(trimmedOption.toUpperCase())) {
|
|
||||||
const declarationLineIndex = macro.declarationLines.findIndex(
|
|
||||||
(dl) => dl.indexOf(trimmedOption) !== -1
|
|
||||||
)
|
|
||||||
const declarationLine = macro.declarationLines[declarationLineIndex]
|
|
||||||
|
|
||||||
diagnostics.push({
|
let result = regex.exec(optionsPresent)
|
||||||
message: `Option '${trimmedOption}' is not valid`,
|
|
||||||
lineNumber: macro.startLineNumbers[declarationLineIndex],
|
while (result) {
|
||||||
startColumnNumber: declarationLine.indexOf(trimmedOption) + 1,
|
optionsPresent =
|
||||||
endColumnNumber:
|
optionsPresent.slice(0, result.index) +
|
||||||
declarationLine.indexOf(trimmedOption) + trimmedOption.length,
|
optionsPresent.slice(result.index + result[0].length)
|
||||||
severity: Severity.Warning
|
|
||||||
})
|
result = regex.exec(optionsPresent)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
optionsPresent
|
||||||
|
.split(' ')
|
||||||
|
?.filter((o) => !!o)
|
||||||
|
.forEach((option) => {
|
||||||
|
const trimmedOption = option.trim()
|
||||||
|
if (!validOptions.includes(trimmedOption.toUpperCase())) {
|
||||||
|
const declarationLineIndex = macro.declarationLines.findIndex(
|
||||||
|
(dl) => dl.indexOf(trimmedOption) !== -1
|
||||||
|
)
|
||||||
|
const declarationLine = macro.declarationLines[declarationLineIndex]
|
||||||
|
|
||||||
|
diagnostics.push({
|
||||||
|
message: `Option '${trimmedOption}' is not valid`,
|
||||||
|
lineNumber: macro.startLineNumbers[declarationLineIndex],
|
||||||
|
startColumnNumber: declarationLine.indexOf(trimmedOption) + 1,
|
||||||
|
endColumnNumber:
|
||||||
|
declarationLine.indexOf(trimmedOption) + trimmedOption.length,
|
||||||
|
severity: Severity.Warning
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return diagnostics
|
return diagnostics
|
||||||
|
|||||||
Reference in New Issue
Block a user