Skip to content

Commit

Permalink
fix(hasMacroNameInMend): check if %mend is extra
Browse files Browse the repository at this point in the history
  • Loading branch information
saadjutt01 committed Apr 7, 2021
1 parent bc3320a commit 5c130c7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/rules/hasMacroNameInMend.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 15 additions & 5 deletions src/rules/hasMacroNameInMend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5c130c7

Please sign in to comment.