mirror of
https://github.com/sasjs/lint.git
synced 2026-01-07 12:40:05 +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', () => {
|
it('should return an empty array when the file is undefined', () => {
|
||||||
const content = undefined
|
const content = undefined
|
||||||
|
|
||||||
|
|||||||
@@ -36,17 +36,27 @@ const test = (value: string) => {
|
|||||||
.slice(7, trimmedStatement.length)
|
.slice(7, trimmedStatement.length)
|
||||||
.trim()
|
.trim()
|
||||||
.split('(')[0]
|
.split('(')[0]
|
||||||
declaredMacros.push({
|
if (macroName)
|
||||||
name: macroName,
|
declaredMacros.push({
|
||||||
lineNumber: lineIndex + 1
|
name: macroName,
|
||||||
})
|
lineNumber: lineIndex + 1
|
||||||
|
})
|
||||||
} else if (trimmedStatement.startsWith('%mend')) {
|
} else if (trimmedStatement.startsWith('%mend')) {
|
||||||
const declaredMacro = declaredMacros.pop()
|
const declaredMacro = declaredMacros.pop()
|
||||||
const macroName = trimmedStatement
|
const macroName = trimmedStatement
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.filter((s: string) => !!s)[1]
|
.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({
|
diagnostics.push({
|
||||||
message: `%mend statement is missing macro name - ${
|
message: `%mend statement is missing macro name - ${
|
||||||
declaredMacro!.name
|
declaredMacro!.name
|
||||||
|
|||||||
Reference in New Issue
Block a user