mirror of
https://github.com/sasjs/lint.git
synced 2026-01-07 20:50:04 +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', () => {
|
it('should return an empty array when %mend has correct macro name', () => {
|
||||||
const content = `
|
const content = `
|
||||||
|
/* 1st comment */
|
||||||
%macro somemacro ;
|
%macro somemacro ;
|
||||||
|
|
||||||
%put &sysmacroname;
|
%put &sysmacroname;
|
||||||
%mend somemacro ;`
|
|
||||||
|
/* 2nd
|
||||||
|
comment */
|
||||||
|
/* 3rd comment */ %mend somemacro ;`
|
||||||
|
|
||||||
expect(hasMacroNameInMend.test(content)).toEqual([])
|
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', () => {
|
it('should return an array with a single diagnostic when %mend has incorrect macro name', () => {
|
||||||
const content = `
|
const content = `
|
||||||
%macro somemacro;
|
%macro somemacro;
|
||||||
|
/* some comments */
|
||||||
%put &sysmacroname;
|
%put &sysmacroname;
|
||||||
|
/* some comments */
|
||||||
%mend someanothermacro ;`
|
%mend someanothermacro ;`
|
||||||
|
|
||||||
expect(hasMacroNameInMend.test(content)).toEqual([
|
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', () => {
|
it('should return an array with a single diagnostic when %mend has no macro name', () => {
|
||||||
const content = `
|
const content = `
|
||||||
%macro somemacro ;
|
%macro somemacro ;
|
||||||
%put &sysmacroname;
|
/* some comments */%put &sysmacroname;
|
||||||
%mend ;`
|
%mend ;`
|
||||||
|
|
||||||
expect(hasMacroNameInMend.test(content)).toEqual([
|
expect(hasMacroNameInMend.test(content)).toEqual([
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ const test = (value: string) => {
|
|||||||
|
|
||||||
const stack: string[] = []
|
const stack: string[] = []
|
||||||
statements.forEach((statement, index) => {
|
statements.forEach((statement, index) => {
|
||||||
const trimmedStatement = statement.trim()
|
const trimmedStatement = trimComments(statement).trim()
|
||||||
if (trimmedStatement.startsWith('%macro ')) {
|
if (trimmedStatement.startsWith('%macro ')) {
|
||||||
const macroName = trimmedStatement
|
const macroName = trimmedStatement
|
||||||
.split(' ')
|
.split(' ')
|
||||||
@@ -58,6 +58,15 @@ const test = (value: string) => {
|
|||||||
return diagnostics
|
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 getLineNumber = (statements: string[], index: number): number => {
|
||||||
const combinedCode = statements.slice(0, index).join(';')
|
const combinedCode = statements.slice(0, index).join(';')
|
||||||
const lines = (combinedCode.match(/\n/g) || []).length + 1
|
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 => {
|
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