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

fix(hasMacroNameInMend): check if %mend is extra

This commit is contained in:
Saad Jutt
2021-04-07 18:07:58 +05:00
parent bc3320adcb
commit 5c130c7a0e
2 changed files with 33 additions and 5 deletions

View File

@@ -92,6 +92,24 @@ describe('hasMacroNameInMend', () => {
])
})
it('should return an array with a single diagnostic when extra %mend statement is present', () => {
const content = `
%macro somemacro;
%put &sysmacroname;
%mend somemacro;
%mend something;`
expect(hasMacroNameInMend.test(content)).toEqual([
{
message: '%mend statement is redundant',
lineNumber: 5,
startColumnNumber: 3,
endColumnNumber: 18,
severity: Severity.Warning
}
])
})
it('should return an empty array when the file is undefined', () => {
const content = undefined

View File

@@ -36,17 +36,27 @@ const test = (value: string) => {
.slice(7, trimmedStatement.length)
.trim()
.split('(')[0]
declaredMacros.push({
name: macroName,
lineNumber: lineIndex + 1
})
if (macroName)
declaredMacros.push({
name: macroName,
lineNumber: lineIndex + 1
})
} else if (trimmedStatement.startsWith('%mend')) {
const declaredMacro = declaredMacros.pop()
const macroName = trimmedStatement
.split(' ')
.filter((s: string) => !!s)[1]
if (!macroName) {
if (!declaredMacro) {
diagnostics.push({
message: `%mend statement is redundant`,
lineNumber: lineIndex + 1,
startColumnNumber: getColumnNumber(line, '%mend'),
endColumnNumber:
getColumnNumber(line, '%mend') + trimmedStatement.length,
severity: Severity.Warning
})
} else if (!macroName) {
diagnostics.push({
message: `%mend statement is missing macro name - ${
declaredMacro!.name