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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user