mirror of
https://github.com/sasjs/lint.git
synced 2026-01-06 20:20:06 +00:00
fix(hasMacroNameInMend): linting through comments
This commit is contained in:
@@ -149,12 +149,17 @@ describe('hasMacroNameInMend', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('with extra spaces ', () => {
|
||||
describe('with extra spaces and comments', () => {
|
||||
it('should return an empty array when %mend has correct macro name', () => {
|
||||
const content = `
|
||||
/* 1st comment */
|
||||
%macro somemacro ;
|
||||
|
||||
%put &sysmacroname;
|
||||
%mend somemacro ;`
|
||||
|
||||
/* 2nd
|
||||
comment */
|
||||
/* 3rd comment */ %mend somemacro ;`
|
||||
|
||||
expect(hasMacroNameInMend.test(content)).toEqual([])
|
||||
})
|
||||
@@ -162,9 +167,9 @@ describe('hasMacroNameInMend', () => {
|
||||
it('should return an array with a single diagnostic when %mend has incorrect macro name', () => {
|
||||
const content = `
|
||||
%macro somemacro;
|
||||
|
||||
/* some comments */
|
||||
%put &sysmacroname;
|
||||
|
||||
/* some comments */
|
||||
%mend someanothermacro ;`
|
||||
|
||||
expect(hasMacroNameInMend.test(content)).toEqual([
|
||||
@@ -181,7 +186,7 @@ describe('hasMacroNameInMend', () => {
|
||||
it('should return an array with a single diagnostic when %mend has no macro name', () => {
|
||||
const content = `
|
||||
%macro somemacro ;
|
||||
%put &sysmacroname;
|
||||
/* some comments */%put &sysmacroname;
|
||||
%mend ;`
|
||||
|
||||
expect(hasMacroNameInMend.test(content)).toEqual([
|
||||
|
||||
@@ -13,7 +13,7 @@ const test = (value: string) => {
|
||||
|
||||
const stack: string[] = []
|
||||
statements.forEach((statement, index) => {
|
||||
const trimmedStatement = statement.trim()
|
||||
const trimmedStatement = trimComments(statement).trim()
|
||||
if (trimmedStatement.startsWith('%macro ')) {
|
||||
const macroName = trimmedStatement
|
||||
.split(' ')
|
||||
@@ -58,6 +58,15 @@ const test = (value: string) => {
|
||||
return diagnostics
|
||||
}
|
||||
|
||||
const trimComments = (statement: string): string => {
|
||||
let trimmed = statement.trim()
|
||||
|
||||
if (trimmed.startsWith('/*'))
|
||||
trimmed = (trimmed.split('*/').pop() as string).trim()
|
||||
|
||||
return trimmed
|
||||
}
|
||||
|
||||
const getLineNumber = (statements: string[], index: number): number => {
|
||||
const combinedCode = statements.slice(0, index).join(';')
|
||||
const lines = (combinedCode.match(/\n/g) || []).length + 1
|
||||
@@ -65,7 +74,7 @@ const getLineNumber = (statements: string[], index: number): number => {
|
||||
}
|
||||
|
||||
const getColNumber = (statement: string, text: string): number => {
|
||||
return statement.replace(/[\r\n]+/, '').indexOf(text) + 1
|
||||
return (statement.split('\n').pop() as string).indexOf(text) + 1
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user