mirror of
https://github.com/sasjs/lint.git
synced 2026-01-11 06:20:06 +00:00
feat: mult-line macro declarations
This commit is contained in:
@@ -24,6 +24,19 @@ describe('strictMacroDefinition', () => {
|
||||
const line7 =
|
||||
' /* Some Comment */ %macro somemacro(var1, var2) /minoperator ; /* Some Comment */'
|
||||
expect(strictMacroDefinition.test(line7, 1)).toEqual([])
|
||||
|
||||
const line8 =
|
||||
'%macro macroName( arr, arr/* / store source */3 ) /* / store source */;/* / store source */'
|
||||
expect(strictMacroDefinition.test(line8, 1)).toEqual([])
|
||||
|
||||
const line9 = '%macro macroName(var1, var2=with space, var3=);'
|
||||
expect(strictMacroDefinition.test(line9, 1)).toEqual([])
|
||||
|
||||
const line10 = '%macro macroName()/ /* some comment */ store source;'
|
||||
expect(strictMacroDefinition.test(line10, 1)).toEqual([])
|
||||
|
||||
const line11 = '`%macro macroName() /* / store source */;'
|
||||
expect(strictMacroDefinition.test(line11, 1)).toEqual([])
|
||||
})
|
||||
|
||||
it('should return an array with a single diagnostic when Macro definition has space in param', () => {
|
||||
@@ -39,7 +52,7 @@ describe('strictMacroDefinition', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('should return an array with a two diagnostics when Macro definition has space in param', () => {
|
||||
it('should return an array with a two diagnostics when Macro definition has space in params', () => {
|
||||
const line = '%macro somemacro(var1, var 2, v ar3, var4);'
|
||||
expect(strictMacroDefinition.test(line, 1)).toEqual([
|
||||
{
|
||||
@@ -59,6 +72,20 @@ describe('strictMacroDefinition', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('should return an array with a two diagnostics when Macro definition has space in params - special case', () => {
|
||||
const line =
|
||||
'%macro macroName( arr, ar r/* / store source */ 3 ) /* / store source */;/* / store source */'
|
||||
expect(strictMacroDefinition.test(line, 1)).toEqual([
|
||||
{
|
||||
message: `Param 'ar r 3' cannot have space`,
|
||||
lineNumber: 1,
|
||||
startColumnNumber: 24,
|
||||
endColumnNumber: 49,
|
||||
severity: Severity.Warning
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('should return an array with a single diagnostic when Macro definition has invalid option', () => {
|
||||
const line = '%macro somemacro(var1, var2)/minXoperator;'
|
||||
expect(strictMacroDefinition.test(line, 1)).toEqual([
|
||||
|
||||
@@ -42,12 +42,34 @@ const test = (value: string, lineNumber: number) => {
|
||||
const params = paramsTrimmed.split(',')
|
||||
params.forEach((param) => {
|
||||
const trimedParam = param.split('=')[0].trim()
|
||||
|
||||
let paramStartIndex: number = 1,
|
||||
paramEndIndex: number = value.length
|
||||
|
||||
if (value.indexOf(trimedParam) === -1) {
|
||||
const comment = '/\\*(.*?)\\*/'
|
||||
for (let i = 1; i < trimedParam.length; i++) {
|
||||
const paramWithComment =
|
||||
trimedParam.slice(0, i) + comment + trimedParam.slice(i)
|
||||
const regEx = new RegExp(paramWithComment)
|
||||
const result = regEx.exec(value)
|
||||
if (result) {
|
||||
paramStartIndex = value.indexOf(result[0])
|
||||
paramEndIndex = value.indexOf(result[0]) + result[0].length
|
||||
break
|
||||
}
|
||||
}
|
||||
} else {
|
||||
paramStartIndex = value.indexOf(trimedParam)
|
||||
paramEndIndex = value.indexOf(trimedParam) + trimedParam.length
|
||||
}
|
||||
|
||||
if (trimedParam.includes(' ')) {
|
||||
diagnostics.push({
|
||||
message: `Param '${trimedParam}' cannot have space`,
|
||||
lineNumber,
|
||||
startColumnNumber: value.indexOf(trimedParam) + 1,
|
||||
endColumnNumber: value.indexOf(trimedParam) + trimedParam.length,
|
||||
startColumnNumber: paramStartIndex + 1,
|
||||
endColumnNumber: paramEndIndex,
|
||||
severity: Severity.Warning
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user